[K2/N] Rewrite mpp tests from old native infra to new

^KT-58543

Merge-request: KT-MR-10065
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
This commit is contained in:
Vladimir Sukharev
2023-05-16 08:41:39 +00:00
committed by Space Team
parent 2b913d7c47
commit bbe1e708f9
35 changed files with 2067 additions and 823 deletions
@@ -0,0 +1,45 @@
// !LANGUAGE: +MultiPlatformProjects
// TARGET_BACKEND: JS_IR
// TARGET_BACKEND: NATIVE
// TARGET_BACKEND: WASM
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: ANY
// MODULE: common
// FILE: common.kt
expect class A {
constructor()
inner class B {
fun fourtyTwo(): Int
constructor()
}
}
expect fun seventeen(): Int
// MODULE: actual()()(common)
// FILE: actual.kt
actual fun seventeen() = 17
actual class A {
actual inner class B actual constructor() {
actual fun fourtyTwo() = 42
}
}
fun box(): String {
val fourtyTwo = A().B().fourtyTwo()
if (fourtyTwo != 42)
return "fourtyTwo is wrongly $fourtyTwo"
val seventeen = seventeen()
if (seventeen != 17)
return "seventeen is wrongly $seventeen"
return "OK"
}
@@ -0,0 +1,49 @@
// !LANGUAGE: +MultiPlatformProjects
// TARGET_BACKEND: JS_IR
// TARGET_BACKEND: NATIVE
// TARGET_BACKEND: WASM
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: ANY
// MODULE: common
// FILE: common.kt
expect class C {
constructor(arg: Any?)
}
expect class T
expect fun f(arg: Int): Int
expect var p: String
// MODULE: actual()()(common)
// FILE: actual.kt
actual data class C actual constructor(val arg: Any?) {}
actual typealias T = C
actual fun f(arg: Int) = arg
actual var p: String = "p"
fun box(): String {
val c = C(42).toString()
if (c != "C(arg=42)")
return "c is wrongly $c"
val cIsT = C(42) is T
if (!cIsT)
return "C(42) is wrongly not T"
val f = f(1)
if (f != 1)
return "f is wrongly $f"
p = "h"
if (p != "h")
return "p is wrongly $p"
return "OK"
}
@@ -0,0 +1,104 @@
// !LANGUAGE: +MultiPlatformProjects
// TARGET_BACKEND: JS_IR
// TARGET_BACKEND: NATIVE
// TARGET_BACKEND: WASM
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: ANY
// IllegalArgumentException: arg wrongly != this@Test5: arg=null, this@Test5=[object Object]
// IGNORE_BACKEND_K2: JS_IR
// Wrong box result 'arg1 wrongly != this@Test5: arg1=Inner@1346131020, this@Test5=Test5@314569418'; Expected "OK"
// IGNORE_BACKEND: WASM
// MODULE: common
// FILE: common.kt
// Default parameter in inline function.
expect inline fun inlineFunction(a: String, b: Int = 0, c: () -> Double? = { null }): String
expect fun test1(x: Int = 42): Int
expect fun test2(x: Int, y: Int = x): Int
expect fun test3(x: Int = 42, y: Int = x + 1): Int
expect fun Int.test6(arg: Int = this): String
expect class Test4 {
fun test(arg: Any = this): String
}
expect class Test5 {
inner class Inner {
constructor(arg: Any = this@Test5)
fun test(arg1: Any = this@Test5, arg2: Any = this@Inner): String
}
}
// MODULE: actual()()(common)
// FILE: actual.kt
actual inline fun inlineFunction(a: String, b: Int, c: () -> Double?): String = a + "," + b + "," + c()
actual fun test1(x: Int) = x
actual fun test2(x: Int, y: Int) = x + y
actual fun test3(x: Int, y: Int) = x - y
actual fun Int.test6(arg: Int): String {
if (arg != this)
return "arg wrongly != this: arg=$arg, this=$this"
return "OK"
}
actual class Test4 {
actual fun test(arg: Any): String {
if (arg != this)
return "arg wrongly != this: arg=$arg, this=$this"
return "OK"
}
}
actual class Test5 {
actual inner class Inner {
actual constructor(arg: Any) {
if (arg != this@Test5)
throw IllegalArgumentException("arg wrongly != this@Test5: arg=$arg, this@Test5=${this@Test5}")
}
actual fun test(arg1: Any, arg2: Any): String {
if (arg1 != this@Test5)
return "arg1 wrongly != this@Test5: arg1=$arg1, this@Test5=${this@Test5}"
if (arg2 != this@Inner)
return "arg2 wrongly != this@Inner: arg2=$arg2, this@Inner=${this@Inner}"
return "OK"
}
}
}
fun box(): String {
val test1 = test1()
if (test1 != 42)
return "test1 is wrongly $test1"
val test2 = test2(17)
if (test2 != 34)
return "test2 is wrongly $test2"
val test3 = test3()
if (test3 != -1)
return "test3 is wrongly $test3"
val test4 = Test4().test()
if (test4 != "OK")
return test4
val test5 = Test5().Inner().test()
if (test5 != "OK")
return test5
val test6 = 42.test6()
if (test6 != "OK")
return test6
val inlineFunctionResult = inlineFunction("OK")
if (inlineFunctionResult != "OK,0,null")
return "inlineFunctionResult is wrongly $inlineFunctionResult"
return "OK"
}
@@ -0,0 +1,30 @@
// TARGET_BACKEND: JS_IR
// TARGET_BACKEND: NATIVE
// TARGET_BACKEND: WASM
// TARGET_BACKEND: JVM_IR
// Stdlib is needed only for JVM_IR to resolve `kotlin.OptionalExpectation
// WITH_STDLIB
// LANGUAGE: +MultiPlatformProjects
@file:Suppress("OPT_IN_USAGE_ERROR", "OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE")
@OptionalExpectation
expect annotation class Optional()
@Optional
fun foo() = "42"
fun bar() = "43"
fun box(): String {
val foo = foo()
if (foo != "42")
return "foo is wrongly $foo"
val bar = bar()
if (bar != "43")
return "bar is wrongly $bar"
return "OK"
}
@@ -0,0 +1,34 @@
// !LANGUAGE: +MultiPlatformProjects
// !OPT_IN: kotlin.ExperimentalMultiplatform
// TARGET_BACKEND: JS_IR
// TARGET_BACKEND: NATIVE
// TARGET_BACKEND: WASM
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: ANY
// Can't link symbol function Foo.<get-p>
// IGNORE_BACKEND: WASM
// MODULE: common
// FILE: common.kt
expect class Foo {
val p: Int
fun bar(r: () -> Int = this::p): Int
}
// MODULE: actual()()(common)
// FILE: actual.kt
actual class Foo {
actual val p = 42
actual fun bar(r: () -> Int) = r()
}
fun box(): String {
val bar = Foo().bar()
if (bar != 42)
return "bar is wrongly $bar"
return "OK"
}
@@ -0,0 +1,43 @@
// !LANGUAGE: +MultiPlatformProjects
// TARGET_BACKEND: JS_IR
// TARGET_BACKEND: NATIVE
// TARGET_BACKEND: WASM
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K2: ANY
// FILE: common.kt
expect class A {
constructor()
inner class B {
fun fourtyTwo(): Int
constructor()
}
}
expect fun seventeen(): Int
// FILE: actual.kt
actual fun seventeen() = 17
actual class A {
actual inner class B actual constructor() {
actual fun fourtyTwo() = 42
}
}
fun box(): String {
val fourtyTwo = A().B().fourtyTwo()
if (fourtyTwo != 42)
return "fourtyTwo is wrongly $fourtyTwo"
val seventeen = seventeen()
if (seventeen != 17)
return "seventeen is wrongly $seventeen"
return "OK"
}
@@ -0,0 +1,47 @@
// !LANGUAGE: +MultiPlatformProjects
// TARGET_BACKEND: JS_IR
// TARGET_BACKEND: NATIVE
// TARGET_BACKEND: WASM
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K2: ANY
// FILE: common.kt
expect class C {
constructor(arg: Any?)
}
expect class T
expect fun f(arg: Int): Int
expect var p: String
// FILE: actual.kt
actual data class C actual constructor(val arg: Any?) {}
actual typealias T = C
actual fun f(arg: Int) = arg
actual var p: String = "p"
fun box(): String {
val c = C(42).toString()
if (c != "C(arg=42)")
return "c is wrongly $c"
val cIsT = C(42) is T
if (!cIsT)
return "C(42) is wrongly not T"
val f = f(1)
if (f != 1)
return "f is wrongly $f"
p = "h"
if (p != "h")
return "p is wrongly $p"
return "OK"
}
@@ -0,0 +1,102 @@
// !LANGUAGE: +MultiPlatformProjects
// TARGET_BACKEND: JS_IR
// TARGET_BACKEND: NATIVE
// TARGET_BACKEND: WASM
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K2: ANY
// IllegalArgumentException: arg wrongly != this@Test5: arg=null, this@Test5=[object Object]
// IGNORE_BACKEND_K1: JS_IR, JS_IR_ES6
// Wrong box result 'arg1 wrongly != this@Test5: arg1=Inner@1342209928, this@Test5=Test5@167512675'; Expected "OK"
// IGNORE_BACKEND_K1: WASM
// FILE: common.kt
// Default parameter in inline function.
expect inline fun inlineFunction(a: String, b: Int = 0, c: () -> Double? = { null }): String
expect fun test1(x: Int = 42): Int
expect fun test2(x: Int, y: Int = x): Int
expect fun test3(x: Int = 42, y: Int = x + 1): Int
expect fun Int.test6(arg: Int = this): String
expect class Test4 {
fun test(arg: Any = this): String
}
expect class Test5 {
inner class Inner {
constructor(arg: Any = this@Test5)
fun test(arg1: Any = this@Test5, arg2: Any = this@Inner): String
}
}
// FILE: actual.kt
actual inline fun inlineFunction(a: String, b: Int, c: () -> Double?): String = a + "," + b + "," + c()
actual fun test1(x: Int) = x
actual fun test2(x: Int, y: Int) = x + y
actual fun test3(x: Int, y: Int) = x - y
actual fun Int.test6(arg: Int): String {
if (arg != this)
return "arg wrongly != this: arg=$arg, this=$this"
return "OK"
}
actual class Test4 {
actual fun test(arg: Any): String {
if (arg != this)
return "arg wrongly != this: arg=$arg, this=$this"
return "OK"
}
}
actual class Test5 {
actual inner class Inner {
actual constructor(arg: Any) {
if (arg != this@Test5)
throw IllegalArgumentException("arg wrongly != this@Test5: arg=$arg, this@Test5=${this@Test5}")
}
actual fun test(arg1: Any, arg2: Any): String {
if (arg1 != this@Test5)
return "arg1 wrongly != this@Test5: arg1=$arg1, this@Test5=${this@Test5}"
if (arg2 != this@Inner)
return "arg2 wrongly != this@Inner: arg2=$arg2, this@Inner=${this@Inner}"
return "OK"
}
}
}
fun box(): String {
val test1 = test1()
if (test1 != 42)
return "test1 is wrongly $test1"
val test2 = test2(17)
if (test2 != 34)
return "test2 is wrongly $test2"
val test3 = test3()
if (test3 != -1)
return "test3 is wrongly $test3"
val test4 = Test4().test()
if (test4 != "OK")
return test4
val test5 = Test5().Inner().test()
if (test5 != "OK")
return test5
val test6 = 42.test6()
if (test6 != "OK")
return test6
val inlineFunctionResult = inlineFunction("OK")
if (inlineFunctionResult != "OK,0,null")
return "inlineFunctionResult is wrongly $inlineFunctionResult"
return "OK"
}
@@ -0,0 +1,32 @@
// LANGUAGE: +MultiPlatformProjects
// !OPT_IN: kotlin.ExperimentalMultiplatform
// TARGET_BACKEND: JS_IR
// TARGET_BACKEND: NATIVE
// TARGET_BACKEND: WASM
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K2: ANY
// Can't link symbol function Foo.<get-p>
// IGNORE_BACKEND_K1: WASM
// FILE: common.kt
expect class Foo {
val p: Int
fun bar(r: () -> Int = this::p): Int
}
// FILE: actual.kt
actual class Foo {
actual val p = 42
actual fun bar(r: () -> Int) = r()
}
fun box(): String {
val bar = Foo().bar()
if (bar != 42)
return "bar is wrongly $bar"
return "OK"
}