[Test] Merge box against java testdata into codegen black box testsdata

This commit is contained in:
Dmitriy Novozhilov
2021-01-27 16:21:31 +03:00
parent e62b118351
commit 3199ce03a6
165 changed files with 0 additions and 3948 deletions
@@ -0,0 +1,129 @@
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
// IGNORE_BACKEND_FIR: JVM_IR
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS
// MODULE: lib
// 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; }
}
}
// MODULE: main(lib)
// FILE: callAssertions.kt
class AssertionChecker(val nullPointerExceptionExpected: Boolean) {
operator fun invoke(name: String, f: () -> Any) {
try {
f()
} catch (e: NullPointerException) {
if (!nullPointerExceptionExpected) throw AssertionError("Unexpected NullPointerException on calling $name")
return
}
if (nullPointerExceptionExpected) throw AssertionError("NullPointerException 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 @@
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
// IGNORE_BACKEND_FIR: JVM_IR
// MODULE: lib
// FILE: Delegation.java
public class Delegation {
public static class ReturnNull {
public String foo() {
return null;
}
}
}
// MODULE: main(lib)
// FILE: delegation.kt
interface Tr {
fun foo(): String
}
class DelegateTo : Delegation.ReturnNull(), Tr {
override fun foo() = super<Delegation.ReturnNull>.foo()
}
class DelegateFrom : Tr by DelegateTo()
fun box(): String {
try {
DelegateFrom().foo()
return "Fail: should have been an exception"
}
catch(e: NullPointerException) {
return "OK"
}
}
@@ -0,0 +1,39 @@
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_CALL_ASSERTIONS
// MODULE: lib
// 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 (NullPointerException e) {
return;
}
throw new AssertionError("Fail: NullPointerException expected");
}
}
// MODULE: main(lib)
// 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,128 @@
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS, +JVM.DISABLE_CALL_ASSERTIONS
// MODULE: lib
// 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; }
}
}
// MODULE: main(lib)
// FILE: noCallAssertions.kt
class AssertionChecker(val nullPointerExceptionExpected: Boolean) {
operator fun invoke(name: String, f: () -> Any) {
try {
f()
} catch (e: NullPointerException) {
if (!nullPointerExceptionExpected) throw AssertionError("Unexpected NullPointerException on calling $name")
return
}
if (nullPointerExceptionExpected) throw AssertionError("NullPointerException 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(nullPointerExceptionExpected: Boolean) {
val check = AssertionChecker(nullPointerExceptionExpected)
// 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"
}
@@ -0,0 +1,35 @@
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
// IGNORE_BACKEND_FIR: JVM_IR
// MODULE: lib
// FILE: RightElvisOperand.java
class RightElvisOperand {
static String foo() {
return null;
}
}
// MODULE: main(lib)
// FILE: 1.kt
fun baz(): String? = null
fun bar(): String = baz() ?: RightElvisOperand.foo()
fun foo(x: String) {}
fun box(): String {
try {
foo(baz() ?: RightElvisOperand.foo())
return "Fail: should have been an exception in `foo(baz() ?: RightElvisOperand.foo())`"
}
catch(e: NullPointerException) {}
try {
bar()
return "Fail: should have been an exception in `bar()`"
}
catch(e: NullPointerException) {
return "OK"
}
}