Produciton code uses a shared application between many projects.
Tests always dispose the application together with JetCoreEnvironment
This commit is contained in:
@@ -52,7 +52,6 @@ import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LazyResolveTestUtil;
|
||||
@@ -241,7 +240,7 @@ public class JetTestUtils {
|
||||
@NotNull ConfigurationKind configurationKind,
|
||||
@NotNull TestJdkKind jdkKind
|
||||
) {
|
||||
return new JetCoreEnvironment(disposable, compilerConfigurationForTests(
|
||||
return JetCoreEnvironment.createForTests(disposable, compilerConfigurationForTests(
|
||||
configurationKind, jdkKind, getAnnotationsJar(), getAnnotationsExtJar()));
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public abstract class KotlinAsJavaTestBase extends KotlinTestWithEnvironment {
|
||||
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, root.getPath());
|
||||
}
|
||||
|
||||
return new JetCoreEnvironment(getTestRootDisposable(), configuration);
|
||||
return JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration);
|
||||
}
|
||||
|
||||
protected abstract List<File> getKotlinSourceRoots();
|
||||
|
||||
@@ -71,15 +71,12 @@ public abstract class AbstractJetDiagnosticsTest extends JetLiteFixture {
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
}
|
||||
return new JetCoreEnvironment(
|
||||
getTestRootDisposable(),
|
||||
JetTestUtils.compilerConfigurationForTests(
|
||||
return JetCoreEnvironment.createForTests(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.JDK_AND_ANNOTATIONS,
|
||||
TestJdkKind.MOCK_JDK,
|
||||
Arrays.asList(JetTestUtils.getAnnotationsJar()),
|
||||
Arrays.asList(javaFilesDir)
|
||||
)
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
private static boolean writeJavaFile(@NotNull String fileName, @NotNull String content, @NotNull File javaFilesDir) {
|
||||
|
||||
@@ -56,7 +56,7 @@ public abstract class AbstractTopLevelMembersInvocationTest extends AbstractByte
|
||||
assert !sourceFiles.isEmpty() : getTestName(true) + " should contains at least one .kt file";
|
||||
Collections.sort(sourceFiles);
|
||||
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, Arrays.asList(JetTestUtils.getAnnotationsJar()), classPath));
|
||||
|
||||
loadFiles(sourceFiles.toArray(new String[sourceFiles.size()]));
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ClassPathInParentClassLoaderTest extends CodegenTestCase {
|
||||
public void testKt2781() throws Exception {
|
||||
File javaClassesTempDirectory = compileJava("classPathInParentClassLoader/kt2781.java");
|
||||
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory));
|
||||
|
||||
loadFile("classPathInParentClassLoader/kt2781.kt");
|
||||
|
||||
@@ -51,7 +51,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, generateAssertions);
|
||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, generateParamAssertions);
|
||||
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), configuration);
|
||||
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration);
|
||||
}
|
||||
|
||||
private void doTestGenerateAssertions(boolean generateAssertions) throws Exception {
|
||||
|
||||
@@ -36,7 +36,7 @@ public class JUnitUsageGenTest extends CodegenTestCase {
|
||||
throw new AssertionError("JUnit jar wasn't found");
|
||||
}
|
||||
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, junitJar));
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public class LineNumberTest extends TestCaseWithTmpdir {
|
||||
|
||||
@NotNull
|
||||
private JetCoreEnvironment createEnvironment() {
|
||||
return new JetCoreEnvironment(myTestRootDisposable, JetTestUtils
|
||||
return JetCoreEnvironment.createForTests(myTestRootDisposable, JetTestUtils
|
||||
.compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), tmpdir));
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public class OuterClassGenTest extends CodegenTestCase {
|
||||
private void doTest(@NotNull String kotlinName, @NotNull String javaName) throws Exception {
|
||||
File javaClassesTempDirectory = compileJava("outerClassInfo/outerClassInfo.java");
|
||||
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory));
|
||||
|
||||
UrlClassLoader javaClassLoader = new UrlClassLoader(new URL[] {javaClassesTempDirectory.toURI().toURL()}, getClass().getClassLoader());
|
||||
|
||||
@@ -98,7 +98,7 @@ public class TestlibTest extends UsefulTestCase {
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY,
|
||||
new MessageCollectorPlainTextToStream(System.out, MessageCollectorPlainTextToStream.NON_VERBOSE));
|
||||
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), configuration);
|
||||
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration);
|
||||
|
||||
generationState = KotlinToJVMBytecodeCompiler.analyzeAndGenerate(myEnvironment);
|
||||
if (generationState == null) {
|
||||
|
||||
@@ -79,7 +79,7 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
||||
String ktFile = ktFileFullPath.substring("compiler/testData/codegen/".length());
|
||||
File javaClassesTempDirectory = compileJava(ktFile.replaceFirst("\\.kt$", ".java"));
|
||||
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory));
|
||||
|
||||
loadFile(ktFile);
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit
|
||||
private void compileB(@NotNull File ktBFile) throws IOException {
|
||||
CompilerConfiguration configurationWithADirInClasspath = JetTestUtils
|
||||
.compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), aDir);
|
||||
compileKotlin(ktBFile, bDir, new JetCoreEnvironment(getTestRootDisposable(), configurationWithADirInClasspath),
|
||||
compileKotlin(ktBFile, bDir, JetCoreEnvironment.createForTests(getTestRootDisposable(), configurationWithADirInClasspath),
|
||||
getTestRootDisposable());
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, tmpdir);
|
||||
configuration.put(CommonConfigurationKeys.SOURCE_ROOTS_KEY, Arrays.asList(sourcesDir.getAbsolutePath()));
|
||||
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, new File("compiler/tests")); // for @ExpectLoadError annotation
|
||||
JetCoreEnvironment environment = new JetCoreEnvironment(getTestRootDisposable(), configuration);
|
||||
JetCoreEnvironment environment = JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration);
|
||||
|
||||
// we need the same binding trace for resolve from Java and Kotlin
|
||||
BindingTrace trace = CliLightClassGenerationSupport.getInstanceForCli(environment.getProject()).getTrace();
|
||||
|
||||
+4
-2
@@ -24,6 +24,7 @@ import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.MockLibraryUtil;
|
||||
import org.jetbrains.jet.TestJdkKind;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptorForObject;
|
||||
@@ -92,8 +93,9 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
extras.addAll(extraClassPath);
|
||||
extras.add(JetTestUtils.getAnnotationsJar());
|
||||
|
||||
return new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, extras.toArray(new File[extras.size()])));
|
||||
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, extras.toArray(new File[extras.size()]));
|
||||
return JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -69,7 +69,7 @@ public class JdkAnnotationsValidityTest extends UsefulTestCase {
|
||||
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.JDK_AND_ANNOTATIONS, TestJdkKind.FULL_JDK, JetTestUtils.getAnnotationsJar());
|
||||
configuration.add(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, new File("ideaSDK/lib/jdkAnnotations.jar"));
|
||||
return new JetCoreEnvironment(parentDisposable, configuration);
|
||||
return JetCoreEnvironment.createForTests(parentDisposable, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -95,7 +95,7 @@ public final class LoadDescriptorUtil {
|
||||
javaRoot,
|
||||
new File("compiler/tests") // for @ExpectLoadError annotation
|
||||
);
|
||||
JetCoreEnvironment jetCoreEnvironment = new JetCoreEnvironment(disposable, configuration);
|
||||
JetCoreEnvironment jetCoreEnvironment = JetCoreEnvironment.createForTests(disposable, configuration);
|
||||
BindingTraceContext trace = new BindingTraceContext();
|
||||
InjectorForJavaDescriptorResolver injector = new InjectorForJavaDescriptorResolver(jetCoreEnvironment.getProject(), trace);
|
||||
NamespaceDescriptor namespaceDescriptor =
|
||||
|
||||
+2
-2
@@ -145,13 +145,13 @@ public class ResolveDescriptorsFromExternalLibraries {
|
||||
|
||||
JetCoreEnvironment jetCoreEnvironment;
|
||||
if (jar != null) {
|
||||
jetCoreEnvironment = new JetCoreEnvironment(junk, JetTestUtils.compilerConfigurationForTests(
|
||||
jetCoreEnvironment = JetCoreEnvironment.createForTests(junk, JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.JDK_AND_ANNOTATIONS, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), jar));
|
||||
}
|
||||
else {
|
||||
CompilerConfiguration configuration =
|
||||
JetTestUtils.compilerConfigurationForTests(ConfigurationKind.JDK_AND_ANNOTATIONS, TestJdkKind.FULL_JDK);
|
||||
jetCoreEnvironment = new JetCoreEnvironment(junk, configuration);
|
||||
jetCoreEnvironment = JetCoreEnvironment.createForTests(junk, configuration);
|
||||
if (!PathUtil.findRtJar().equals(jar)) {
|
||||
throw new RuntimeException("rt.jar mismatch: " + jar + ", " + PathUtil.findRtJar());
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class JetPsiUtilTest extends JetLiteFixture {
|
||||
|
||||
@Override
|
||||
protected JetCoreEnvironment createEnvironment() {
|
||||
return new JetCoreEnvironment(getTestRootDisposable(), new CompilerConfiguration());
|
||||
return JetCoreEnvironment.createForTests(getTestRootDisposable(), new CompilerConfiguration());
|
||||
}
|
||||
|
||||
private ImportPath getImportPathFromParsed(String text) {
|
||||
|
||||
Reference in New Issue
Block a user