Add box tests for new nullability assertions

This commit is contained in:
Dmitry Petrov
2017-10-24 13:18:59 +03:00
parent 2a7d555be4
commit 706a3698ec
11 changed files with 573 additions and 234 deletions

View File

@@ -0,0 +1,29 @@
// TARGET_BACKEND: JVM
// STRICT_JAVA_NULLABILITY_ASSERTIONS
// FILE: box.kt
fun box(): String {
try {
J().test()
return "Fail: should throw"
}
catch (e: Throwable) {
return "OK"
}
}
// FILE: test.kt
fun withAssertion(j: J) = j.nullString()
// FILE: J.java
import org.jetbrains.annotations.NotNull;
public class J {
public @NotNull String nullString() {
return null;
}
public void test() {
TestKt.withAssertion(this);
}
}

View File

@@ -0,0 +1,34 @@
// TARGET_BACKEND: JVM
// STRICT_JAVA_NULLABILITY_ASSERTIONS
// See KT-8135
// We could generate runtime assertion on call site for 'generic<NOT_NULL_TYPE>()' below.
// FILE: box.kt
fun box(): String {
try {
J().test()
return "OK"
}
catch (e: Throwable) {
return "Fail: SHOULD NOT throw"
}
}
// FILE: test.kt
fun withAssertion(j: J) = generic<String?>(j)
fun <T> generic(j: J) = j.nullT<T>()
// FILE: J.java
import org.jetbrains.annotations.NotNull;
public class J {
public <T> @NotNull T nullT() {
return null;
}
public void test() {
TestKt.withAssertion(this);
}
}

View File

@@ -0,0 +1,28 @@
// TARGET_BACKEND: JVM
// STRICT_JAVA_NULLABILITY_ASSERTIONS
// FILE: box.kt
fun box(): String {
try {
outer()
return "Fail: should throw"
}
catch (e: Throwable) {
return "OK"
}
}
// FILE: test.kt
fun outer() {
fun withAssertion() = J().nullString()
withAssertion() // NB not used itself
}
// FILE: J.java
import org.jetbrains.annotations.NotNull;
public class J {
public @NotNull String nullString() {
return null;
}
}

View File

@@ -0,0 +1,31 @@
// TARGET_BACKEND: JVM
// STRICT_JAVA_NULLABILITY_ASSERTIONS
// FILE: box.kt
fun box(): String {
try {
J().test()
return "Fail: should throw"
}
catch (e: Throwable) {
return "OK"
}
}
// FILE: test.kt
fun withAssertion(j: J) {
val x = j.nullString()
}
// FILE: J.java
import org.jetbrains.annotations.NotNull;
public class J {
public @NotNull String nullString() {
return null;
}
public void test() {
TestKt.withAssertion(this);
}
}

View File

@@ -0,0 +1,31 @@
// TARGET_BACKEND: JVM
// STRICT_JAVA_NULLABILITY_ASSERTIONS
// FILE: box.kt
fun box(): String {
try {
J().test()
return "Fail: should throw"
}
catch (e: Throwable) {
return "OK"
}
}
// FILE: test.kt
class C {
val withAssertion = J().nullString()
}
// FILE: J.java
import org.jetbrains.annotations.NotNull;
public class J {
public @NotNull String nullString() {
return null;
}
public Object test() {
return new C();
}
}

View File

@@ -0,0 +1,29 @@
// TARGET_BACKEND: JVM
// STRICT_JAVA_NULLABILITY_ASSERTIONS
// FILE: box.kt
fun box(): String {
try {
J().test()
return "Fail: should throw"
}
catch (e: Throwable) {
return "OK"
}
}
// FILE: test.kt
val withAssertion get() = J().nullString()
// FILE: J.java
import org.jetbrains.annotations.NotNull;
public class J {
public @NotNull String nullString() {
return null;
}
public void test() {
TestKt.getWithAssertion();
}
}

View File

@@ -0,0 +1,31 @@
// TARGET_BACKEND: JVM
// STRICT_JAVA_NULLABILITY_ASSERTIONS
// FILE: box.kt
fun box(): String {
try {
J().test()
return "Fail: should throw"
}
catch (e: Throwable) {
return "OK"
}
}
// FILE: test.kt
val withAssertion = J().nullString()
fun clinitTrigger() {}
// FILE: J.java
import org.jetbrains.annotations.NotNull;
public class J {
public @NotNull String nullString() {
return null;
}
public void test() {
TestKt.clinitTrigger();
}
}