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
@@ -14,10 +14,11 @@ interface Tr {
class C : a.Tr
fun main(args: Array<String>) {
fun box(): String {
val method = C::class.java.getDeclaredMethod("foo")
val annotations = method.getDeclaredAnnotations().joinToString("\n")
if (annotations != "@a.Ann()") {
throw AssertionError(annotations)
return "Fail: $annotations"
}
return "OK"
}
@@ -12,10 +12,11 @@ var varOK: String = "Hmmm?"
import a.*
fun main(args: Array<String>) {
if (foo() != "OK") throw AssertionError("Fail function")
if (constOK != "OK") throw AssertionError("Fail const")
if (valOK != "OK") throw AssertionError("Fail val")
fun box(): String {
if (foo() != "OK") return "Fail function"
if (constOK != "OK") return "Fail const"
if (valOK != "OK") return "Fail val"
varOK = "OK"
if (varOK != "OK") throw AssertionError("Fail var")
if (varOK != "OK") return "Fail var"
return varOK
}
@@ -3,13 +3,16 @@
package a
object CartRoutes {
class RemoveOrderItem()
class RemoveOrderItem {
val result = "OK"
}
}
// FILE: B.kt
import a.CartRoutes
fun main(args: Array<String>) {
fun box(): String {
val r = CartRoutes.RemoveOrderItem()
return r.result
}
@@ -14,6 +14,6 @@ public enum class EnumClass {
import library.EnumClass
fun main(args: Array<String>) {
if (EnumClass.entry() != EnumClass.ENTRY) throw AssertionError()
fun box(): String {
return if (EnumClass.entry() != EnumClass.ENTRY) "Fail" else "OK"
}
@@ -9,7 +9,7 @@ class A {
// FILE: B.kt
fun main(args: Array<String>) {
if (A.foo() != 42) throw Exception()
if (A.bar != "OK") throw Exception()
fun box(): String {
if (A.foo() != 42) return "Fail foo"
return A.bar
}
@@ -12,7 +12,7 @@ const val OK: String = "OK"
import a.OK
fun main(args: Array<String>) {
fun box(): String {
val okRef = ::OK
// TODO: see KT-10892
@@ -23,5 +23,5 @@ fun main(args: Array<String>) {
// }
val result = okRef.get()
if (result != "OK") throw AssertionError("Fail: $result")
return result
}
@@ -6,8 +6,9 @@ class A(vararg s: String) {
// FILE: B.kt
fun main(args: Array<String>) {
A()
A("a")
A("a", "b")
fun box(): String {
A()
A("a")
A("a", "b")
return "OK"
}
@@ -6,6 +6,7 @@ class A(val a: Int = 1)
// FILE: B.kt
fun main(args: Array<String>) {
fun box(): String {
aaa.A()
return "OK"
}
@@ -12,9 +12,7 @@ class A {
// FILE: B.kt
fun main(args: Array<String>) {
fun box(): String {
val str = aaa.A.B.O().s
if (str != "OK") {
throw Exception()
}
return str
}
+3 -2
View File
@@ -11,6 +11,7 @@ enum class E {
import aaa.E
fun main(args: Array<String>) {
if (E.TRIVIAL_ENTRY == E.SUBCLASS) throw AssertionError()
fun box(): String {
if (E.TRIVIAL_ENTRY == E.SUBCLASS) return "Fail"
return "OK"
}
@@ -1,17 +0,0 @@
// FILE: A.kt
package some
public object SOME_OBJECT {
}
// FILE: B.kt
//This a test for blinking bug from KT-3124
import some.SOME_OBJECT
fun main(args: Array<String>) {
val a = SOME_OBJECT
}
@@ -23,10 +23,11 @@ import constants.*
@AnnotationClass("$b $s $i $l $f $d $bb $c $str")
class DummyClass()
fun main(args: Array<String>) {
fun box(): String {
val klass = DummyClass::class.java
val annotationClass = AnnotationClass::class.java
val annotation = klass.getAnnotation(annotationClass)!!
val value = annotation.value
require(value == "100 20000 2000000 2000000000000 3.14 3.14 true \u03c0 :)", { "Annotation value: $value" })
return "OK"
}
@@ -15,6 +15,7 @@ fun Outer.testExt() {
Inner("test")
}
fun main(args: Array<String>) {
fun box(): String {
Outer().testExt()
return "OK"
}
+2 -1
View File
@@ -18,6 +18,7 @@ open class C : B() {
}
}
fun main(args: Array<String>) {
fun box(): String {
C().test()
return "OK"
}
@@ -14,6 +14,7 @@ open class C : B() {
}
}
fun main(args: Array<String>) {
fun box(): String {
C().test()
return "OK"
}
@@ -1,12 +0,0 @@
// FILE: A.kt
class A {
val OK: String = "OK"
@JvmName("OK") get
}
// FILE: B.kt
fun main(args: Array<String>) {
if (A().OK != "OK") throw java.lang.AssertionError()
}
@@ -11,13 +11,20 @@ var v: Int = 1
@JvmName("vset")
set
fun consumeInt(x: Int) {}
class A {
val OK: String = "OK"
@JvmName("OK") get
}
// FILE: B.kt
import lib.*
fun main(args: Array<String>) {
fun box(): String {
foo()
v = 1
println(v)
consumeInt(v)
return A().OK
}
@@ -0,0 +1,16 @@
// FILE: A.kt
package aaa
import kotlin.jvm.*
public object TestObject {
@JvmStatic
public val test: String = "OK"
}
// FILE: B.kt
fun box(): String {
return aaa.TestObject.test
}
@@ -45,8 +45,9 @@ annotation class Ann(
val str: String
)
fun main(args: Array<String>) {
fun box(): String {
// Trigger annotation loading
(MyClass1() as java.lang.Object).getClass().getAnnotations()
(MyClass2() as java.lang.Object).getClass().getAnnotations()
return "OK"
}
@@ -9,7 +9,6 @@ inline fun K(body: () -> String): String =
// FILE: B.kt
fun main(args: Array<String>) {
val ok = K { "O" }
if (ok != "OK") throw java.lang.AssertionError("Expected: OK, actual: $ok")
fun box(): String {
return K { "O" }
}
@@ -4,15 +4,12 @@ package aaa
class A {
class O {
val s = "OK"
val s = "OK"
}
}
// FILE: B.kt
fun main(args: Array<String>) {
val str = aaa.A.O().s
if (str != "OK") {
throw Exception()
}
fun box(): String {
return aaa.A.O().s
}
+4 -3
View File
@@ -4,15 +4,16 @@ package aaa
class A {
enum class E {
A
A
}
}
// FILE: B.kt
fun main(args: Array<String>) {
fun box(): String {
val str = aaa.A.E.A
if (str.toString() != "A") {
throw Exception()
return "Fail $str"
}
return "OK"
}
@@ -4,15 +4,12 @@ package aaa
class A {
object O {
val s = "OK"
val s = "OK"
}
}
// FILE: B.kt
fun main(args: Array<String>) {
val str = aaa.A.O.s
if (str != "OK") {
throw Exception()
}
fun box(): String {
return aaa.A.O.s
}
@@ -1,21 +0,0 @@
// FILE: A.kt
package aaa
import kotlin.jvm.*
public object TestObject {
@JvmStatic
public val test: String = "test"
}
// FILE: B.kt
fun main(args: Array<String>) {
val h = aaa.TestObject.test
if (h != "test") {
throw Exception()
}
}
@@ -18,7 +18,7 @@ import test.*
class Inv<T>
fun <T> inv(t: T): Inv<T> = Inv<T>()
fun main(args: Array<String>) {
fun box(): String {
printStream().checkError()
val p: Inv<PrintStream> = inv(printStream())
val p1: Inv<PrintStream?> = inv(printStream())
@@ -31,4 +31,6 @@ fun main(args: Array<String>) {
a[0] = 1
val a1: Inv<Array<Int>> = inv(a)
val a2: Inv<Array<out Int>?> = inv(a)
return "OK"
}
@@ -11,15 +11,17 @@ public val String.extension: Long
import a.*
fun main(args: Array<String>) {
fun box(): String {
val f = ::topLevel
val x1 = f.get()
if (x1 != 42) throw AssertionError("Fail x1: $x1")
if (x1 != 42) return "Fail x1: $x1"
f.set(239)
val x2 = f.get()
if (x2 != 239) throw AssertionError("Fail x2: $x2")
if (x2 != 239) return "Fail x2: $x2"
val g = String::extension
val y1 = g.get("abcde")
if (y1 != 5L) throw AssertionError("Fail y1: $y1")
if (y1 != 5L) return "Fail y1: $y1"
return "OK"
}
@@ -14,10 +14,11 @@ interface Super {
import a.*
fun main(args: Array<String>) {
fun box(): String {
val declaredMethod = Super::class.java.getDeclaredMethod("foo", Rec::class.java)
val genericString = declaredMethod.toGenericString()
if (genericString != "public abstract a.Rec<?, ?> a.Super.foo(a.Rec<?, ?>)") throw AssertionError(genericString)
if (genericString != "public abstract a.Rec<?, ?> a.Super.foo(a.Rec<?, ?>)") return "Fail: $genericString"
return "OK"
}
fun test(s: Super, p: Rec<*, *>) {
@@ -22,16 +22,17 @@ class B2 : A {
constructor(x1: Int): super(x1.toLong()) {}
}
fun main(args: Array<String>) {
fun box(): String {
val b1 = B1()
if (b1.prop != "123#abc") throw AssertionError("fail1: ${b1.prop}")
if (b1.prop != "123#abc") return "fail1: ${b1.prop}"
val b2 = B1(456)
if (b2.prop != "123#abc") throw AssertionError("fail2: ${b2.prop}")
if (b2.prop != "123#abc") return "fail2: ${b2.prop}"
val b3 = B2("cde")
if (b3.prop != "cde#abc") throw AssertionError("fail3: ${b3.prop}")
if (b3.prop != "cde#abc") return "fail3: ${b3.prop}"
val b4 = B2()
if (b4.prop != "empty#abc") throw AssertionError("fail4: ${b4.prop}")
if (b4.prop != "empty#abc") return "fail4: ${b4.prop}"
val b5 = B2(789)
if (b5.prop != "789") throw AssertionError("fail5: ${b5.prop}")
if (b5.prop != "789") return "fail5: ${b5.prop}"
return "OK"
}
+2 -1
View File
@@ -6,9 +6,10 @@ fun hello() = 17
// FILE: B.kt
fun main(args: Array<String>) {
fun box(): String {
val h = aaa.hello()
if (h != 17) {
throw Exception()
}
return "OK"
}
@@ -14,7 +14,7 @@ interface ClassA {
import pkg.ClassA
fun main(args: Array<String>) {
fun box(): String {
val obj = ClassA.DEFAULT
obj.toString()
return obj.toString()
}
@@ -15,7 +15,8 @@ enum class E {
import aaa.E.*
fun main(args: Array<String>) {
if (TRIVIAL_ENTRY == SUBCLASS) throw AssertionError()
if (Nested().fortyTwo() != 42) throw AssertionError()
fun box(): String {
if (TRIVIAL_ENTRY == SUBCLASS) return "Fail 1"
if (Nested().fortyTwo() != 42) return "Fail 2"
return "OK"
}
@@ -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");