Adapt CompileKotlinAgainstKotlin test to black box format

Rename/remove some obsolete test cases
This commit is contained in:
Alexander Udalov
2016-02-29 13:36:16 +03:00
parent 0b26e749f6
commit 9f67fe2fe3
34 changed files with 152 additions and 183 deletions
@@ -16,37 +16,19 @@
package org.jetbrains.kotlin.codegen
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
import java.io.File
abstract class AbstractCompileKotlinAgainstInlineKotlinTest : AbstractCompileKotlinAgainstKotlinTest() {
override fun doMultiFileTest(wholeFile: File, files: List<TestFile>, javaFilesDir: File?) {
val kotlinFiles = files.filter { it.name.endsWith(".kt") }
assert(kotlinFiles.size == 2) { "There should be exactly two files in this test" }
var factory1: ClassFileFactory? = null
var factory2: ClassFileFactory? = null
val (factory1, factory2) = doTwoFileTest(files.filter { it.name.endsWith(".kt") })
try {
val (fileA, fileB) = kotlinFiles
factory1 = compileA(fileA.name, fileA.content)
factory2 = compileB(fileB.name, fileB.content)
invokeBox(PackagePartClassUtils.getFilePartShortName(File(fileB.name).name))
val allGeneratedFiles = factory1.asList() + factory2.asList()
val sourceFiles = factory1.inputFiles + factory2.inputFiles
InlineTestUtil.checkNoCallsToInline(allGeneratedFiles.filterClassFiles(), sourceFiles)
SMAPTestUtil.checkSMAP(files, allGeneratedFiles.filterClassFiles())
}
catch (e: Throwable) {
var result = ""
if (factory1 != null) {
result += "FIRST: \n\n" + factory1.createText()
}
if (factory2 != null) {
result += "\n\nSECOND: \n\n" + factory2.createText()
}
println(result)
println("FIRST:\n\n${factory1.createText()}\n\nSECOND:\n\n${factory2.createText()}")
throw e
}
}
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.codegen;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.ArrayUtil;
import kotlin.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.cli.common.modules.ModuleBuilder;
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestJdkKind;
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
import java.io.File;
import java.io.IOException;
@@ -58,19 +59,31 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends CodegenTest
@Override
protected void doMultiFileTest(@NotNull File wholeFile, @NotNull List<TestFile> files, @Nullable File javaFilesDir) throws Exception {
assert javaFilesDir == null : ".java files are not supported yet in this test";
doTwoFileTest(files);
}
@NotNull
protected Pair<ClassFileFactory, ClassFileFactory> doTwoFileTest(@NotNull List<TestFile> files) throws Exception {
// Note that it may be beneficial to improve this test to handle many files, compiling them successively against all previous
assert files.size() == 2 : "There should be exactly two files in this test";
TestFile fileA = files.get(0);
TestFile fileB = files.get(1);
compileA(fileA.name, fileA.content);
compileB(fileB.name, fileB.content);
invokeMain(fileB.name);
}
private void invokeMain(@NotNull String fileName) throws Exception {
String className = PackagePartClassUtils.getFilePartShortName(fileName);
Method main = createGeneratedClassLoader().loadClass(className).getMethod("main", String[].class);
main.invoke(null, new Object[] {ArrayUtil.EMPTY_STRING_ARRAY});
ClassFileFactory factoryA = compileA(fileA.name, fileA.content);
ClassFileFactory factoryB = null;
try {
factoryB = compileB(fileB.name, fileB.content);
invokeBox(PackagePartClassUtils.getFilePartShortName(new File(fileB.name).getName()));
}
catch (Throwable e) {
String result = "FIRST: \n\n" + factoryA.createText();
if (factoryB != null) {
result += "\n\nSECOND: \n\n" + factoryB.createText();
}
System.out.println(result);
throw ExceptionUtilsKt.rethrow(e);
}
return new Pair<ClassFileFactory, ClassFileFactory>(factoryA, factoryB);
}
protected void invokeBox(@NotNull String className) throws Exception {
@@ -35,9 +35,9 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileKotlinAgainstKotlin"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("annotationInTrait.kt")
public void testAnnotationInTrait() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/annotationInTrait.kt");
@TestMetadata("annotationInInterface.kt")
public void testAnnotationInInterface() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/annotationInInterface.kt");
doTest(fileName);
}
@@ -53,15 +53,15 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
doTest(fileName);
}
@TestMetadata("classObjectInEnum.kt")
public void testClassObjectInEnum() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/classObjectInEnum.kt");
@TestMetadata("companionObjectInEnum.kt")
public void testCompanionObjectInEnum() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/companionObjectInEnum.kt");
doTest(fileName);
}
@TestMetadata("classObjectMember.kt")
public void testClassObjectMember() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/classObjectMember.kt");
@TestMetadata("companionObjectMember.kt")
public void testCompanionObjectMember() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/companionObjectMember.kt");
doTest(fileName);
}
@@ -95,12 +95,6 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
doTest(fileName);
}
@TestMetadata("importObject.kt")
public void testImportObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/importObject.kt");
doTest(fileName);
}
@TestMetadata("inlinedConstants.kt")
public void testInlinedConstants() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/inlinedConstants.kt");
@@ -125,9 +119,15 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
doTest(fileName);
}
@TestMetadata("jvmNameOnAccessor.kt")
public void testJvmNameOnAccessor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/jvmNameOnAccessor.kt");
@TestMetadata("jvmNames.kt")
public void testJvmNames() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/jvmNames.kt");
doTest(fileName);
}
@TestMetadata("jvmStaticInObject.kt")
public void testJvmStaticInObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/jvmStaticInObject.kt");
doTest(fileName);
}
@@ -161,18 +161,6 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
doTest(fileName);
}
@TestMetadata("platformNames.kt")
public void testPlatformNames() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/platformNames.kt");
doTest(fileName);
}
@TestMetadata("platformStaticInObject.kt")
public void testPlatformStaticInObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/platformStaticInObject.kt");
doTest(fileName);
}
@TestMetadata("platformTypes.kt")
public void testPlatformTypes() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/platformTypes.kt");