Extract some codegen tests to black box testData
This commit is contained in:
committed by
Alexander Udalov
parent
f7e0b06c2f
commit
10c5949199
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
fun StringBuilder.first() = this.charAt(0)
|
||||
|
||||
fun foo() = StringBuilder("foo").first()
|
||||
|
||||
fun box() = if (foo() == 'f') "OK" else "Fail ${foo()}"
|
||||
+10
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+59
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user