Add codegen tests for old behavior of null checks

#KT-22275
This commit is contained in:
Alexander Udalov
2020-01-22 15:58:49 +01:00
parent 632fe18db6
commit 2fca7f1a54
15 changed files with 160 additions and 127 deletions
@@ -0,0 +1,15 @@
// !API_VERSION: 1.3
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
fun box(): String {
val s: String? = null
try {
s!!
return "Fail: KNPE should have been thrown"
} catch (e: Throwable) {
if (e::class != KotlinNullPointerException::class) return "Fail: exception class should be KNPE: ${e::class}"
return "OK"
}
}
@@ -1,4 +1,3 @@
// !API_VERSION: LATEST
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
@@ -0,0 +1,23 @@
// !API_VERSION: 1.3
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: A.java
import org.jetbrains.annotations.NotNull;
public class A {
@NotNull
public static String foo() { return null; }
}
// FILE: test.kt
fun box(): String {
try {
val s: String = A.foo()
return "Fail: ISE should have been thrown"
} catch (e: Throwable) {
if (e::class != IllegalStateException::class) return "Fail: exception class should be ISE: ${e::class}"
return "OK"
}
}
@@ -1,4 +1,3 @@
// !API_VERSION: LATEST
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: A.java
@@ -0,0 +1,26 @@
// !API_VERSION: 1.3
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: A.java
public class A {
public static void test() {
new B().foo(null);
}
}
// FILE: test.kt
class B {
fun foo(s: String) {}
}
fun box(): String {
try {
A.test()
return "Fail: IAE should have been thrown"
} catch (e: Throwable) {
if (e::class != IllegalArgumentException::class) return "Fail: exception class should be IAE: ${e::class}"
return "OK"
}
}
@@ -1,4 +1,3 @@
// !API_VERSION: LATEST
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: A.java
@@ -1,16 +0,0 @@
// !API_VERSION: LATEST
// FILE: 1.kt
package test
public inline fun <R> doRun(block: () -> R): R {
return block()
}
// FILE: 2.kt
import test.*
fun box(): String {
return doRun { "OK" }
}
@@ -17305,9 +17305,14 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/nullCheckOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("exclExclThrowsNpe_1_4.kt")
public void testExclExclThrowsNpe_1_4() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/exclExclThrowsNpe_1_4.kt");
@TestMetadata("exclExclThrowsKnpe_1_3.kt")
public void testExclExclThrowsKnpe_1_3() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/exclExclThrowsKnpe_1_3.kt");
}
@TestMetadata("exclExclThrowsNpe.kt")
public void testExclExclThrowsNpe() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/exclExclThrowsNpe.kt");
}
@TestMetadata("isNullable.kt")
@@ -17315,9 +17320,14 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/nullCheckOptimization/isNullable.kt");
}
@TestMetadata("javaNullCheckThrowsNpe_1_4.kt")
public void testJavaNullCheckThrowsNpe_1_4() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/javaNullCheckThrowsNpe_1_4.kt");
@TestMetadata("javaNullCheckThrowsIse_1_3.kt")
public void testJavaNullCheckThrowsIse_1_3() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/javaNullCheckThrowsIse_1_3.kt");
}
@TestMetadata("javaNullCheckThrowsNpe.kt")
public void testJavaNullCheckThrowsNpe() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/javaNullCheckThrowsNpe.kt");
}
@TestMetadata("kt22410.kt")
@@ -17330,9 +17340,14 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt7774.kt");
}
@TestMetadata("parameterNullCheckThrowsNpe_1_4.kt")
public void testParameterNullCheckThrowsNpe_1_4() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/parameterNullCheckThrowsNpe_1_4.kt");
@TestMetadata("parameterNullCheckThrowsIae_1_3.kt")
public void testParameterNullCheckThrowsIae_1_3() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/parameterNullCheckThrowsIae_1_3.kt");
}
@TestMetadata("parameterNullCheckThrowsNpe.kt")
public void testParameterNullCheckThrowsNpe() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/parameterNullCheckThrowsNpe.kt");
}
@TestMetadata("primitiveCheckWithSideEffect.kt")
@@ -2591,24 +2591,6 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
}
}
@TestMetadata("compiler/testData/codegen/boxInline/nullChecks")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class NullChecks extends AbstractBlackBoxInlineCodegenTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
public void testAllFilesPresentInNullChecks() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/nullChecks"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("parameterNullCheck_1_4.kt")
public void testParameterNullCheck_1_4() throws Exception {
runTest("compiler/testData/codegen/boxInline/nullChecks/parameterNullCheck_1_4.kt");
}
}
@TestMetadata("compiler/testData/codegen/boxInline/optimizations")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -2591,24 +2591,6 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
}
}
@TestMetadata("compiler/testData/codegen/boxInline/nullChecks")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class NullChecks extends AbstractCompileKotlinAgainstInlineKotlinTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM, testDataFilePath, "// IGNORE_BACKEND_MULTI_MODULE: ");
}
public void testAllFilesPresentInNullChecks() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/nullChecks"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("parameterNullCheck_1_4.kt")
public void testParameterNullCheck_1_4() throws Exception {
runTest("compiler/testData/codegen/boxInline/nullChecks/parameterNullCheck_1_4.kt");
}
}
@TestMetadata("compiler/testData/codegen/boxInline/optimizations")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -17305,9 +17305,14 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/nullCheckOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("exclExclThrowsNpe_1_4.kt")
public void testExclExclThrowsNpe_1_4() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/exclExclThrowsNpe_1_4.kt");
@TestMetadata("exclExclThrowsKnpe_1_3.kt")
public void testExclExclThrowsKnpe_1_3() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/exclExclThrowsKnpe_1_3.kt");
}
@TestMetadata("exclExclThrowsNpe.kt")
public void testExclExclThrowsNpe() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/exclExclThrowsNpe.kt");
}
@TestMetadata("isNullable.kt")
@@ -17315,9 +17320,14 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/nullCheckOptimization/isNullable.kt");
}
@TestMetadata("javaNullCheckThrowsNpe_1_4.kt")
public void testJavaNullCheckThrowsNpe_1_4() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/javaNullCheckThrowsNpe_1_4.kt");
@TestMetadata("javaNullCheckThrowsIse_1_3.kt")
public void testJavaNullCheckThrowsIse_1_3() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/javaNullCheckThrowsIse_1_3.kt");
}
@TestMetadata("javaNullCheckThrowsNpe.kt")
public void testJavaNullCheckThrowsNpe() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/javaNullCheckThrowsNpe.kt");
}
@TestMetadata("kt22410.kt")
@@ -17330,9 +17340,14 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt7774.kt");
}
@TestMetadata("parameterNullCheckThrowsNpe_1_4.kt")
public void testParameterNullCheckThrowsNpe_1_4() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/parameterNullCheckThrowsNpe_1_4.kt");
@TestMetadata("parameterNullCheckThrowsIae_1_3.kt")
public void testParameterNullCheckThrowsIae_1_3() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/parameterNullCheckThrowsIae_1_3.kt");
}
@TestMetadata("parameterNullCheckThrowsNpe.kt")
public void testParameterNullCheckThrowsNpe() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/parameterNullCheckThrowsNpe.kt");
}
@TestMetadata("primitiveCheckWithSideEffect.kt")
@@ -16150,9 +16150,14 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/nullCheckOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("exclExclThrowsNpe_1_4.kt")
public void testExclExclThrowsNpe_1_4() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/exclExclThrowsNpe_1_4.kt");
@TestMetadata("exclExclThrowsKnpe_1_3.kt")
public void testExclExclThrowsKnpe_1_3() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/exclExclThrowsKnpe_1_3.kt");
}
@TestMetadata("exclExclThrowsNpe.kt")
public void testExclExclThrowsNpe() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/exclExclThrowsNpe.kt");
}
@TestMetadata("isNullable.kt")
@@ -16160,9 +16165,14 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/nullCheckOptimization/isNullable.kt");
}
@TestMetadata("javaNullCheckThrowsNpe_1_4.kt")
public void testJavaNullCheckThrowsNpe_1_4() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/javaNullCheckThrowsNpe_1_4.kt");
@TestMetadata("javaNullCheckThrowsIse_1_3.kt")
public void testJavaNullCheckThrowsIse_1_3() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/javaNullCheckThrowsIse_1_3.kt");
}
@TestMetadata("javaNullCheckThrowsNpe.kt")
public void testJavaNullCheckThrowsNpe() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/javaNullCheckThrowsNpe.kt");
}
@TestMetadata("kt22410.kt")
@@ -16175,9 +16185,14 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt7774.kt");
}
@TestMetadata("parameterNullCheckThrowsNpe_1_4.kt")
public void testParameterNullCheckThrowsNpe_1_4() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/parameterNullCheckThrowsNpe_1_4.kt");
@TestMetadata("parameterNullCheckThrowsIae_1_3.kt")
public void testParameterNullCheckThrowsIae_1_3() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/parameterNullCheckThrowsIae_1_3.kt");
}
@TestMetadata("parameterNullCheckThrowsNpe.kt")
public void testParameterNullCheckThrowsNpe() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/parameterNullCheckThrowsNpe.kt");
}
@TestMetadata("primitiveCheckWithSideEffect.kt")
@@ -16150,9 +16150,14 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/nullCheckOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("exclExclThrowsNpe_1_4.kt")
public void testExclExclThrowsNpe_1_4() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/exclExclThrowsNpe_1_4.kt");
@TestMetadata("exclExclThrowsKnpe_1_3.kt")
public void testExclExclThrowsKnpe_1_3() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/exclExclThrowsKnpe_1_3.kt");
}
@TestMetadata("exclExclThrowsNpe.kt")
public void testExclExclThrowsNpe() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/exclExclThrowsNpe.kt");
}
@TestMetadata("isNullable.kt")
@@ -16160,9 +16165,14 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/nullCheckOptimization/isNullable.kt");
}
@TestMetadata("javaNullCheckThrowsNpe_1_4.kt")
public void testJavaNullCheckThrowsNpe_1_4() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/javaNullCheckThrowsNpe_1_4.kt");
@TestMetadata("javaNullCheckThrowsIse_1_3.kt")
public void testJavaNullCheckThrowsIse_1_3() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/javaNullCheckThrowsIse_1_3.kt");
}
@TestMetadata("javaNullCheckThrowsNpe.kt")
public void testJavaNullCheckThrowsNpe() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/javaNullCheckThrowsNpe.kt");
}
@TestMetadata("kt22410.kt")
@@ -16175,9 +16185,14 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt7774.kt");
}
@TestMetadata("parameterNullCheckThrowsNpe_1_4.kt")
public void testParameterNullCheckThrowsNpe_1_4() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/parameterNullCheckThrowsNpe_1_4.kt");
@TestMetadata("parameterNullCheckThrowsIae_1_3.kt")
public void testParameterNullCheckThrowsIae_1_3() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/parameterNullCheckThrowsIae_1_3.kt");
}
@TestMetadata("parameterNullCheckThrowsNpe.kt")
public void testParameterNullCheckThrowsNpe() throws Exception {
runTest("compiler/testData/codegen/box/nullCheckOptimization/parameterNullCheckThrowsNpe.kt");
}
@TestMetadata("primitiveCheckWithSideEffect.kt")
@@ -2591,24 +2591,6 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
}
}
@TestMetadata("compiler/testData/codegen/boxInline/nullChecks")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class NullChecks extends AbstractIrBlackBoxInlineCodegenTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
}
public void testAllFilesPresentInNullChecks() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/nullChecks"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("parameterNullCheck_1_4.kt")
public void testParameterNullCheck_1_4() throws Exception {
runTest("compiler/testData/codegen/boxInline/nullChecks/parameterNullCheck_1_4.kt");
}
}
@TestMetadata("compiler/testData/codegen/boxInline/optimizations")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -2591,24 +2591,6 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
}
}
@TestMetadata("compiler/testData/codegen/boxInline/nullChecks")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class NullChecks extends AbstractIrCompileKotlinAgainstInlineKotlinTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_MULTI_MODULE: ");
}
public void testAllFilesPresentInNullChecks() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/nullChecks"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("parameterNullCheck_1_4.kt")
public void testParameterNullCheck_1_4() throws Exception {
runTest("compiler/testData/codegen/boxInline/nullChecks/parameterNullCheck_1_4.kt");
}
}
@TestMetadata("compiler/testData/codegen/boxInline/optimizations")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)