From 10c5949199f4f1056399ef79dd6e661282d511ed Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Sun, 27 Jan 2013 20:01:55 +0400 Subject: [PATCH] Extract some codegen tests to black box testData --- compiler/testData/codegen/box/casts/as.kt | 8 ++ compiler/testData/codegen/box/casts/asSafe.kt | 8 ++ compiler/testData/codegen/box/casts/is.kt | 8 ++ compiler/testData/codegen/box/casts/notIs.kt | 8 ++ .../{ => box}/extensionFunctions/simple.kt | 2 + .../{ => box}/extensionFunctions/whenFail.kt | 10 +++ .../primitiveTypes}/kt828.kt | 0 .../{regressions => box/ranges}/kt2596.kt | 0 .../jet/codegen/ExtensionFunctionsTest.java | 51 ------------- .../org/jetbrains/jet/codegen/StdlibTest.java | 8 -- .../jetbrains/jet/codegen/TypeInfoTest.java | 76 ------------------- .../BlackBoxCodegenTestGenerated.java | 60 ++++++++++++++- 12 files changed, 103 insertions(+), 136 deletions(-) create mode 100644 compiler/testData/codegen/box/casts/as.kt create mode 100644 compiler/testData/codegen/box/casts/asSafe.kt create mode 100644 compiler/testData/codegen/box/casts/is.kt create mode 100644 compiler/testData/codegen/box/casts/notIs.kt rename compiler/testData/codegen/{ => box}/extensionFunctions/simple.kt (59%) rename compiler/testData/codegen/{ => box}/extensionFunctions/whenFail.kt (71%) rename compiler/testData/codegen/{regressions => box/primitiveTypes}/kt828.kt (100%) rename compiler/testData/codegen/{regressions => box/ranges}/kt2596.kt (100%) delete mode 100644 compiler/tests/org/jetbrains/jet/codegen/ExtensionFunctionsTest.java delete mode 100644 compiler/tests/org/jetbrains/jet/codegen/TypeInfoTest.java diff --git a/compiler/testData/codegen/box/casts/as.kt b/compiler/testData/codegen/box/casts/as.kt new file mode 100644 index 00000000000..7392e121bbe --- /dev/null +++ b/compiler/testData/codegen/box/casts/as.kt @@ -0,0 +1,8 @@ +fun foo(x: Any) = x as Runnable + +fun box(): String { + val r = object : Runnable { + override fun run() {} + } + return if (foo(r) identityEquals r) "OK" else "Fail" +} diff --git a/compiler/testData/codegen/box/casts/asSafe.kt b/compiler/testData/codegen/box/casts/asSafe.kt new file mode 100644 index 00000000000..348925891c7 --- /dev/null +++ b/compiler/testData/codegen/box/casts/asSafe.kt @@ -0,0 +1,8 @@ +fun foo(x: Any) = x as? Runnable + +fun box(): String { + val r = object : Runnable { + override fun run() {} + } + return if (foo(r) identityEquals r) "OK" else "Fail" +} diff --git a/compiler/testData/codegen/box/casts/is.kt b/compiler/testData/codegen/box/casts/is.kt new file mode 100644 index 00000000000..30b0a2763a1 --- /dev/null +++ b/compiler/testData/codegen/box/casts/is.kt @@ -0,0 +1,8 @@ +fun foo(x: Any) = x is Runnable + +fun box(): String { + val r = object : Runnable { + override fun run() {} + } + return if (foo(r) && !foo(42)) "OK" else "Fail" +} diff --git a/compiler/testData/codegen/box/casts/notIs.kt b/compiler/testData/codegen/box/casts/notIs.kt new file mode 100644 index 00000000000..3231c0e9743 --- /dev/null +++ b/compiler/testData/codegen/box/casts/notIs.kt @@ -0,0 +1,8 @@ +fun foo(x: Any) = x !is Runnable + +fun box(): String { + val r = object : Runnable { + override fun run() {} + } + return if (!foo(r) && foo(42)) "OK" else "Fail" +} diff --git a/compiler/testData/codegen/extensionFunctions/simple.kt b/compiler/testData/codegen/box/extensionFunctions/simple.kt similarity index 59% rename from compiler/testData/codegen/extensionFunctions/simple.kt rename to compiler/testData/codegen/box/extensionFunctions/simple.kt index f8d04d540e0..fd45243eab5 100644 --- a/compiler/testData/codegen/extensionFunctions/simple.kt +++ b/compiler/testData/codegen/box/extensionFunctions/simple.kt @@ -1,3 +1,5 @@ fun StringBuilder.first() = this.charAt(0) fun foo() = StringBuilder("foo").first() + +fun box() = if (foo() == 'f') "OK" else "Fail ${foo()}" diff --git a/compiler/testData/codegen/extensionFunctions/whenFail.kt b/compiler/testData/codegen/box/extensionFunctions/whenFail.kt similarity index 71% rename from compiler/testData/codegen/extensionFunctions/whenFail.kt rename to compiler/testData/codegen/box/extensionFunctions/whenFail.kt index e56a8482b2d..a3d6beb6208 100644 --- a/compiler/testData/codegen/extensionFunctions/whenFail.kt +++ b/compiler/testData/codegen/box/extensionFunctions/whenFail.kt @@ -12,3 +12,13 @@ fun foo(expr: StringBuilder): Int { else -> throw Exception("nonzero" + c) } } + +fun box(): String { + try { + foo(StringBuilder()) + return "Fail" + } + catch (e: Exception) { + return "OK" + } +} diff --git a/compiler/testData/codegen/regressions/kt828.kt b/compiler/testData/codegen/box/primitiveTypes/kt828.kt similarity index 100% rename from compiler/testData/codegen/regressions/kt828.kt rename to compiler/testData/codegen/box/primitiveTypes/kt828.kt diff --git a/compiler/testData/codegen/regressions/kt2596.kt b/compiler/testData/codegen/box/ranges/kt2596.kt similarity index 100% rename from compiler/testData/codegen/regressions/kt2596.kt rename to compiler/testData/codegen/box/ranges/kt2596.kt diff --git a/compiler/tests/org/jetbrains/jet/codegen/ExtensionFunctionsTest.java b/compiler/tests/org/jetbrains/jet/codegen/ExtensionFunctionsTest.java deleted file mode 100644 index eafbfa1ab70..00000000000 --- a/compiler/tests/org/jetbrains/jet/codegen/ExtensionFunctionsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.codegen; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.ConfigurationKind; - -import java.lang.reflect.Method; - -import static org.jetbrains.jet.codegen.CodegenTestUtil.assertThrows; - -public class ExtensionFunctionsTest extends CodegenTestCase { - @Override - protected void setUp() throws Exception { - super.setUp(); - createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); - } - - @NotNull - @Override - protected String getPrefix() { - return "extensionFunctions"; - } - - public void testSimple() throws Exception { - loadFile(); - final Method foo = generateFunction("foo"); - final Character c = (Character) foo.invoke(null); - assertEquals('f', c.charValue()); - } - - public void testWhenFail() throws Exception { - loadFile(); - Method foo = generateFunction("foo"); - assertThrows(foo, Exception.class, null, new StringBuilder()); - } -} diff --git a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java index 9b9868d0048..5d2d2dd40ee 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java @@ -79,10 +79,6 @@ public class StdlibTest extends CodegenTestCase { blackBoxFile("regressions/kt789.kt"); } - public void testKt828 () { - blackBoxFile("regressions/kt828.kt"); - } - public void testKt715 () { blackBoxFile("regressions/kt715.kt"); } @@ -356,10 +352,6 @@ public class StdlibTest extends CodegenTestCase { blackBoxFile("regressions/kt2246.kt"); } - public void testKt2596() { - blackBoxFile("regressions/kt2596.kt"); - } - public void testCollections() { blackBoxFile("jdk-annotations/collections.kt"); } diff --git a/compiler/tests/org/jetbrains/jet/codegen/TypeInfoTest.java b/compiler/tests/org/jetbrains/jet/codegen/TypeInfoTest.java deleted file mode 100644 index e61cbf7a5ff..00000000000 --- a/compiler/tests/org/jetbrains/jet/codegen/TypeInfoTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.codegen; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.ConfigurationKind; - -import java.lang.reflect.Method; - -import static org.jetbrains.jet.codegen.CodegenTestUtil.assertThrows; - -public class TypeInfoTest extends CodegenTestCase { - @Override - protected void setUp() throws Exception { - super.setUp(); - createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); - } - - @NotNull - @Override - protected String getPrefix() { - return "typeInfo"; - } - - public void testAsSafeOperator() throws Exception { - loadText("fun foo(x: Any) = x as? Runnable"); - Method foo = generateFunction(); - assertNull(foo.invoke(null, new Object())); - Runnable r = newRunnable(); - assertSame(r, foo.invoke(null, r)); - } - - public void testAsOperator() throws Exception { - loadText("fun foo(x: Any) = x as Runnable"); - Method foo = generateFunction(); - Runnable r = newRunnable(); - assertSame(r, foo.invoke(null, r)); - assertThrows(foo, ClassCastException.class, null, new Object()); - } - - public void testIsOperator() throws Exception { - loadText("fun foo(x: Any) = x is Runnable"); - Method foo = generateFunction(); - assertFalse((Boolean) foo.invoke(null, new Object())); - assertTrue((Boolean) foo.invoke(null, newRunnable())); - } - - public void testNotIsOperator() throws Exception { - loadText("fun foo(x: Any) = x !is Runnable"); - Method foo = generateFunction(); - assertTrue((Boolean) foo.invoke(null, new Object())); - assertFalse((Boolean) foo.invoke(null, newRunnable())); - } - - private Runnable newRunnable() { - return new Runnable() { - @Override - public void run() { - } - }; - } -} diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java index ee85b1c61ee..09a237273cc 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -29,7 +29,7 @@ import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("compiler/testData/codegen/box") -@InnerTestClasses({BlackBoxCodegenTestGenerated.Arrays.class, BlackBoxCodegenTestGenerated.Bridges.class, BlackBoxCodegenTestGenerated.Classes.class, BlackBoxCodegenTestGenerated.Closures.class, BlackBoxCodegenTestGenerated.ControlStructures.class, BlackBoxCodegenTestGenerated.DefaultArguments.class, BlackBoxCodegenTestGenerated.Enum.class, BlackBoxCodegenTestGenerated.ExtensionFunctions.class, BlackBoxCodegenTestGenerated.ExtensionProperties.class, BlackBoxCodegenTestGenerated.Functions.class, BlackBoxCodegenTestGenerated.InnerNested.class, BlackBoxCodegenTestGenerated.Instructions.class, BlackBoxCodegenTestGenerated.Intrinsics.class, BlackBoxCodegenTestGenerated.Labels.class, BlackBoxCodegenTestGenerated.LocalClasses.class, BlackBoxCodegenTestGenerated.MultiDecl.class, BlackBoxCodegenTestGenerated.Namespace.class, BlackBoxCodegenTestGenerated.Objects.class, BlackBoxCodegenTestGenerated.OperatorConventions.class, BlackBoxCodegenTestGenerated.PrimitiveTypes.class, BlackBoxCodegenTestGenerated.Properties.class, BlackBoxCodegenTestGenerated.SafeCall.class, BlackBoxCodegenTestGenerated.Strings.class, BlackBoxCodegenTestGenerated.Super.class, BlackBoxCodegenTestGenerated.Traits.class, BlackBoxCodegenTestGenerated.TypeInfo.class, BlackBoxCodegenTestGenerated.Unit.class, BlackBoxCodegenTestGenerated.Vararg.class, BlackBoxCodegenTestGenerated.When.class}) +@InnerTestClasses({BlackBoxCodegenTestGenerated.Arrays.class, BlackBoxCodegenTestGenerated.Bridges.class, BlackBoxCodegenTestGenerated.Casts.class, BlackBoxCodegenTestGenerated.Classes.class, BlackBoxCodegenTestGenerated.Closures.class, BlackBoxCodegenTestGenerated.ControlStructures.class, BlackBoxCodegenTestGenerated.DefaultArguments.class, BlackBoxCodegenTestGenerated.Enum.class, BlackBoxCodegenTestGenerated.ExtensionFunctions.class, BlackBoxCodegenTestGenerated.ExtensionProperties.class, BlackBoxCodegenTestGenerated.Functions.class, BlackBoxCodegenTestGenerated.InnerNested.class, BlackBoxCodegenTestGenerated.Instructions.class, BlackBoxCodegenTestGenerated.Intrinsics.class, BlackBoxCodegenTestGenerated.Labels.class, BlackBoxCodegenTestGenerated.LocalClasses.class, BlackBoxCodegenTestGenerated.MultiDecl.class, BlackBoxCodegenTestGenerated.Namespace.class, BlackBoxCodegenTestGenerated.Objects.class, BlackBoxCodegenTestGenerated.OperatorConventions.class, BlackBoxCodegenTestGenerated.PrimitiveTypes.class, BlackBoxCodegenTestGenerated.Properties.class, BlackBoxCodegenTestGenerated.Ranges.class, BlackBoxCodegenTestGenerated.SafeCall.class, BlackBoxCodegenTestGenerated.Strings.class, BlackBoxCodegenTestGenerated.Super.class, BlackBoxCodegenTestGenerated.Traits.class, BlackBoxCodegenTestGenerated.TypeInfo.class, BlackBoxCodegenTestGenerated.Unit.class, BlackBoxCodegenTestGenerated.Vararg.class, BlackBoxCodegenTestGenerated.When.class}) public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInBox() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/box"), "kt", true); @@ -416,6 +416,34 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } + @TestMetadata("compiler/testData/codegen/box/casts") + public static class Casts extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInCasts() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/box/casts"), "kt", true); + } + + @TestMetadata("as.kt") + public void testAs() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/box/casts/as.kt"); + } + + @TestMetadata("asSafe.kt") + public void testAsSafe() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/box/casts/asSafe.kt"); + } + + @TestMetadata("is.kt") + public void testIs() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/box/casts/is.kt"); + } + + @TestMetadata("notIs.kt") + public void testNotIs() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/box/casts/notIs.kt"); + } + + } + @TestMetadata("compiler/testData/codegen/box/classes") public static class Classes extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInClasses() throws Exception { @@ -1436,11 +1464,21 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { blackBoxFileByFullPath("compiler/testData/codegen/box/extensionFunctions/shared.kt"); } + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/box/extensionFunctions/simple.kt"); + } + @TestMetadata("virtual.kt") public void testVirtual() throws Exception { blackBoxFileByFullPath("compiler/testData/codegen/box/extensionFunctions/virtual.kt"); } + @TestMetadata("whenFail.kt") + public void testWhenFail() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/box/extensionFunctions/whenFail.kt"); + } + } @TestMetadata("compiler/testData/codegen/box/extensionProperties") @@ -2769,6 +2807,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { blackBoxFileByFullPath("compiler/testData/codegen/box/primitiveTypes/kt821.kt"); } + @TestMetadata("kt828.kt") + public void testKt828() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/box/primitiveTypes/kt828.kt"); + } + @TestMetadata("kt877.kt") public void testKt877() throws Exception { blackBoxFileByFullPath("compiler/testData/codegen/box/primitiveTypes/kt877.kt"); @@ -2914,6 +2957,19 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } + @TestMetadata("compiler/testData/codegen/box/ranges") + public static class Ranges extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInRanges() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/box/ranges"), "kt", true); + } + + @TestMetadata("kt2596.kt") + public void testKt2596() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/box/ranges/kt2596.kt"); + } + + } + @TestMetadata("compiler/testData/codegen/box/safeCall") public static class SafeCall extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInSafeCall() throws Exception { @@ -3248,6 +3304,7 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { suite.addTestSuite(BlackBoxCodegenTestGenerated.class); suite.addTestSuite(Arrays.class); suite.addTestSuite(Bridges.class); + suite.addTestSuite(Casts.class); suite.addTestSuite(Classes.class); suite.addTestSuite(Closures.class); suite.addTestSuite(ControlStructures.class); @@ -3267,6 +3324,7 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { suite.addTest(OperatorConventions.innerSuite()); suite.addTestSuite(PrimitiveTypes.class); suite.addTestSuite(Properties.class); + suite.addTestSuite(Ranges.class); suite.addTestSuite(SafeCall.class); suite.addTestSuite(Strings.class); suite.addTestSuite(Super.class);