[Spec tests] Add tests for not-null-assertion-expression

This commit is contained in:
anastasiia.spaseeva
2019-12-23 18:41:33 +03:00
parent e4d12593be
commit 0a1b8a928c
9 changed files with 407 additions and 0 deletions
@@ -0,0 +1,36 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-220
* PLACE: expressions, not-null-assertion-expression -> paragraph 2 -> sentence 2
* RELEVANT PLACES: expressions, not-null-assertion-expression -> paragraph 2 -> sentence 1
* NUMBER: 1
* DESCRIPTION: For an expression e!!, if the type of e is nullable, a not-null assertion expression checks, whether the evaluation result of e is equal to null and, if it is, throws a runtime exception.
*/
// MODULE: libModule
// FILE: libModule/JavaClass.java
package libModule;
public class JavaClass {
public static Boolean FALSE;
}
// MODULE: mainModule(libModule)
// FILE: KotlinClass.kt
package mainModule
import libModule.*
fun box(): String {
try {
val x = JavaClass.FALSE!!
}catch (e: java.lang.NullPointerException){
return "OK"
}
return "NOK"
}
@@ -0,0 +1,27 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-220
* PLACE: expressions, not-null-assertion-expression -> paragraph 2 -> sentence 2
* RELEVANT PLACES: expressions, not-null-assertion-expression -> paragraph 2 -> sentence 1
* NUMBER: 2
* DESCRIPTION: For an expression e!!, if the type of e is nullable, a not-null assertion expression checks, whether the evaluation result of e is equal to null and, if it is, throws a runtime exception.
*/
fun box(): String {
val x = A(A(A(A())))
if ( x.a!!.a!!.a!!.a == null)
{
try {
val t = x.a!!.a!!.a!!.a!!
}catch (e: java.lang.NullPointerException){
return "OK"
}
}
return "NOK"
}
class A ( val a: A? = null)
@@ -0,0 +1,21 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-220
* PLACE: expressions, not-null-assertion-expression -> paragraph 2 -> sentence 3
* NUMBER: 1
* DESCRIPTION: If the evaluation result of e is not equal to null, the result of e!! is the evaluation result of e.
*/
fun box(): String {
val x: String? = "str"
try {
val y = x!!
}catch (e: java.lang.NullPointerException){
return "NOK"
}
return "OK"
}
@@ -0,0 +1,44 @@
{
"2": {
"pos": {
"2": [
{
"specVersion": "0.1-220",
"casesNumber": 0,
"description": "For an expression e!!, if the type of e is nullable, a not-null assertion expression checks, whether the evaluation result of e is equal to null and, if it is, throws a runtime exception.",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-220",
"casesNumber": 0,
"description": "For an expression e!!, if the type of e is nullable, a not-null assertion expression checks, whether the evaluation result of e is equal to null and, if it is, throws a runtime exception.",
"unexpectedBehaviour": false
}
],
"1": [
{
"specVersion": "0.1-220",
"casesNumber": 0,
"description": "For an expression e!!, if the type of e is nullable, a not-null assertion expression checks, whether the evaluation result of e is equal to null and, if it is, throws a runtime exception.",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/not-null-assertion-expression/p-2/pos/2.1.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-220",
"casesNumber": 0,
"description": "For an expression e!!, if the type of e is nullable, a not-null assertion expression checks, whether the evaluation result of e is equal to null and, if it is, throws a runtime exception.",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/not-null-assertion-expression/p-2/pos/2.2.kt",
"unexpectedBehaviour": false
}
],
"3": [
{
"specVersion": "0.1-220",
"casesNumber": 0,
"description": "If the evaluation result of e is not equal to null, the result of e!! is the evaluation result of e.",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -0,0 +1,54 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNREACHABLE_CODE -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-220
* PLACE: expressions, not-null-assertion-expression -> paragraph 3 -> sentence 1
* NUMBER: 1
* DESCRIPTION: If the type of e is non-nullable, not-null assertion expression e!! has no effect.
*/
// MODULE: libModule
// FILE: libModule/JavaClass.java
package libModule;
public class JavaClass {
public static final boolean FALSE = false;
public static int obj = 5;
}
// MODULE: mainModule(libModule)
// FILE: KotlinClass.kt
package mainModule
import libModule.*
// TESTCASE NUMBER: 1
fun case1() {
val res = JavaClass.FALSE<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
// TESTCASE NUMBER: 2
fun case2() {
val x = JavaClass.obj<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
// TESTCASE NUMBER: 3
fun case3() {
val a = false
val x = a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
// TESTCASE NUMBER: 4
fun case4() {
val x = "weds"<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
// TESTCASE NUMBER: 5
fun case5(nothing: Nothing) {
val y = nothing<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
@@ -0,0 +1,70 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNREACHABLE_CODE -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-220
* PLACE: expressions, not-null-assertion-expression -> paragraph 4 -> sentence 1
* NUMBER: 1
* DESCRIPTION: The type of non-null assertion e!! expression is the non-nullable variant of the type of e.
* HELPERS: checktype
*/
// MODULE: libModule
// FILE: libModule/JavaClass.java
package libModule;
public class JavaClass {
public static final String STR;
public static Object obj;
}
// MODULE: mainModule(libModule)
// FILE: KotlinClass.kt
package mainModule
import libModule.*
import checkSubtype
// TESTCASE NUMBER: 1
fun case1() {
val a = JavaClass.STR
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.String..kotlin.String?)")!>a<!>
val res = a!!
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>res<!>
}
// TESTCASE NUMBER: 2
fun case2() {
val a = JavaClass.obj
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.Any..kotlin.Any?)")!>a<!>
val x = a!!
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>x<!>
}
// TESTCASE NUMBER: 3
fun case3() {
val a : Any? = false
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>a<!>
val x = a!!
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>x<!>
}
// TESTCASE NUMBER: 4
fun case4() {
val a : String? = "weds"
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String?")!>a<!>
val x = a!!
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>x<!>
}
// TESTCASE NUMBER: 5
fun case5(nothing: Nothing?) {
<!DEBUG_INFO_CONSTANT, DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing?")!>nothing<!>
val y = <!ALWAYS_NULL!>nothing<!>!!
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>y<!>
}
@@ -0,0 +1,26 @@
{
"4": {
"pos": {
"1": [
{
"specVersion": "0.1-220",
"casesNumber": 5,
"description": "The type of non-null assertion e!! expression is the non-nullable variant of the type of e.",
"unexpectedBehaviour": false
}
]
}
},
"3": {
"pos": {
"1": [
{
"specVersion": "0.1-220",
"casesNumber": 5,
"description": "If the type of e is non-nullable, not-null assertion expression e!! has no effect.",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -1992,6 +1992,81 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
}
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Not_null_assertion_expression extends AbstractDiagnosticsTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInNot_null_assertion_expression() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression/p-3")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class P_3 extends AbstractDiagnosticsTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInP_3() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression/p-3"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression/p-3/pos")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Pos extends AbstractDiagnosticsTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("1.1.kt")
public void test1_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression/p-3/pos/1.1.kt");
}
public void testAllFilesPresentInPos() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression/p-3/pos"), Pattern.compile("^(.+)\\.kt$"), true);
}
}
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression/p-4")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class P_4 extends AbstractDiagnosticsTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInP_4() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression/p-4"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression/p-4/pos")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Pos extends AbstractDiagnosticsTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("1.1.kt")
public void test1_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression/p-4/pos/1.1.kt");
}
public void testAllFilesPresentInPos() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/not-null-assertion-expression/p-4/pos"), Pattern.compile("^(.+)\\.kt$"), true);
}
}
}
}
@TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/prefix-expressions")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -1481,6 +1481,60 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes
}
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/not-null-assertion-expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Not_null_assertion_expression extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInNot_null_assertion_expression() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/not-null-assertion-expression"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/not-null-assertion-expression/p-2")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class P_2 extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInP_2() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/not-null-assertion-expression/p-2"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/not-null-assertion-expression/p-2/pos")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Pos extends AbstractBlackBoxCodegenTestSpec {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("2.1.kt")
public void test2_1() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/not-null-assertion-expression/p-2/pos/2.1.kt");
}
@TestMetadata("2.2.kt")
public void test2_2() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/not-null-assertion-expression/p-2/pos/2.2.kt");
}
@TestMetadata("3.1.kt")
public void test3_1() throws Exception {
runTest("compiler/tests-spec/testData/codegen/box/linked/expressions/not-null-assertion-expression/p-2/pos/3.1.kt");
}
public void testAllFilesPresentInPos() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/not-null-assertion-expression/p-2/pos"), Pattern.compile("^(.+)\\.kt$"), true);
}
}
}
}
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/postfix-operator-expressions")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)