From 3ce324fa9d5daa4533f91ac9794d7f7ff7b51d63 Mon Sep 17 00:00:00 2001 From: Roman Artemev Date: Mon, 2 Apr 2018 14:46:31 +0300 Subject: [PATCH] Add tests for secondary constructors --- .../kotlin/test/jsIrBackendTestWhitelist.kt | 19 +- .../js/test/semantics/BoxJsTestGenerated.java | 30 +++ .../test/semantics/IrBoxJsTestGenerated.java | 217 +++++++----------- .../box/simple/primCtorDelegation1.kt | 19 ++ .../testData/box/simple/secCtorDelegation1.kt | 35 +++ .../testData/box/simple/secCtorDelegation2.kt | 36 +++ .../testData/box/simple/secCtorDelegation3.kt | 35 +++ .../testData/box/simple/secCtorDelegation4.kt | 26 +++ 8 files changed, 284 insertions(+), 133 deletions(-) create mode 100644 js/js.translator/testData/box/simple/primCtorDelegation1.kt create mode 100644 js/js.translator/testData/box/simple/secCtorDelegation1.kt create mode 100644 js/js.translator/testData/box/simple/secCtorDelegation2.kt create mode 100644 js/js.translator/testData/box/simple/secCtorDelegation3.kt create mode 100644 js/js.translator/testData/box/simple/secCtorDelegation4.kt diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/jsIrBackendTestWhitelist.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/test/jsIrBackendTestWhitelist.kt index 08102a7845d..c34a1a2efe0 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/jsIrBackendTestWhitelist.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/jsIrBackendTestWhitelist.kt @@ -15,5 +15,22 @@ val JS_IR_BACKEND_TEST_WHITELIST = listOf( "js/js.translator/testData/box/expression/identifierClash/useVariableOfNameOfFunction.kt", "js/js.translator/testData/box/expression/stringClass/stringConstant.kt", "js/js.translator/testData/box/expression/when/empty.kt", - "js/js.translator/testData/box/simple/notBoolean.kt" + "js/js.translator/testData/box/simple/notBoolean.kt", + "js/js.translator/testData/box/simple/primCtorDelegation1.kt", + "js/js.translator/testData/box/simple/secCtorDelegation1.kt", + "js/js.translator/testData/box/simple/secCtorDelegation2.kt", + "js/js.translator/testData/box/simple/secCtorDelegation3.kt", + "js/js.translator/testData/box/simple/secCtorDelegation4.kt", + "js/js.translator/testData/box/operatorOverloading/notOverload.kt", + "js/js.translator/testData/box/operatorOverloading/binaryDivOverload.kt", + "js/js.translator/testData/box/package/initializersOfNestedPackagesExecute.kt", + "js/js.translator/testData/box/package/classCreatedInDeeplyNestedPackage.kt", + "js/js.translator/testData/box/extensionProperty/inClass.kt", + "js/js.translator/testData/box/multiPackage/createClassFromOtherPackage.kt", + "js/js.translator/testData/box/multiPackage/createClassFromOtherPackageUsingImport.kt", + "js/js.translator/testData/box/simple/methodDeclarationAndCall.kt", + "js/js.translator/testData/box/simple/propertyAccess.kt", + "js/js.translator/testData/box/simple/classInstantiation.kt", + "js/js.translator/testData/box/expression/invoke/internalFunctionFromSuperclass.kt", + "js/js.translator/testData/box/inheritance/withInitializeMethod.kt" ).map { File(it) } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java index fcb1835c2fe..7db19aee4cc 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java @@ -8095,6 +8095,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { doTest(fileName); } + @TestMetadata("primCtorDelegation1.kt") + public void testPrimCtorDelegation1() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/primCtorDelegation1.kt"); + doTest(fileName); + } + @TestMetadata("propertiesAsParametersInitialized.kt") public void testPropertiesAsParametersInitialized() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/propertiesAsParametersInitialized.kt"); @@ -8107,6 +8113,30 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { doTest(fileName); } + @TestMetadata("secCtorDelegation1.kt") + public void testSecCtorDelegation1() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/secCtorDelegation1.kt"); + doTest(fileName); + } + + @TestMetadata("secCtorDelegation2.kt") + public void testSecCtorDelegation2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/secCtorDelegation2.kt"); + doTest(fileName); + } + + @TestMetadata("secCtorDelegation3.kt") + public void testSecCtorDelegation3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/secCtorDelegation3.kt"); + doTest(fileName); + } + + @TestMetadata("secCtorDelegation4.kt") + public void testSecCtorDelegation4() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/secCtorDelegation4.kt"); + doTest(fileName); + } + @TestMetadata("simpleInitializer.kt") public void testSimpleInitializer() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/simpleInitializer.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrBoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrBoxJsTestGenerated.java index 38547438ed7..f2e7d82ec51 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrBoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrBoxJsTestGenerated.java @@ -7586,18 +7586,7 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { @TestMetadata("internalFunctionFromSuperclass.kt") public void testInternalFunctionFromSuperclass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/expression/invoke/internalFunctionFromSuperclass.kt"); - if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { - doTest(fileName); - return; - } - try { - doTest(fileName); - } - catch (Throwable ignore) { - ignore.printStackTrace(); - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + doTest(fileName); } @TestMetadata("invokeInExtensionFunctionLiteral.kt") @@ -9847,18 +9836,7 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { @TestMetadata("inClass.kt") public void testInClass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/extensionProperty/inClass.kt"); - if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { - doTest(fileName); - return; - } - try { - doTest(fileName); - } - catch (Throwable ignore) { - ignore.printStackTrace(); - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + doTest(fileName); } @TestMetadata("privateExtensionProperty.kt") @@ -10511,18 +10489,7 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { @TestMetadata("withInitializeMethod.kt") public void testWithInitializeMethod() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/inheritance/withInitializeMethod.kt"); - if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { - doTest(fileName); - return; - } - try { - doTest(fileName); - } - catch (Throwable ignore) { - ignore.printStackTrace(); - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + doTest(fileName); } @TestMetadata("js/js.translator/testData/box/inheritance/interfaces") @@ -16533,35 +16500,13 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { @TestMetadata("createClassFromOtherPackage.kt") public void testCreateClassFromOtherPackage() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/multiPackage/createClassFromOtherPackage.kt"); - if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { - doTest(fileName); - return; - } - try { - doTest(fileName); - } - catch (Throwable ignore) { - ignore.printStackTrace(); - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + doTest(fileName); } @TestMetadata("createClassFromOtherPackageUsingImport.kt") public void testCreateClassFromOtherPackageUsingImport() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/multiPackage/createClassFromOtherPackageUsingImport.kt"); - if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { - doTest(fileName); - return; - } - try { - doTest(fileName); - } - catch (Throwable ignore) { - ignore.printStackTrace(); - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + doTest(fileName); } @TestMetadata("functionsVisibleFromOtherPackage.kt") @@ -18744,18 +18689,7 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { @TestMetadata("binaryDivOverload.kt") public void testBinaryDivOverload() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/operatorOverloading/binaryDivOverload.kt"); - if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { - doTest(fileName); - return; - } - try { - doTest(fileName); - } - catch (Throwable ignore) { - ignore.printStackTrace(); - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + doTest(fileName); } @TestMetadata("compareTo.kt") @@ -18812,18 +18746,7 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { @TestMetadata("notOverload.kt") public void testNotOverload() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/operatorOverloading/notOverload.kt"); - if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { - doTest(fileName); - return; - } - try { - doTest(fileName); - } - catch (Throwable ignore) { - ignore.printStackTrace(); - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + doTest(fileName); } @TestMetadata("operatorOverloadOnPropertyCallGetterAndSetterOnlyOnce.kt") @@ -19127,18 +19050,7 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { @TestMetadata("classCreatedInDeeplyNestedPackage.kt") public void testClassCreatedInDeeplyNestedPackage() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/package/classCreatedInDeeplyNestedPackage.kt"); - if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { - doTest(fileName); - return; - } - try { - doTest(fileName); - } - catch (Throwable ignore) { - ignore.printStackTrace(); - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + doTest(fileName); } @TestMetadata("deeplyNestedPackage.kt") @@ -19156,18 +19068,7 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { @TestMetadata("initializersOfNestedPackagesExecute.kt") public void testInitializersOfNestedPackagesExecute() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/package/initializersOfNestedPackagesExecute.kt"); - if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { - doTest(fileName); - return; - } - try { - doTest(fileName); - } - catch (Throwable ignore) { - ignore.printStackTrace(); - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + doTest(fileName); } @TestMetadata("nestedPackage.kt") @@ -21096,18 +20997,7 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { @TestMetadata("classInstantiation.kt") public void testClassInstantiation() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/classInstantiation.kt"); - if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { - doTest(fileName); - return; - } - try { - doTest(fileName); - } - catch (Throwable ignore) { - ignore.printStackTrace(); - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + doTest(fileName); } @TestMetadata("comparison.kt") @@ -21300,18 +21190,7 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { @TestMetadata("methodDeclarationAndCall.kt") public void testMethodDeclarationAndCall() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/methodDeclarationAndCall.kt"); - if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { - doTest(fileName); - return; - } - try { - doTest(fileName); - } - catch (Throwable ignore) { - ignore.printStackTrace(); - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + doTest(fileName); } @TestMetadata("minusAssignOnProperty.kt") @@ -21405,6 +21284,23 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); } + @TestMetadata("primCtorDelegation1.kt") + public void testPrimCtorDelegation1() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/primCtorDelegation1.kt"); + if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { + doTest(fileName); + return; + } + try { + doTest(fileName); + } + catch (Throwable ignore) { + ignore.printStackTrace(); + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + } + @TestMetadata("propertiesAsParametersInitialized.kt") public void testPropertiesAsParametersInitialized() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/propertiesAsParametersInitialized.kt"); @@ -21425,6 +21321,63 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { @TestMetadata("propertyAccess.kt") public void testPropertyAccess() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/propertyAccess.kt"); + doTest(fileName); + } + + @TestMetadata("secCtorDelegation1.kt") + public void testSecCtorDelegation1() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/secCtorDelegation1.kt"); + if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { + doTest(fileName); + return; + } + try { + doTest(fileName); + } + catch (Throwable ignore) { + ignore.printStackTrace(); + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + } + + @TestMetadata("secCtorDelegation2.kt") + public void testSecCtorDelegation2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/secCtorDelegation2.kt"); + if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { + doTest(fileName); + return; + } + try { + doTest(fileName); + } + catch (Throwable ignore) { + ignore.printStackTrace(); + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + } + + @TestMetadata("secCtorDelegation3.kt") + public void testSecCtorDelegation3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/secCtorDelegation3.kt"); + if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { + doTest(fileName); + return; + } + try { + doTest(fileName); + } + catch (Throwable ignore) { + ignore.printStackTrace(); + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); + } + + @TestMetadata("secCtorDelegation4.kt") + public void testSecCtorDelegation4() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/simple/secCtorDelegation4.kt"); if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) { doTest(fileName); return; diff --git a/js/js.translator/testData/box/simple/primCtorDelegation1.kt b/js/js.translator/testData/box/simple/primCtorDelegation1.kt new file mode 100644 index 00000000000..34ec11623db --- /dev/null +++ b/js/js.translator/testData/box/simple/primCtorDelegation1.kt @@ -0,0 +1,19 @@ +// EXPECTED_REACHABLE_NODES: 1114 +package foo + +open class Base(val bb: String) { + + open fun foo() = bb +} + +class Test(val tt: String) : Base("fail") { + + override fun foo() = tt + +} + +fun box(): String { + + val t = Test("OK") + return t.foo() +} \ No newline at end of file diff --git a/js/js.translator/testData/box/simple/secCtorDelegation1.kt b/js/js.translator/testData/box/simple/secCtorDelegation1.kt new file mode 100644 index 00000000000..17420009a26 --- /dev/null +++ b/js/js.translator/testData/box/simple/secCtorDelegation1.kt @@ -0,0 +1,35 @@ +// EXPECTED_REACHABLE_NODES: 1114 +package foo + +open class Base { + val i: Int + val i2: Int + val i3: Int + val bs: String + + constructor(ii1: Int, ii2: Int) { + i = ii1 + i2 = ii2 + i3 = 30 + } + + constructor(ii: Int): this(ii, 25) { + } + + open fun foo() = bs + + init { + bs = "fail" + } +} + +class Test(val tt: String) : Base(18) { + + override fun foo() = tt +} + +fun box(): String { + + val t = Test("OK") + return t.foo() +} \ No newline at end of file diff --git a/js/js.translator/testData/box/simple/secCtorDelegation2.kt b/js/js.translator/testData/box/simple/secCtorDelegation2.kt new file mode 100644 index 00000000000..a9283819445 --- /dev/null +++ b/js/js.translator/testData/box/simple/secCtorDelegation2.kt @@ -0,0 +1,36 @@ +// EXPECTED_REACHABLE_NODES: 1114 +package foo + +open class Base(val bs: String) { + + + val i: Int + val i2: Int + val i3: Int + + fun foo() = bs + + init { + i = 10 + i2 = 20 + i3 = 30 + } +} + +class Test : Base { + + val t1: Int + val t2: Int + + constructor(tt1: Int, tt2: Int): super("OK") { + t1 = tt1 + t2 = tt2 + } + +} + +fun box(): String { + + val t = Test(1, 2) + return t.foo() +} \ No newline at end of file diff --git a/js/js.translator/testData/box/simple/secCtorDelegation3.kt b/js/js.translator/testData/box/simple/secCtorDelegation3.kt new file mode 100644 index 00000000000..a2fd366497b --- /dev/null +++ b/js/js.translator/testData/box/simple/secCtorDelegation3.kt @@ -0,0 +1,35 @@ +// EXPECTED_REACHABLE_NODES: 1114 +package foo + +open class Base { + val i: Int + val i2: Int + val i3: Int + val bs: String + + constructor(s:String) {bs = s} + + fun foo() = bs + + init { + i = 10 + i2 = 20 + i3 = 30 + } +} + +class Test: Base { + val t1: Int + val t2: Int + + constructor(tt1: Int, tt2:Int) : super("OK") { + t1 = tt1 + t2 = tt2 + } +} + +fun box(): String { + + val t = Test(1, 2) + return t.foo() +} \ No newline at end of file diff --git a/js/js.translator/testData/box/simple/secCtorDelegation4.kt b/js/js.translator/testData/box/simple/secCtorDelegation4.kt new file mode 100644 index 00000000000..85923bf07b2 --- /dev/null +++ b/js/js.translator/testData/box/simple/secCtorDelegation4.kt @@ -0,0 +1,26 @@ +// EXPECTED_REACHABLE_NODES: 1114 +package foo + +class Test(val bs: String) { + + var i: Int = 0 + var i2: Int = 0 + var i3: Int =0 + + constructor(ii1: Int, ii2: Int): this("OK") { + i = ii1 + i2 = ii2 + i3 = 30 + } + + constructor(ii: Int): this(ii, 18) { + } + + fun foo() = bs +} + +fun box(): String { + + val t = Test(1) + return t.foo() +} \ No newline at end of file