Split GenerateNotNullAssertionsTests into standard box and bytecode tests

This commit is contained in:
Steven Schäfer
2019-07-02 10:07:37 +02:00
committed by Alexander Udalov
parent dfd0042a5b
commit dd20b74030
33 changed files with 668 additions and 360 deletions
@@ -0,0 +1,28 @@
// TARGET_BACKEND: JVM
// FILE: Test.java
public class Test {
public static void callFoo() {
new A().foo(null);
}
}
// FILE: Test.kt
class A {
fun foo(s: String) {}
}
fun box(): String {
try {
Test.callFoo()
return "Fail 1"
} catch (e : IllegalArgumentException) {
if (e.message != "Parameter specified as non-null is null: method A.foo, parameter s") {
return "Fail 2 (message: ${e.message})"
}
} catch (e : Throwable) {
return "Fail 3 (exception class: ${e::class.simpleName})"
}
return "OK"
}
@@ -0,0 +1,126 @@
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS
// IGNORE_BACKEND: JVM_IR
// Missing IMPLICIT_NOTNULL casts
// FILE: A.java
import org.jetbrains.annotations.NotNull;
public class A {
@NotNull
public final String NULL = null;
@NotNull
public static final String STATIC_NULL = null;
public String foo() {
return null;
}
public static String staticFoo() {
return null;
}
public A plus(A a) {
return null;
}
public A inc() {
return null;
}
public Object get(Object o) {
return null;
}
public A a() { return this; }
public static class B {
public static B b() { return null; }
}
public static class C {
public static C c() { return null; }
}
}
// FILE: AssertionChecker.kt
class AssertionChecker(val illegalStateExpected: Boolean) {
operator fun invoke(name: String, f: () -> Any) {
try {
f()
} catch (e: IllegalStateException) {
if (!illegalStateExpected) throw AssertionError("Unexpected IllegalStateException on calling $name")
return
}
if (illegalStateExpected) throw AssertionError("IllegalStateException expected on calling $name")
}
}
interface Tr {
fun foo(): String
}
class Derived : A(), Tr {
override fun foo() = super<A>.foo()
}
class Delegated : Tr by Derived() {
}
fun checkAssertions(illegalStateExpected: Boolean) {
val check = AssertionChecker(illegalStateExpected)
// simple call
check("foo") { A().foo() }
// simple static call
check("staticFoo") { A.staticFoo() }
// supercall
check("foo") { Derived().foo() }
// delegated call
check("foo") { Delegated().foo() }
// collection element
check("get") { A()[""] }
// binary expression
check("plus") { A() + A() }
// field
check("NULL") { A().NULL }
// static field
check("STATIC_NULL") { A.STATIC_NULL }
// postfix expression
// TODO:
// check("inc") { var a = A().a(); a++ }
// prefix expression
check("inc-b") { var a = A.B.b(); a++ }
// prefix expression
check("inc-c") { var a = A.C.c(); a++ }
// prefix expression
check("inc") { var a = A().a(); ++a }
// prefix expression
check("inc-b") { var a = A.B.b(); ++a }
// prefix expression
// TODO:
// check("inc-c") { var a = A.C.c(); ++a }
}
operator fun A.C.inc(): A.C = A.C()
operator fun <T> T.inc(): T = null as T
fun box(): String {
checkAssertions(true)
return "OK"
}
@@ -0,0 +1,36 @@
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_CALL_ASSERTIONS
// FILE: C.java
package test;
import org.jetbrains.annotations.NotNull;
public abstract class C<Type> {
public abstract void doTest(@NotNull Type s);
public static void runTest(C a) {
try {
a.doTest(null);
} catch (IllegalArgumentException e) {
return;
}
throw new AssertionError("Fail: IllegalArgumentException expected");
}
}
// FILE: B.kt
import test.C
class TestString : C<String>() {
override fun doTest(s: String) { }
}
class TestUnit : C<Unit>() {
override fun doTest(s: Unit) { }
}
fun box(): String {
C.runTest(TestString())
C.runTest(TestUnit())
return "OK"
}
@@ -1,3 +1,49 @@
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS, +JVM.DISABLE_CALL_ASSERTIONS
// IGNORE_BACKEND: JVM_IR
// FILE: A.java
import org.jetbrains.annotations.NotNull;
public class A {
@NotNull
public final String NULL = null;
@NotNull
public static final String STATIC_NULL = null;
public String foo() {
return null;
}
public static String staticFoo() {
return null;
}
public A plus(A a) {
return null;
}
public A inc() {
return null;
}
public Object get(Object o) {
return null;
}
public A a() { return this; }
public static class B {
public static B b() { return null; }
}
public static class C {
public static C c() { return null; }
}
}
// FILE: AssertionChecker.kt
class AssertionChecker(val illegalStateExpected: Boolean) {
operator fun invoke(name: String, f: () -> Any) {
try {
@@ -22,31 +68,30 @@ class Derived : A(), Tr {
class Delegated : Tr by Derived() {
}
fun checkAssertions(illegalStateExpected: Boolean) {
val check = AssertionChecker(illegalStateExpected)
// simple call
check("foo") { A().foo() }
// simple static call
check("staticFoo") { A.staticFoo() }
// supercall
check("foo") { Derived().foo() }
// delegated call
check("foo") { Delegated().foo() }
// collection element
check("get") { A()[""] }
// binary expression
check("plus") { A() + A() }
// field
check("NULL") { A().NULL }
// static field
check("STATIC_NULL") { A.STATIC_NULL }
@@ -73,3 +118,8 @@ fun checkAssertions(illegalStateExpected: Boolean) {
operator fun A.C.inc(): A.C = A.C()
operator fun <T> T.inc(): T = null as T
fun box(): String {
checkAssertions(false)
return "OK"
}
@@ -1,3 +1,5 @@
// IGNORE_BACKEND: JVM_IR
// Missing IMPLICIT_NOTNULL casts
import java.util.ArrayList
fun foo(): Any {
@@ -7,3 +9,6 @@ fun foo(): Any {
fun bar(a: ArrayList<String>) {
}
// 1 checkExpressionValueIsNotNull
// 1 checkParameterIsNotNull
@@ -1,3 +1,6 @@
// IGNORE_BACKEND: JVM_IR
// Missing IMPLICIT_NOTNULL casts
class A<T> {
fun add(element: T) {}
}
@@ -5,3 +8,5 @@ class A<T> {
public fun <R : Any> foo(x: MutableCollection<in R>, block: java.util.AbstractList<R>) {
x.add(block.get(0))
}
// 1 checkExpressionValueIsNotNull
@@ -0,0 +1,3 @@
fun <T : Any> foo(t: T) = t
// 1 checkParameterIsNotNull
@@ -0,0 +1,9 @@
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS
// IGNORE_BACKEND: JVM_IR
class A {
fun foo(s: String) {
}
}
// 0 kotlin/jvm/internal/Intrinsics
@@ -0,0 +1,38 @@
// IGNORE_BACKEND: JVM_IR
// Missing IMPLICIT_NOTNULL casts
// FILE: A.java
import org.jetbrains.annotations.NotNull;
class A<T, U> {
@NotNull
T foo() { return null; }
}
// FILE: B.java
import org.jetbrains.annotations.NotNull;
class B<T> extends A<T, Integer> {
@Override
@NotNull
T foo() { return null; }
}
// FILE: C.java
import org.jetbrains.annotations.NotNull;
class C extends B<String> {
@Override
@NotNull
String foo() { return null; }
}
// FILE: javaMultipleSubstitutions.kt
internal fun bar(a: A<String, Int>, b: B<String>, c: C) {
val sa: String = a.foo()
val sb: String = b.foo()
val sc: String = c.foo()
}
// @JavaMultipleSubstitutionsKt.class
// 3 checkExpressionValueIsNotNull
// 3 checkParameterIsNotNull
@@ -1,3 +1,6 @@
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS
// IGNORE_BACKEND: JVM_IR
class A<T> {
fun add(element: T) {}
}
@@ -5,3 +8,5 @@ class A<T> {
public fun <R> foo(x: MutableCollection<in R>, block: () -> R) {
x.add(block())
}
// 0 kotlin/jvm/internal/Intrinsics
@@ -0,0 +1,8 @@
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS
// IGNORE_BACKEND: JVM_IR
fun <T> foo(a: List<T>) {
val t: T = a.get(0)
}
// 0 kotlin/jvm/internal/Intrinsics
@@ -0,0 +1,11 @@
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS
import java.util.HashMap
class A<T: Any> {
fun main() {
HashMap<String, T>()[""]
}
}
// 0 kotlin/jvm/internal/Intrinsics
@@ -2,3 +2,5 @@ class A {
private fun foo(s: String) {
}
}
// 0 kotlin/jvm/internal/Intrinsics
@@ -0,0 +1,33 @@
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS
// FILE: noAssertionsForKotlin.kt
class A {
val x: Int = 42
fun foo(): String = ""
companion object {
val y: Any? = 239
fun bar(): String = ""
}
}
fun baz(): String = ""
// FILE: noAssertionsForKotlinMain.kt
fun bar() {
val x = A().x
val foo = A().foo()
val y = A.y
val bar = A.bar()
val baz = baz()
}
// @A.class:
// 0 kotlin/jvm/internal/Intrinsics
// @NoAssertionsForKotlinKt.class:
// 0 kotlin/jvm/internal/Intrinsics
// @NoAssertionsForKotlinMainKt.class:
// 0 kotlin/jvm/internal/Intrinsics
-39
View File
@@ -1,39 +0,0 @@
import org.jetbrains.annotations.NotNull;
public class A {
@NotNull
public final String NULL = null;
@NotNull
public static final String STATIC_NULL = null;
public String foo() {
return null;
}
public static String staticFoo() {
return null;
}
public A plus(A a) {
return null;
}
public A inc() {
return null;
}
public Object get(Object o) {
return null;
}
public A a() { return this; }
public static class B {
public static B b() { return null; }
}
public static class C {
public static C c() { return null; }
}
}
@@ -1 +0,0 @@
fun <T : Any> foo(t: T) = t
@@ -1,17 +0,0 @@
package test;
import org.jetbrains.annotations.NotNull;
public abstract class doGenerateParamAssertions<Type> {
public abstract void doTest(@NotNull Type s);
public static void runTest(doGenerateParamAssertions a) {
try {
a.doTest(null);
} catch (IllegalArgumentException e) {
return;
}
throw new AssertionError("Fail: IllegalArgumentException expected");
}
}
@@ -1,14 +0,0 @@
import test.doGenerateParamAssertions as C
class TestString : C<String>() {
override fun doTest(s: String) { }
}
class TestUnit : C<Unit>() {
override fun doTest(s: Unit) { }
}
fun doTest() {
C.runTest(TestString())
C.runTest(TestUnit())
}
@@ -1,4 +0,0 @@
class A {
fun foo(s: String) {
}
}
@@ -1,18 +0,0 @@
import org.jetbrains.annotations.NotNull;
class A<T, U> {
@NotNull
T foo() { return null; }
}
class B<T> extends A<T, Integer> {
@Override
@NotNull
T foo() { return null; }
}
class C extends B<String> {
@Override
@NotNull
String foo() { return null; }
}
@@ -1,5 +0,0 @@
internal fun bar(a: A<String, Int>, b: B<String>, c: C) {
val sa: String = a.foo()
val sb: String = b.foo()
val sc: String = c.foo()
}
@@ -1,3 +0,0 @@
fun <T> foo(a: List<T>) {
val t: T = a.get(0)
}
@@ -1,7 +0,0 @@
import java.util.HashMap
class A<T: Any> {
fun main() {
HashMap<String, T>()[""]
}
}