added configuration kind parameter to tests

This commit is contained in:
Svetlana Isakova
2012-09-05 16:25:06 +04:00
parent 096218c2b8
commit 9263dbb0fc
5 changed files with 25 additions and 19 deletions
@@ -17,6 +17,7 @@
package org.jetbrains.jet.jvm.compiler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.test.TestCaseWithTmpdir;
import org.jetbrains.jet.test.generator.SimpleTestClassModel;
@@ -46,9 +47,9 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
File javaFile = new File(javaFileName);
File ktFile = new File(javaFile.getPath().replaceFirst("\\.java$", ".kt"));
File txtFile = new File(javaFile.getPath().replaceFirst("\\.java$", ".txt"));
NamespaceDescriptor nsa = analyzeKotlinAndLoadTestNamespace(ktFile, myTestRootDisposable);
NamespaceDescriptor nsa = analyzeKotlinAndLoadTestNamespace(ktFile, myTestRootDisposable, ConfigurationKind.JDK_AND_ANNOTATIONS);
NamespaceDescriptor nsb = compileJavaAndLoadTestNamespaceFromBinary(Collections.singletonList(javaFile),
tmpdir, myTestRootDisposable);
tmpdir, myTestRootDisposable, ConfigurationKind.JDK_AND_ANNOTATIONS);
compareNamespaces(nsa, nsb, DONT_INCLUDE_METHODS_OF_OBJECT, txtFile);
}
@@ -18,6 +18,7 @@ package org.jetbrains.jet.jvm.compiler;
import junit.framework.Test;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.JetTestCaseBuilder;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.TestCaseWithTmpdir;
@@ -56,7 +57,7 @@ public class CompileJavaAgainstKotlinTest extends TestCaseWithTmpdir {
@Override
protected void runTest() throws Throwable {
compileKotlinToDirAndGetAnalyzeExhaust(ktFile, tmpdir, getTestRootDisposable());
compileKotlinToDirAndGetAnalyzeExhaust(ktFile, tmpdir, getTestRootDisposable(), ConfigurationKind.JDK_ONLY);
List<String> options = Arrays.asList(
"-classpath", tmpdir.getPath() + System.getProperty("path.separator") + "out/production/stdlib",
@@ -19,6 +19,7 @@ package org.jetbrains.jet.jvm.compiler;
import junit.framework.Assert;
import junit.framework.Test;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.JetTestCaseBuilder;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
@@ -54,13 +55,13 @@ public final class LoadCompiledKotlinTest extends TestCaseWithTmpdir {
@Override
public void runTest() throws Exception {
AnalyzeExhaust exhaust = compileKotlinToDirAndGetAnalyzeExhaust(testFile, tmpdir, getTestRootDisposable());
AnalyzeExhaust exhaust = compileKotlinToDirAndGetAnalyzeExhaust(testFile, tmpdir, getTestRootDisposable(), ConfigurationKind.JDK_ONLY);
NamespaceDescriptor namespaceFromSource = exhaust.getBindingContext().get(BindingContext.FQNAME_TO_NAMESPACE_DESCRIPTOR,
TEST_PACKAGE_FQNAME);
assert namespaceFromSource != null;
Assert.assertEquals("test", namespaceFromSource.getName().getName());
NamespaceDescriptor namespaceFromClass = LoadDescriptorUtil.loadTestNamespaceFromBinaries(tmpdir, getTestRootDisposable());
NamespaceDescriptor namespaceFromClass = LoadDescriptorUtil.loadTestNamespaceFromBinaries(tmpdir, getTestRootDisposable(), ConfigurationKind.JDK_ONLY);
compareNamespaces(namespaceFromSource, namespaceFromClass, NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT, txtFile);
}
@@ -69,20 +69,22 @@ public final class LoadDescriptorUtil {
public static NamespaceDescriptor compileKotlinAndLoadTestNamespaceDescriptorFromBinary(
@NotNull File kotlinFile,
@NotNull File outDir,
@NotNull Disposable disposable
@NotNull Disposable disposable,
@NotNull ConfigurationKind configurationKind
)
throws IOException {
compileKotlinToDirAndGetAnalyzeExhaust(kotlinFile, outDir, disposable);
return loadTestNamespaceFromBinaries(outDir, disposable);
compileKotlinToDirAndGetAnalyzeExhaust(kotlinFile, outDir, disposable, configurationKind);
return loadTestNamespaceFromBinaries(outDir, disposable, ConfigurationKind.JDK_ONLY);
}
@NotNull
public static AnalyzeExhaust compileKotlinToDirAndGetAnalyzeExhaust(
@NotNull File kotlinFile,
@NotNull File outDir,
@NotNull Disposable disposable
@NotNull Disposable disposable,
@NotNull ConfigurationKind configurationKind
) throws IOException {
JetFileAndExhaust fileAndExhaust = JetFileAndExhaust.createJetFileAndAnalyze(kotlinFile, disposable);
JetFileAndExhaust fileAndExhaust = JetFileAndExhaust.createJetFileAndAnalyze(kotlinFile, disposable, configurationKind);
GenerationState state = GenerationUtils.compileFilesGetGenerationState(fileAndExhaust.getJetFile().getProject(), fileAndExhaust.getExhaust(), Collections.singletonList(
fileAndExhaust.getJetFile()));
ClassFileFactory classFileFactory = state.getFactory();
@@ -91,11 +93,11 @@ public final class LoadDescriptorUtil {
}
@NotNull
public static NamespaceDescriptor loadTestNamespaceFromBinaries(@NotNull File outDir, @NotNull Disposable disposable) {
public static NamespaceDescriptor loadTestNamespaceFromBinaries(@NotNull File outDir, @NotNull Disposable disposable, @NotNull ConfigurationKind configurationKind) {
Disposer.dispose(disposable);
CompilerConfiguration configuration = CompileCompilerDependenciesTest.compilerConfigurationForTests(
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), outDir,
configurationKind, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), outDir,
ForTestCompileRuntime.runtimeJarForTests());
JetCoreEnvironment jetCoreEnvironment = new JetCoreEnvironment(disposable, configuration);
InjectorForJavaSemanticServices injector = new InjectorForJavaSemanticServices(BuiltinsScopeExtensionMode.ALL,
@@ -111,11 +113,12 @@ public final class LoadDescriptorUtil {
public static NamespaceDescriptor compileJavaAndLoadTestNamespaceFromBinary(
@NotNull Collection<File> javaFiles,
@NotNull File outDir,
@NotNull Disposable disposable
@NotNull Disposable disposable,
@NotNull ConfigurationKind configurationKind
)
throws IOException {
compileJavaWithAnnotationsJar(javaFiles, outDir);
return loadTestNamespaceFromBinaries(outDir, disposable);
return loadTestNamespaceFromBinaries(outDir, disposable, configurationKind);
}
private static void compileJavaWithAnnotationsJar(@NotNull Collection<File> javaFiles, @NotNull File outDir) throws IOException {
@@ -127,8 +130,8 @@ public final class LoadDescriptorUtil {
}
@NotNull
public static NamespaceDescriptor analyzeKotlinAndLoadTestNamespace(@NotNull File ktFile, @NotNull Disposable disposable) throws Exception {
JetFileAndExhaust fileAndExhaust = JetFileAndExhaust.createJetFileAndAnalyze(ktFile, disposable);
public static NamespaceDescriptor analyzeKotlinAndLoadTestNamespace(@NotNull File ktFile, @NotNull Disposable disposable, @NotNull ConfigurationKind configurationKind) throws Exception {
JetFileAndExhaust fileAndExhaust = JetFileAndExhaust.createJetFileAndAnalyze(ktFile, disposable, configurationKind);
//noinspection ConstantConditions
return fileAndExhaust.getExhaust().getBindingContext().get(BindingContext.FQNAME_TO_NAMESPACE_DESCRIPTOR, TEST_PACKAGE_FQNAME);
}
@@ -136,9 +139,9 @@ public final class LoadDescriptorUtil {
private static class JetFileAndExhaust {
@NotNull
public static JetFileAndExhaust createJetFileAndAnalyze(@NotNull File kotlinFile, @NotNull Disposable disposable)
public static JetFileAndExhaust createJetFileAndAnalyze(@NotNull File kotlinFile, @NotNull Disposable disposable, @NotNull ConfigurationKind configurationKind)
throws IOException {
JetCoreEnvironment jetCoreEnvironment = createEnvironmentWithMockJdkAndIdeaAnnotations(disposable, ConfigurationKind.JDK_ONLY);
JetCoreEnvironment jetCoreEnvironment = createEnvironmentWithMockJdkAndIdeaAnnotations(disposable, configurationKind);
JetFile jetFile = createFile(jetCoreEnvironment.getProject(), FileUtil.loadFile(kotlinFile, true));
AnalyzeExhaust exhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(
jetFile, Collections.<AnalyzerScriptParameter>emptyList(), BuiltinsScopeExtensionMode.ALL);
@@ -56,7 +56,7 @@ public final class LoadJavaCustomTest extends KotlinTestWithEnvironment {
});
File expected = new File(expectedFileName);
File tmpDir = JetTestUtils.tmpDir(expected.getName());
NamespaceDescriptor javaNamespaceDescriptor = compileJavaAndLoadTestNamespaceFromBinary(files, tmpDir, getTestRootDisposable());
NamespaceDescriptor javaNamespaceDescriptor = compileJavaAndLoadTestNamespaceFromBinary(files, tmpDir, getTestRootDisposable(), ConfigurationKind.JDK_ONLY);
//NOTE: comparing namespace to file (hack)
NamespaceComparator.compareNamespaces(javaNamespaceDescriptor, javaNamespaceDescriptor, NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT, expected);
}