[K/N][tests] Migrate link tests to new testing infra ^KT-61259

This commit is contained in:
Alexander Shabalin
2023-12-20 16:40:03 +01:00
committed by Space Team
parent 588549d1d0
commit d6a922bc74
136 changed files with 1615 additions and 1246 deletions
@@ -0,0 +1,31 @@
// MODULE: lib
// FILE: lib.kt
package a
interface A<T> {
fun foo(): T
}
open class C: A<Int> {
override fun foo(): Int = 42
}
// MODULE: main(lib)
// FILE: main.kt
import a.*
import kotlin.test.*
class B: C()
fun box(): String {
val b = B()
assertEquals(42, b.foo())
val c: C = b
assertEquals(42, c.foo())
val a: A<Int> = b
assertEquals(42, a.foo())
return "OK"
}
@@ -0,0 +1,23 @@
// MODULE: lib
// FILE: lib.kt
sealed class Tag {
abstract fun value(): Any
}
sealed class TagBoolean : Tag() {
abstract override fun value(): String
object True : TagBoolean() {
override fun value() = "OK"
}
object False : TagBoolean() {
override fun value() = "FAIL"
}
}
// MODULE: main(lib)
// FILE: main.kt
fun box() = TagBoolean.True.value()
@@ -0,0 +1,39 @@
// MODULE: lib
// FILE: lib.kt
package zzz
interface I {
fun foo(): Int
}
open class A : I {
override fun foo() = 42
}
open class B : I by A() {
val x = 117
val y = "zzz"
}
// MODULE: main(lib)
// FILE: main.kt
import zzz.*
import kotlin.test.*
class C : B() {
val a = "qxx"
val b = 123
}
fun box(): String {
val c = C()
assertEquals("qxx", c.a)
assertEquals(123, c.b)
assertEquals(42, c.foo())
assertEquals(117, c.x)
assertEquals("zzz", c.y)
return "OK"
}
@@ -0,0 +1,30 @@
// MODULE: lib
// FILE: lib.kt
package zzz
open class B {
val z by lazy { "qzz" }
val x = 117
val zzz = "zzz"
}
// MODULE: main(lib)
// FILE: main.kt
import zzz.*
import kotlin.test.*
class C : B() {
val a = "qxx"
}
fun box(): String {
val c = C()
assertEquals("qxx", c.a)
assertEquals(117, c.x)
assertEquals("zzz", c.zzz)
assertEquals("qzz", c.z)
return "OK"
}
@@ -0,0 +1,60 @@
// MODULE: lib
// FILE: lib.kt
package a
import kotlin.reflect.KProperty
public val sb = StringBuilder()
open class A {
open val x = 42
}
class Delegate {
val f = 117
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
sb.appendLine(p.name)
return f
}
}
open class B: A() {
override val x: Int by Delegate()
fun bar() {
sb.appendLine(super<A>.x)
}
}
// MODULE: main(lib)
// FILE: main.kt
import a.*
import kotlin.test.*
open class C: B() {
override val x: Int = 156
fun foo() {
sb.appendLine(x)
sb.appendLine(super<B>.x)
bar()
}
}
fun box(): String {
val c = C()
c.foo()
assertEquals("""
156
x
117
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -0,0 +1,23 @@
// MODULE: lib
// FILE: lib.kt
package a
enum class A(val x: Int) {
Z1(42),
Z2(117),
Z3(-1)
}
// MODULE: main(lib)
// FILE: main.kt
import a.*
import kotlin.test.*
fun box(): String {
assertEquals(42, A.Z1.x)
assertEquals(117, A.valueOf("Z2").x)
assertEquals(-1, A.values()[2].x)
return "OK"
}
@@ -0,0 +1,13 @@
// MODULE: lib
// FILE: lib.kt
enum class Foo {
Z;
open fun bar() = "OK"
}
// MODULE: main(lib)
// FILE: main.kt
fun box() = Foo.Z.bar()
@@ -0,0 +1,16 @@
// MODULE: lib
// FILE: lib.kt
val a = 10
val b = a * 6
val c = a * b * 2
// MODULE: main(lib)
// FILE: main.kt
import kotlin.test.*
fun box(): String {
assertEquals(1200, c)
return "OK"
}
@@ -0,0 +1,11 @@
// MODULE: lib
// FILE: lib.kt
val a = mutableListOf<String>()
val b = 1.also { a += "OK" }
val c = a.single()
// MODULE: main(lib)
// FILE: main.kt
fun box() = c
@@ -0,0 +1,21 @@
// MODULE: lib
// FILE: lib.kt
class A {
val x: String
init {
var y = "FAIL"
fun foo() { y = "OK" }
foo()
x = y
}
}
// MODULE: main(lib)
// FILE: main.kt
fun box() = A().x
@@ -0,0 +1,18 @@
// MODULE: lib
// FILE: lib.kt
package a
inline fun foo(x: Int, y: Int = 117) = x + y
// MODULE: main(lib)
// FILE: main.kt
import a.*
import kotlin.test.*
fun box(): String {
assertEquals(122, foo(5))
assertEquals(47, foo(5, 42))
return "OK"
}
@@ -0,0 +1,22 @@
// MODULE: lib
// FILE: lib.kt
package a
fun foo(n: Int, block: (Int) -> Int): Int {
val arr = IntArray(n) { block(it) }
var sum = 0
for (x in arr) sum += x
return sum
}
// MODULE: main(lib)
// FILE: main.kt
import a.*
import kotlin.test.*
fun box(): String {
assertEquals(42, foo(7) { it * 2 })
return "OK"
}
@@ -0,0 +1,19 @@
// MODULE: lib
// FILE: lib.kt
package a
class E(val x: String) {
inner class Inner {
inline fun foo(y: String) = x + y
}
}
// MODULE: main(lib)
// FILE: main.kt
import a.*
fun box(): String {
return E("O").Inner().foo("K")
}
@@ -0,0 +1,35 @@
// KT-64511: lateinit is not lowered with caches
// DISABLE_NATIVE: cacheMode=STATIC_EVERYWHERE
// DISABLE_NATIVE: cacheMode=STATIC_PER_FILE_EVERYWHERE
// MODULE: lib
// FILE: lib.kt
package a
fun IntArray.forEachNoInline(block: (Int) -> Unit) = this.forEach { block(it) }
inline fun foo(values: IntArray, crossinline block: (Int, Int, Int) -> Int): Int {
val o = object {
lateinit var s: String
var x: Int = 42
}
values.forEachNoInline {
o.x = block(o.x, o.s.length, it)
}
return o.x
}
// MODULE: main(lib)
// FILE: main.kt
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
import a.*
import kotlin.test.*
fun box(): String {
assertFailsWith<UninitializedPropertyAccessException> {
foo(intArrayOf(1, 2, 3)) { x, y, z -> x + y - z }
}
return "OK"
}
@@ -0,0 +1,25 @@
// MODULE: lib
// FILE: lib.kt
package a
fun IntArray.forEachNoInline(block: (Int) -> Unit) = this.forEach { block(it) }
inline fun fold(initial: Int, values: IntArray, crossinline block: (Int, Int) -> Int): Int {
var res = initial
values.forEachNoInline {
res = block(res, it)
}
return res
}
// MODULE: main(lib)
// FILE: main.kt
import a.*
import kotlin.test.*
fun box(): String {
assertEquals(6, fold(0, intArrayOf(1, 2, 3)) { x, y -> x + y })
return "OK"
}
@@ -0,0 +1,25 @@
// MODULE: lib
// FILE: lib.kt
open class Foo(val z: Int) {
open inner class FooInner {
fun foo() = z
}
}
// MODULE: main(lib)
// FILE: main.kt
import kotlin.test.*
class Bar : Foo(42) {
inner class BarInner(val x: Int) : FooInner()
}
fun box(): String {
val o = Bar().BarInner(117)
assertEquals(117, o.x)
assertEquals(42, o.foo())
return "OK"
}
@@ -0,0 +1,16 @@
// MODULE: lib
// FILE: lib.kt
open class Outer(val x: String) {
open inner class Inner1
inner class Middle(x: String) : Outer(x) {
inner class Inner2 : Inner1() {
fun foo() = this@Outer.x + this@Middle.x
}
}
}
// MODULE: main(lib)
// FILE: main.kt
fun box() = Outer("O").Middle("K").Inner2().foo()
@@ -0,0 +1,25 @@
// MODULE: lib
// FILE: lib.kt
open class Outer {
open inner class Inner1
inner class Middle {
inner class Inner2 : Inner1() {
fun getOuter() = this@Outer
fun getMiddle() = this@Middle
}
}
}
// MODULE: main(lib)
// FILE: main.kt
import kotlin.test.*
fun box(): String {
val o = Outer().Middle().Inner2()
assertNotSame(o.getOuter(), Outer())
assertNotSame(o.getMiddle(), Outer().Middle())
return "OK"
}
@@ -0,0 +1,17 @@
// MODULE: lib
// FILE: lib.kt
open class A {
open inner class Inner {
val x = "OK"
}
}
// MODULE: main(lib)
// FILE: main.kt
open class B : A() {
open inner class Inner : A.Inner()
}
fun box() = B().Inner().x
+9
View File
@@ -0,0 +1,9 @@
// MODULE: lib@name
// FILE: lib.kt
fun foo() = "OK"
// MODULE: main(lib@name)
// FILE: main.kt
fun box() = foo()
+23
View File
@@ -0,0 +1,23 @@
// MODULE: lib
// FILE: lib1.kt
package qwerty
fun foo(a: String): String {
return a
}
// FILE: lib2.kt
package qwerty
fun foo2(a: String): String {
return a
}
// MODULE: main(lib)
// FILE: main.kt
import qwerty.*
fun box() = foo(foo2("OK"))
+13
View File
@@ -0,0 +1,13 @@
// MODULE: lib
// FILE: lib.kt
package foo
fun foo() {}
// MODULE: main(lib)
// FILE: main.kt
// TODO: This test should be checking that there's no foo in the resulting binary.
fun box(): String = "OK"
@@ -0,0 +1,76 @@
// MODULE: lib
// FILE: lib.kt
val sb = StringBuilder()
// Private classes
private open class A {
public fun foo1() = sb.appendLine("PASS")
internal fun foo2() = sb.appendLine("PASS")
protected fun foo3() = sb.appendLine("PASS")
}
private class B:A() {
fun foo4() = foo3()
}
// Private interfaces
private interface C {
fun foo() = sb.appendLine("PASS")
}
private class D: C
fun runner() {
B().foo1()
B().foo2()
B().foo4()
D().foo()
// Objects
object : A(){
fun foo4() = foo3()
}.apply {
foo1()
foo2()
foo4()
}
// Function local classes
abstract class E {
public open fun foo1() = sb.appendLine("PASS")
internal open fun foo2() = sb.appendLine("PASS")
protected open fun foo3() = sb.appendLine("PASS")
}
class F : E() {
fun foo4() = foo3()
}
F().foo1()
F().foo2()
F().foo4()
}
// MODULE: main(lib)
// FILE: main.kt
import kotlin.test.*
fun box(): String {
runner()
assertEquals("""
PASS
PASS
PASS
PASS
PASS
PASS
PASS
PASS
PASS
PASS
""".trimIndent(), sb.toString())
return "OK"
}
@@ -0,0 +1,128 @@
// MODULE: lib
// FILE: lib.kt
val sb = StringBuilder()
// Private classes
private open class A {
public open fun foo1() = sb.appendLine("FAIL")
internal open fun foo2() = sb.appendLine("FAIL")
protected open fun foo3() = sb.appendLine("FAIL")
private fun foo4() = sb.appendLine("FAIL")
}
private class B:A() {
override public fun foo1() = sb.appendLine("PASS")
override internal fun foo2() = sb.appendLine("PASS")
override protected fun foo3() = sb.appendLine("PASS")
private fun foo4() = sb.appendLine("PASS")
fun foo5() = foo3()
fun foo6() = foo4()
}
private abstract class G {
public abstract fun foo1()
internal abstract fun foo2()
protected abstract fun foo3()
private fun foo4() = sb.appendLine("FAIL")
}
private class H:A() {
override public fun foo1() = sb.appendLine("PASS")
override internal fun foo2() = sb.appendLine("PASS")
override protected fun foo3() = sb.appendLine("PASS")
private fun foo4() = sb.appendLine("PASS")
fun foo5() = foo3()
fun foo6() = foo4()
}
// Private interfaces
private interface C {
fun foo() = sb.appendLine("FAIL")
}
private class D: C {
override fun foo() = sb.appendLine("PASS")
}
fun runner() {
B().foo1()
B().foo2()
B().foo5()
B().foo6()
H().foo1()
H().foo2()
H().foo5()
H().foo6()
D().foo()
// Objects
object : A(){
override public fun foo1() = sb.appendLine("PASS")
override internal fun foo2() = sb.appendLine("PASS")
override protected fun foo3() = sb.appendLine("PASS")
private fun foo4() = sb.appendLine("PASS")
fun foo5() = foo3()
fun foo6() = foo4()
}.apply {
foo1()
foo2()
foo5()
foo6()
}
// Function local classes
open class E {
public open fun foo1() = sb.appendLine("FAIL")
internal open fun foo2() = sb.appendLine("FAIL")
protected open fun foo3() = sb.appendLine("FAIL")
private fun foo4() = sb.appendLine("FAIL")
}
class F : E() {
public override fun foo1() = sb.appendLine("PASS")
internal override fun foo2() = sb.appendLine("PASS")
protected override fun foo3() = sb.appendLine("PASS")
private fun foo4() = sb.appendLine("PASS")
fun foo5() = foo3()
fun foo6() = foo4()
}
F().foo1()
F().foo2()
F().foo5()
F().foo6()
}
// MODULE: main(lib)
// FILE: main.kt
import kotlin.test.*
fun box(): String {
runner()
assertEquals("""
PASS
PASS
PASS
PASS
PASS
PASS
PASS
PASS
PASS
PASS
PASS
PASS
PASS
PASS
PASS
PASS
PASS
""".trimIndent(), sb.toString())
return "OK"
}
@@ -0,0 +1,17 @@
// MODULE: lib
// FILE: lib.kt
fun foo(): String {
val bar: String by lazy {
"OK"
}
return bar
}
// MODULE: main(lib)
// FILE: main.kt
import kotlin.test.*
fun box() = foo()
+25
View File
@@ -0,0 +1,25 @@
// MODULE: lib
// FILE: lib.kt
public fun mangle(l: List<Int>) = "Int direct $l"
public fun mangle(l: List<out Number>) = "out Number direct $l"
public fun mangle(l: List<*>) = "star direct $l"
// MODULE: main(lib)
// FILE: main.kt
import kotlin.test.*
fun box(): String {
val mutListInt = mutableListOf<Int>(1, 2, 3, 4)
val mutListNum = mutableListOf<Number>(9, 10, 11, 12)
val mutListAny = mutableListOf<Any>(5, 6, 7, 8)
assertEquals("Int direct [1, 2, 3, 4]", mangle(mutListInt))
assertEquals("out Number direct [9, 10, 11, 12]", mangle(mutListNum))
assertEquals("star direct [5, 6, 7, 8]", mangle(mutListAny))
return "OK"
}
@@ -0,0 +1,25 @@
// MODULE: lib
// FILE: lib.kt
public fun <T> mangle(l: T) = "no constructors $l"
public fun <T> mangle(l: T) where T: Comparable<T> = "single constructor $l"
public fun <T> mangle(l: T) where T: Comparable<T>, T: Number = "two constructors $l"
// MODULE: main(lib)
// FILE: main.kt
import kotlin.test.*
fun box(): String {
val any = mapOf<Float, Float>()
val comparable = "some string"
val number = 17
assertEquals("no constructors {}", mangle(any))
assertEquals("single constructor some string", mangle(comparable))
assertEquals("two constructors 17", mangle(number))
return "OK"
}
+25
View File
@@ -0,0 +1,25 @@
// MODULE: lib
// FILE: lib.kt
public fun <T> mangle(l: T) where T: List<Int> = "Int param $l"
public fun <T> mangle(l: T) where T: List<out Number> = "out Number param $l"
public fun <T> mangle(l: T) where T: List<*> = "star param $l"
// MODULE: main(lib)
// FILE: main.kt
import kotlin.test.*
fun box(): String {
val mutListInt = mutableListOf<Int>(1, 2, 3, 4)
val mutListNum = mutableListOf<Number>(9, 10, 11, 12)
val mutListAny = mutableListOf<Any>(5, 6, 7, 8)
assertEquals("Int param [1, 2, 3, 4]", mangle(mutListInt))
assertEquals("out Number param [9, 10, 11, 12]", mangle(mutListNum))
assertEquals("star param [5, 6, 7, 8]", mangle(mutListAny))
return "OK"
}
@@ -0,0 +1,18 @@
// MODULE: lib
// FILE: lib.kt
package a
class A(val x: String)
// MODULE: main(lib)
// FILE: main.kt
import a.*
fun box(): String {
val p1 = A::x
val a = A("K")
val p2 = a::x
return p1.get(A("O")) + p2.get()
}
@@ -0,0 +1,138 @@
// MODULE: lib
// FILE: lib.kt
package foo.bar
val sb = StringBuilder()
class R<T> {
inline fun bar(t: T) {
sb.appendLine("just a single class: $t")
}
}
class C {
inline fun foo() {
sb.appendLine("first level")
}
class D {
inline fun foo() {
sb.appendLine("second level")
}
class E {
inline fun foo() {
sb.appendLine("third levelxz")
}
}
}
}
class C2 {
inline fun foo() {
sb.appendLine("inner first level")
}
inner class D2 {
inline fun foo() {
sb.appendLine("inner second level")
}
inner class E2 {
inline fun foo() {
sb.appendLine("inner third level")
}
}
}
}
class C3<X> {
inline fun foo(x: X) {
sb.appendLine("types first level: $x")
}
class D3<X> {
inline fun foo(x: X) {
sb.appendLine("types second level $x")
}
class E3<X> {
inline fun foo(x: X) {
sb.appendLine("types third level $x")
}
}
}
}
class C4<X> {
inline fun foo(x: X) {
sb.appendLine("inner types first level: $x")
}
inner class D4<Y> {
inline fun foo(x: X, y: Y) {
sb.appendLine("inner types second level $x, $y")
}
inner class E4<Z> {
inline fun foo(x: X, y: Y, z: Z) {
sb.appendLine("inner types third level $x, $y, $z")
}
}
}
}
// MODULE: main(lib)
// FILE: main.kt
import foo.bar.*
import kotlin.test.*
fun box(): String {
val c = C()
val d = C.D()
val e = C.D.E()
c.foo()
d.foo()
e.foo()
val c2 = C2()
val d2 = C2().D2()
val e2 = C2().D2().E2()
c2.foo()
d2.foo()
e2.foo()
val c3 = C3<Int>()
val d3 = C3.D3<String>()
val e3 = C3.D3.E3<Float>()
c3.foo(13)
d3.foo("cha-cha-cha")
e3.foo(1.0f)
val c4 = C4<Int>()
val d4 = C4<String>().D4<Int>()
val e4 = C4<Int>().D4<String>().E4<Int>()
c4.foo(13)
d4.foo("cawabunga", 17)
e4.foo(19, "raqa-taqa", 23)
assertEquals("""
first level
second level
third levelxz
inner first level
inner second level
inner third level
types first level: 13
types second level cha-cha-cha
types third level 1.0
inner types first level: 13
inner types second level cawabunga, 17
inner types third level 19, raqa-taqa, 23
""".trimIndent(), sb.toString())
return "OK"
}
@@ -0,0 +1,20 @@
// MODULE: lib
// FILE: lib.kt
inline fun foo(): String {
try {
try {
throw Exception("O")
} catch (e: Throwable) {
throw Exception("${e.message}K")
}
} catch (e: Throwable) {
return e.message!!
}
return "FAIL"
}
// MODULE: main(lib)
// FILE: main.kt
fun box() = foo()
@@ -0,0 +1,14 @@
// MODULE: lib
// FILE: lib.kt
inline fun foo(x: Char = '\u042b') = x
// MODULE: main(lib)
// FILE: main.kt
import kotlin.test.*
fun box(): String {
assertEquals('\u042b', foo())
return "OK"
}
@@ -0,0 +1,16 @@
// MODULE: lib
// FILE: lib.kt
inline val Int.prop get() = SomeDataClass(second = this)
data class SomeDataClass(val first: Int = 17, val second: Int = 19, val third: Int = 23)
// MODULE: main(lib)
// FILE: main.kt
import kotlin.test.*
fun box(): String {
assertEquals(SomeDataClass(first = 17, second = 666, third = 23), 666.prop)
return "OK"
}
@@ -0,0 +1,19 @@
// MODULE: lib
// FILE: lib.kt
val sb = StringBuilder()
inline fun foo() {
do {
var x: Int = 999
sb.append("OK")
} while (x != 999)
}
// MODULE: main(lib)
// FILE: main.kt
fun box(): String {
foo()
return sb.toString()
}
@@ -0,0 +1,28 @@
// MODULE: lib
// FILE: lib.kt
enum class Color {
RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW
}
fun determineColor(code: Int): Color = when (code) {
0 -> Color.BLUE
1 -> Color.MAGENTA
else -> Color.CYAN
}
// MODULE: main(lib)
// FILE: main.kt
import kotlin.test.*
fun box(): String {
assertEquals(0, Color.RED.ordinal)
assertEquals(1, Color.GREEN.ordinal)
assertEquals(2, Color.BLUE.ordinal)
assertEquals(Color.BLUE, determineColor(0))
assertEquals(Color.MAGENTA, determineColor(1))
assertEquals(Color.CYAN, determineColor(2))
return "OK"
}
@@ -0,0 +1,32 @@
// MODULE: lib
// FILE: lib.kt
val sb = StringBuilder()
fun bar(vararg x: Int) {
x.forEach {
sb.appendLine(it)
}
sb.appendLine("size: ${x.size}")
}
inline fun foo() = bar(17, 19, 23, *intArrayOf(29, 31))
// MODULE: main(lib)
// FILE: main.kt
import kotlin.test.*
fun box(): String {
foo()
assertEquals("""
17
19
23
29
31
size: 5
""".trimIndent(), sb.toString())
return "OK"
}