Implement new assert semantics in back-end
Previously, assert was just a regular function and its argument used to be computed on each call (even if assertions are disabled on JVM). This change adds support for 3 new behaviours of assert: * always-enable (independently from -ea on JVM) * always-disable (independently from -ea JVM) * runtime/jvm (compile the calls like javac generates assert-operator) * legacy (leave current eager semantics) - this already existed Default behaviour is legacy for now. The behavior is changed based on -Xassertions flag. #KT-7540: Fixed
This commit is contained in:
+139
@@ -700,6 +700,145 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/assert")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Assert extends AbstractBlackBoxCodegenTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInAssert() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/assert"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("alwaysDisable.kt")
|
||||
public void testAlwaysDisable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/assert/alwaysDisable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("alwaysEnable.kt")
|
||||
public void testAlwaysEnable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/assert/alwaysEnable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("legacy.kt")
|
||||
public void testLegacy() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/assert/legacy.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/assert/jvm")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Jvm extends AbstractBlackBoxCodegenTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInJvm() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/assert/jvm"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("interfaceAssertionsDisabled.kt")
|
||||
public void testInterfaceAssertionsDisabled() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/assert/jvm/interfaceAssertionsDisabled.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("interfaceAssertionsEnabled.kt")
|
||||
public void testInterfaceAssertionsEnabled() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/assert/jvm/interfaceAssertionsEnabled.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localAnonymousFunction.kt")
|
||||
public void testLocalAnonymousFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/assert/jvm/localAnonymousFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localClass.kt")
|
||||
public void testLocalClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/assert/jvm/localClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localFunction.kt")
|
||||
public void testLocalFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/assert/jvm/localFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localLambda.kt")
|
||||
public void testLocalLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/assert/jvm/localLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localObject.kt")
|
||||
public void testLocalObject() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/assert/jvm/localObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nonLocalReturn.kt")
|
||||
public void testNonLocalReturn() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/assert/jvm/nonLocalReturn.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ordinary.kt")
|
||||
public void testOrdinary() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/assert/jvm/ordinary.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("superClassInitializer.kt")
|
||||
public void testSuperClassInitializer() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/assert/jvm/superClassInitializer.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendFunctionAssertionDisabled.kt")
|
||||
public void testSuspendFunctionAssertionDisabled_1_2() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt");
|
||||
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendFunctionAssertionDisabled.kt")
|
||||
public void testSuspendFunctionAssertionDisabled_1_3() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt");
|
||||
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendFunctionAssertionsEnabled.kt")
|
||||
public void testSuspendFunctionAssertionsEnabled_1_2() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt");
|
||||
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendFunctionAssertionsEnabled.kt")
|
||||
public void testSuspendFunctionAssertionsEnabled_1_3() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt");
|
||||
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendLambdaAssertionsDisabled.kt")
|
||||
public void testSuspendLambdaAssertionsDisabled_1_2() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt");
|
||||
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendLambdaAssertionsDisabled.kt")
|
||||
public void testSuspendLambdaAssertionsDisabled_1_3() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt");
|
||||
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendLambdaAssertionsEnabled.kt")
|
||||
public void testSuspendLambdaAssertionsEnabled_1_2() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt");
|
||||
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendLambdaAssertionsEnabled.kt")
|
||||
public void testSuspendLambdaAssertionsEnabled_1_3() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt");
|
||||
doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/binaryOp")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user