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,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"
}
@@ -0,0 +1,125 @@
// 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 {
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(false)
return "OK"
}