diff --git a/native/native.tests/testData/codegen/annotations/annotations0.kt b/native/native.tests/testData/codegen/annotations/annotations0.kt index 2b1cd2ece97..c817a590d3c 100644 --- a/native/native.tests/testData/codegen/annotations/annotations0.kt +++ b/native/native.tests/testData/codegen/annotations/annotations0.kt @@ -5,23 +5,18 @@ // FILE: 1.kt -package codegen.annotations.annotations0 - import kotlin.test.* -import kotlinx.serialization.* @SerialInfo annotation class Foo(val x: Int, val y: String) -@Test fun runTest() { - val foo = @Suppress("ANNOTATION_CLASS_CONSTRUCTOR_CALL") Foo(42, "17") +fun box(): String { + val foo = @Suppress("ANNOTATION_CLASS_CONSTRUCTOR_CALL") Foo(42, "OK") assertEquals(foo.x, 42) - assertEquals(foo.y, "17") + return foo.y } // FILE: 2.kt -package kotlinx.serialization - @Target(AnnotationTarget.ANNOTATION_CLASS) annotation class SerialInfo diff --git a/native/native.tests/testData/codegen/arithmetic/basic.kt b/native/native.tests/testData/codegen/arithmetic/basic.kt deleted file mode 100644 index 28afd4c1746..00000000000 --- a/native/native.tests/testData/codegen/arithmetic/basic.kt +++ /dev/null @@ -1,96 +0,0 @@ -package codegen.arithmetic.basic - -import kotlin.test.* - -// Check that compiler doesn't optimize it to `true` -fun selfCmp1(x: Int) = x + 1 > x - -fun selfCmp2(x: Int) = x - 1 < x - -@Test -fun selfComparison() { - assertFalse(selfCmp1(Int.MAX_VALUE)) - assertFalse(selfCmp2(Int.MIN_VALUE)) -} - -private fun charCornersMinus(): Int { - val a: Char = 0xFFFF.toChar() - val b: Char = 0.toChar() - return a - b -} - -private fun charCornersComparison(): Boolean { - val a = 0xFFFF.toChar() - val b = 0.toChar() - return a < b -} - -@Test -fun charCornerCases() { - assertEquals(65535, charCornersMinus()) - assertFalse(charCornersComparison()) -} - -@Test -fun shifts() { - assertEquals(-2147483648, 1 shl -1) - assertEquals(0, 1 shr -1) - assertEquals(1, 1 shl 32) - assertEquals(1073741823, -1 ushr 2) - assertEquals(-1, -1 shr 2) -} - -@Test -@kotlin.ExperimentalUnsignedTypes -fun uintTests() { - assertEquals(UInt.MAX_VALUE, UInt.MIN_VALUE - 1u) -} - -@Test -fun charConversions() { - assertEquals(97.0, 'a'.toDouble()) - assertEquals(-1, Char.MAX_VALUE.toShort()) - assertEquals(32768, Short.MIN_VALUE.toChar().toInt()) - assertEquals(-1, Char.MAX_VALUE.toByte()) - assertEquals(65408, Byte.MIN_VALUE.toChar().toInt()) - assertEquals(0, Float.MIN_VALUE.toChar().toInt()) -} - -@Test -fun doubleBasic() { - assertEquals(1, 0f.compareTo(-0f)) - assertEquals(1, 0.0.compareTo(-0.0)) - - assertEquals(1.0, Double.fromBits(1.0.toBits())) - assertEquals(1.0f, Float.fromBits(1.0f.toBits())) - - assertEquals(Double.NaN, Double.fromBits((0 / 0.0).toBits())) - assertEquals(Float.NaN, Float.fromBits((0 / 0f).toBits())) -} - -@Test -fun integralToFloat() { - assertEquals(9.223372E18f, Long.MAX_VALUE.toFloat()) - assertEquals(-9.223372E18f, Long.MIN_VALUE.toFloat()) - - assertEquals(-2.147483648E9, Int.MIN_VALUE.toDouble()) - assertEquals(2.147483647E9, Int.MAX_VALUE.toDouble()) - - assertEquals(2147483647, Double.MAX_VALUE.toInt()) - assertEquals(0, Float.MIN_VALUE.toLong()) - - assertEquals(9223372036854775807, Float.MAX_VALUE.toLong()) - assertEquals(0, Double.MIN_VALUE.toInt()) -} - -@Test -fun compareIntToFloat() { - assertEquals(1, 0.compareTo(-0.0f)) - assertEquals(0, 0.compareTo(+0.0f)) -} - -@Test -fun testKt37412() { - val two = 2.0 - assertEquals(2, two.toInt()) -} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/arithmetic/basic_charConversions.kt b/native/native.tests/testData/codegen/arithmetic/basic_charConversions.kt new file mode 100644 index 00000000000..b99fe570827 --- /dev/null +++ b/native/native.tests/testData/codegen/arithmetic/basic_charConversions.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + +fun box(): String { + assertEquals(97.0, 'a'.toDouble()) + assertEquals(-1, Char.MAX_VALUE.toShort()) + assertEquals(32768, Short.MIN_VALUE.toChar().toInt()) + assertEquals(-1, Char.MAX_VALUE.toByte()) + assertEquals(65408, Byte.MIN_VALUE.toChar().toInt()) + assertEquals(0, Float.MIN_VALUE.toChar().toInt()) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/arithmetic/basic_charCornerCases.kt b/native/native.tests/testData/codegen/arithmetic/basic_charCornerCases.kt new file mode 100644 index 00000000000..9231cc5b5b1 --- /dev/null +++ b/native/native.tests/testData/codegen/arithmetic/basic_charCornerCases.kt @@ -0,0 +1,20 @@ +import kotlin.test.* + +private fun charCornersMinus(): Int { + val a: Char = 0xFFFF.toChar() + val b: Char = 0.toChar() + return a - b +} + +private fun charCornersComparison(): Boolean { + val a = 0xFFFF.toChar() + val b = 0.toChar() + return a < b +} + +fun box(): String { + assertEquals(65535, charCornersMinus()) + assertFalse(charCornersComparison()) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/arithmetic/basic_compareIntToFloat.kt b/native/native.tests/testData/codegen/arithmetic/basic_compareIntToFloat.kt new file mode 100644 index 00000000000..9b3e0507016 --- /dev/null +++ b/native/native.tests/testData/codegen/arithmetic/basic_compareIntToFloat.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + +fun box(): String { + assertEquals(1, 0.compareTo(-0.0f)) + assertEquals(0, 0.compareTo(+0.0f)) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/arithmetic/basic_doubleBasic.kt b/native/native.tests/testData/codegen/arithmetic/basic_doubleBasic.kt new file mode 100644 index 00000000000..ea2f8ff3422 --- /dev/null +++ b/native/native.tests/testData/codegen/arithmetic/basic_doubleBasic.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + +fun box(): String { + assertEquals(1, 0f.compareTo(-0f)) + assertEquals(1, 0.0.compareTo(-0.0)) + + assertEquals(1.0, Double.fromBits(1.0.toBits())) + assertEquals(1.0f, Float.fromBits(1.0f.toBits())) + + assertEquals(Double.NaN, Double.fromBits((0 / 0.0).toBits())) + assertEquals(Float.NaN, Float.fromBits((0 / 0f).toBits())) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/arithmetic/basic_integralToFloat.kt b/native/native.tests/testData/codegen/arithmetic/basic_integralToFloat.kt new file mode 100644 index 00000000000..685536c9a6d --- /dev/null +++ b/native/native.tests/testData/codegen/arithmetic/basic_integralToFloat.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + +fun box(): String { + assertEquals(9.223372E18f, Long.MAX_VALUE.toFloat()) + assertEquals(-9.223372E18f, Long.MIN_VALUE.toFloat()) + + assertEquals(-2.147483648E9, Int.MIN_VALUE.toDouble()) + assertEquals(2.147483647E9, Int.MAX_VALUE.toDouble()) + + assertEquals(2147483647, Double.MAX_VALUE.toInt()) + assertEquals(0, Float.MIN_VALUE.toLong()) + + assertEquals(9223372036854775807, Float.MAX_VALUE.toLong()) + assertEquals(0, Double.MIN_VALUE.toInt()) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/arithmetic/basic_kt37412.kt b/native/native.tests/testData/codegen/arithmetic/basic_kt37412.kt new file mode 100644 index 00000000000..abcbbf98415 --- /dev/null +++ b/native/native.tests/testData/codegen/arithmetic/basic_kt37412.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + +fun box(): String { + val two = 2.0 + assertEquals(2, two.toInt()) + + return "OK" +} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/arithmetic/basic_selfComparison.kt b/native/native.tests/testData/codegen/arithmetic/basic_selfComparison.kt new file mode 100644 index 00000000000..db91f9f7e63 --- /dev/null +++ b/native/native.tests/testData/codegen/arithmetic/basic_selfComparison.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +// Check that compiler doesn't optimize it to `true` +fun selfCmp1(x: Int) = x + 1 > x + +fun selfCmp2(x: Int) = x - 1 < x + +fun box(): String { + assertFalse(selfCmp1(Int.MAX_VALUE)) + assertFalse(selfCmp2(Int.MIN_VALUE)) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/arithmetic/basic_shifts.kt b/native/native.tests/testData/codegen/arithmetic/basic_shifts.kt new file mode 100644 index 00000000000..90900e4e655 --- /dev/null +++ b/native/native.tests/testData/codegen/arithmetic/basic_shifts.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + +fun box(): String { + assertEquals(-2147483648, 1 shl -1) + assertEquals(0, 1 shr -1) + assertEquals(1, 1 shl 32) + assertEquals(1073741823, -1 ushr 2) + assertEquals(-1, -1 shr 2) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/arithmetic/basic_uintTests.kt b/native/native.tests/testData/codegen/arithmetic/basic_uintTests.kt new file mode 100644 index 00000000000..631483803a5 --- /dev/null +++ b/native/native.tests/testData/codegen/arithmetic/basic_uintTests.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + +@kotlin.ExperimentalUnsignedTypes +fun box(): String { + assertEquals(UInt.MAX_VALUE, UInt.MIN_VALUE - 1u) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/arithmetic/division.kt b/native/native.tests/testData/codegen/arithmetic/division.kt index 9a8a8188cc3..06da86421ce 100644 --- a/native/native.tests/testData/codegen/arithmetic/division.kt +++ b/native/native.tests/testData/codegen/arithmetic/division.kt @@ -1,11 +1,10 @@ -package codegen.arithmetic.division - import kotlin.test.* -@Test -fun divisionByZero() { +fun box(): String { assertFailsWith(ArithmeticException::class, { 5 / 0 }) assertFailsWith(ArithmeticException::class, { 5 % 0 }) assertEquals(1, 5 / try { 0 / 0; 1 } catch (e: ArithmeticException) { 5 }) assertEquals(Double.NaN, 0.0 / 0.0) + + return "OK" } diff --git a/native/native.tests/testData/codegen/arithmetic/github1856.kt b/native/native.tests/testData/codegen/arithmetic/github1856.kt index 667a0c11202..750903a7562 100644 --- a/native/native.tests/testData/codegen/arithmetic/github1856.kt +++ b/native/native.tests/testData/codegen/arithmetic/github1856.kt @@ -1,5 +1,3 @@ -package codegen.arithmetic.github1856 - import kotlin.test.* object RGBA { @@ -18,9 +16,10 @@ object RGBA { } } -@Test -fun main() { +fun box(): String { val source = listOf(0xFFFFFFFF.toInt(), 0xFFFFFF77.toInt(), 0x777777FF.toInt(), 0x77777777.toInt()) val expect = listOf(-1, -137, 2000107383, 2000107319) assertEquals(expect, source.map { RGBA.premultiplyFastInt(it) }) + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testBasics1.kt b/native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testBasics1.kt new file mode 100644 index 00000000000..5dc98529793 --- /dev/null +++ b/native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testBasics1.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +import kotlin.test.* +import kotlin.reflect.* + +@OptIn(ExperimentalAssociatedObjects::class) +fun box(): String { + assertSame(Bar, Foo::class.findAssociatedObject()) + assertSame(Baz, Foo::class.findAssociatedObject()) + assertSame(null, Foo::class.findAssociatedObject()) + + assertSame(null, Bar::class.findAssociatedObject()) + + return "OK" +} + +@OptIn(ExperimentalAssociatedObjects::class) +@AssociatedObjectKey +@Retention(AnnotationRetention.BINARY) +annotation class Associated1(val kClass: KClass<*>) + +@OptIn(ExperimentalAssociatedObjects::class) +@AssociatedObjectKey +@Retention(AnnotationRetention.BINARY) +annotation class Associated2(val kClass: KClass<*>) + +@OptIn(ExperimentalAssociatedObjects::class) +@AssociatedObjectKey +@Retention(AnnotationRetention.BINARY) +annotation class Associated3(val kClass: KClass<*>) + +@Associated1(Bar::class) +@Associated2(Baz::class) +class Foo + +object Bar +object Baz + diff --git a/native/native.tests/testData/codegen/associatedObjects/associatedObjects1.kt b/native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testGlobalOptimizations1.kt similarity index 57% rename from native/native.tests/testData/codegen/associatedObjects/associatedObjects1.kt rename to native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testGlobalOptimizations1.kt index 02f1862655f..67cba1b4f5b 100644 --- a/native/native.tests/testData/codegen/associatedObjects/associatedObjects1.kt +++ b/native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testGlobalOptimizations1.kt @@ -3,21 +3,9 @@ * that can be found in the LICENSE file. */ -package codegen.associatedObjects.associatedObjects1 - import kotlin.test.* import kotlin.reflect.* -@Test -@OptIn(ExperimentalAssociatedObjects::class) -fun testBasics1() { - assertSame(Bar, Foo::class.findAssociatedObject()) - assertSame(Baz, Foo::class.findAssociatedObject()) - assertSame(null, Foo::class.findAssociatedObject()) - - assertSame(null, Bar::class.findAssociatedObject()) -} - @OptIn(ExperimentalAssociatedObjects::class) @AssociatedObjectKey @Retention(AnnotationRetention.BINARY) @@ -33,21 +21,15 @@ annotation class Associated2(val kClass: KClass<*>) @Retention(AnnotationRetention.BINARY) annotation class Associated3(val kClass: KClass<*>) -@Associated1(Bar::class) -@Associated2(Baz::class) -class Foo - -object Bar -object Baz - -@Test @OptIn(ExperimentalAssociatedObjects::class) -fun testGlobalOptimizations1() { +fun box(): String { val i1 = I1ImplHolder::class.findAssociatedObject()!! as I1 assertEquals(42, i1.foo()) val c = C(null) i1.bar(c) assertEquals("zzz", c.list!![0]) + + return "OK" } private class C(var list: List?) @@ -66,21 +48,3 @@ private object I1Impl : I1 { @Associated1(I1Impl::class) private class I1ImplHolder - -@Test -@OptIn(ExperimentalAssociatedObjects::class) -fun testGlobalOptimizations2() { - val i2 = I2ImplHolder()::class.findAssociatedObject()!! as I2 - assertEquals(17, i2.foo()) -} - -private interface I2 { - fun foo(): Int -} - -private object I2Impl : I2 { - override fun foo() = 17 -} - -@Associated1(I2Impl::class) -private class I2ImplHolder \ No newline at end of file diff --git a/native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testGlobalOptimizations2.kt b/native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testGlobalOptimizations2.kt new file mode 100644 index 00000000000..9ee89dcb7d8 --- /dev/null +++ b/native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testGlobalOptimizations2.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +import kotlin.test.* +import kotlin.reflect.* + +@OptIn(ExperimentalAssociatedObjects::class) +@AssociatedObjectKey +@Retention(AnnotationRetention.BINARY) +annotation class Associated1(val kClass: KClass<*>) + +@OptIn(ExperimentalAssociatedObjects::class) +@AssociatedObjectKey +@Retention(AnnotationRetention.BINARY) +annotation class Associated2(val kClass: KClass<*>) + +@OptIn(ExperimentalAssociatedObjects::class) +@AssociatedObjectKey +@Retention(AnnotationRetention.BINARY) +annotation class Associated3(val kClass: KClass<*>) + +@OptIn(ExperimentalAssociatedObjects::class) +fun box(): String { + val i2 = I2ImplHolder()::class.findAssociatedObject()!! as I2 + assertEquals(17, i2.foo()) + + return "OK" +} + +private interface I2 { + fun foo(): Int +} + +private object I2Impl : I2 { + override fun foo() = 17 +} + +@Associated1(I2Impl::class) +private class I2ImplHolder \ No newline at end of file diff --git a/native/native.tests/testData/codegen/basics/array_to_any.kt b/native/native.tests/testData/codegen/basics/array_to_any.kt index 6e1b6bd28f5..eca6e053545 100644 --- a/native/native.tests/testData/codegen/basics/array_to_any.kt +++ b/native/native.tests/testData/codegen/basics/array_to_any.kt @@ -3,13 +3,12 @@ * that can be found in the LICENSE file. */ -package codegen.basics.array_to_any - import kotlin.test.* -@Test -fun runTest() { +fun box(): String { foo().hashCode() + + return "OK" } fun foo(): Any { diff --git a/native/native.tests/testData/codegen/basics/canonical_name.kt b/native/native.tests/testData/codegen/basics/canonical_name.kt index cd2497c7855..a38f96cb683 100644 --- a/native/native.tests/testData/codegen/basics/canonical_name.kt +++ b/native/native.tests/testData/codegen/basics/canonical_name.kt @@ -3,10 +3,10 @@ * that can be found in the LICENSE file. */ -package codegen.basics.canonical_name - import kotlin.test.* +val sb = StringBuilder() + interface I { fun foo(a: U): T fun qux(a: T): U @@ -20,8 +20,8 @@ class A2 //-----------------------------------------------------------------------------// class A : I { - override fun foo(a: A1): A2 { println("A:foo"); return A2() } - override fun qux(a: A2): A1 { println("A:qux"); return A1() } + override fun foo(a: A1): A2 { sb.appendLine("A:foo"); return A2() } + override fun qux(a: A2): A1 { sb.appendLine("A:qux"); return A1() } } //-----------------------------------------------------------------------------// @@ -33,7 +33,9 @@ fun baz(i: I, u: U, v:V) { //-----------------------------------------------------------------------------// -@Test -fun runTest() { +fun box(): String { baz(A(), A1(), A2()) + + assertEquals("A:foo\nA:qux\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/basics/canonical_name.out b/native/native.tests/testData/codegen/basics/canonical_name.out deleted file mode 100644 index b25c0908bfb..00000000000 --- a/native/native.tests/testData/codegen/basics/canonical_name.out +++ /dev/null @@ -1,2 +0,0 @@ -A:foo -A:qux diff --git a/native/native.tests/testData/codegen/basics/cast_null.kt b/native/native.tests/testData/codegen/basics/cast_null.kt index ea47db9ccc0..903ee5c4694 100644 --- a/native/native.tests/testData/codegen/basics/cast_null.kt +++ b/native/native.tests/testData/codegen/basics/cast_null.kt @@ -3,12 +3,9 @@ * that can be found in the LICENSE file. */ -package codegen.basics.cast_null - import kotlin.test.* -@Test -fun runTest() { +fun box(): String { testCast(null, false) testCastToNullable(null, true) testCastToNullable(TestKlass(), true) @@ -16,14 +13,14 @@ fun runTest() { testCastNotNullableToNullable(TestKlass(), true) testCastNotNullableToNullable("", false) - println("Ok") + return "OK" } class TestKlass fun ensure(b: Boolean) { if (!b) { - println("Error") + throw Error("Error") } } diff --git a/native/native.tests/testData/codegen/basics/cast_null.out b/native/native.tests/testData/codegen/basics/cast_null.out deleted file mode 100644 index 7326d960397..00000000000 --- a/native/native.tests/testData/codegen/basics/cast_null.out +++ /dev/null @@ -1 +0,0 @@ -Ok diff --git a/native/native.tests/testData/codegen/basics/cast_simple.kt b/native/native.tests/testData/codegen/basics/cast_simple.kt index 80555ab3f9b..fd05a964318 100644 --- a/native/native.tests/testData/codegen/basics/cast_simple.kt +++ b/native/native.tests/testData/codegen/basics/cast_simple.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.basics.cast_simple - import kotlin.test.* open class A() {} @@ -18,7 +16,8 @@ fun castTest(): Boolean { return true } -@Test -fun runTest() { +fun box(): String { if (!castTest()) throw Error() + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/basics/check_type.kt b/native/native.tests/testData/codegen/basics/check_type.kt index b92232ef337..54a4ece7918 100644 --- a/native/native.tests/testData/codegen/basics/check_type.kt +++ b/native/native.tests/testData/codegen/basics/check_type.kt @@ -2,9 +2,6 @@ * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE file. */ - -package codegen.basics.check_type - import kotlin.test.* interface I @@ -37,12 +34,13 @@ fun isTypeOfInterface(a: Any) : Boolean { //-----------------------------------------------------------------------------// -@Test -fun runTest() { - println(isTypeOf(A())) - println(isTypeOf(null)) - println(isTypeNullableOf(A())) - println(isTypeNullableOf(null)) - println(isNotTypeOf(B())) - println(isTypeOfInterface(A())) +fun box(): String { + if (!isTypeOf(A())) return "FAIL !isTypeOf(A())" + if (isTypeOf(null)) return "FAIL isTypeOf(null)" + if (!isTypeNullableOf(A())) return "FAIL !isTypeNullableOf(A())" + if (!isTypeNullableOf(null)) return "FAIL !isTypeNullableOf(null)" + if (!isNotTypeOf(B())) return "FAIL !isNotTypeOf(B())" + if (!isTypeOfInterface(A())) return "FAIL !isTypeOfInterface(A())" + + return "OK" } diff --git a/native/native.tests/testData/codegen/basics/check_type.out b/native/native.tests/testData/codegen/basics/check_type.out deleted file mode 100644 index f98a79c5b6f..00000000000 --- a/native/native.tests/testData/codegen/basics/check_type.out +++ /dev/null @@ -1,6 +0,0 @@ -true -false -true -true -true -true diff --git a/native/native.tests/testData/codegen/basics/companion.kt b/native/native.tests/testData/codegen/basics/companion.kt index b753406bf18..a8568b28ebb 100644 --- a/native/native.tests/testData/codegen/basics/companion.kt +++ b/native/native.tests/testData/codegen/basics/companion.kt @@ -5,6 +5,8 @@ class A { companion object { - fun foo() = "comp" + fun foo() = "OK" } } + +fun box() = A.foo() diff --git a/native/native.tests/testData/codegen/basics/concatenation.kt b/native/native.tests/testData/codegen/basics/concatenation.kt index e772e4dd4c4..97fc4be3d26 100644 --- a/native/native.tests/testData/codegen/basics/concatenation.kt +++ b/native/native.tests/testData/codegen/basics/concatenation.kt @@ -2,18 +2,19 @@ * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE file. */ - -package codegen.basics.concatenation +// OUTPUT_DATA_FILE: concatenation.out import kotlin.test.* -@Test -fun runTest() { +fun box(): String { val s = "world" val i = 1 - println("Hello $s $i ${2*i}") + val res1 = "Hello $s $i ${2 * i}" + if (res1 != "Hello world 1 2") return "FAIL 1: $res1" - for (item in listOf("a", "b")) { - println("Hello, $item") - } + val a = "a" + val res2 = "Hello, $a" + if (res2 != "Hello, a") return "FAIL 2: $res2" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/basics/concatenation.out b/native/native.tests/testData/codegen/basics/concatenation.out deleted file mode 100644 index 2aafe150106..00000000000 --- a/native/native.tests/testData/codegen/basics/concatenation.out +++ /dev/null @@ -1,3 +0,0 @@ -Hello world 1 2 -Hello, a -Hello, b diff --git a/native/native.tests/testData/codegen/basics/const_infinity.kt b/native/native.tests/testData/codegen/basics/const_infinity.kt index bd05fc84cc9..b35ec807310 100644 --- a/native/native.tests/testData/codegen/basics/const_infinity.kt +++ b/native/native.tests/testData/codegen/basics/const_infinity.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.basics.const_infinity - import kotlin.test.* //Original issue here https://youtrack.jetbrains.com/issue/KT-37212 @@ -13,9 +11,10 @@ const val fpInfConst = 1.0F / 0.0F @Suppress("DIVISION_BY_ZERO") val fpInfVal = 1.0F / 0.0F -@Test -fun runTest() { +fun box(): String { assertEquals(fpInfConst, Float.POSITIVE_INFINITY) assertEquals(fpInfVal, Float.POSITIVE_INFINITY) assertEquals(fpInfConst, fpInfVal) -} \ No newline at end of file + + return "OK" +} diff --git a/native/native.tests/testData/codegen/basics/expression_as_statement.kt b/native/native.tests/testData/codegen/basics/expression_as_statement.kt index b59662329cd..3fe3449e4da 100644 --- a/native/native.tests/testData/codegen/basics/expression_as_statement.kt +++ b/native/native.tests/testData/codegen/basics/expression_as_statement.kt @@ -3,22 +3,18 @@ * that can be found in the LICENSE file. */ -package codegen.basics.expression_as_statement - import kotlin.test.* fun foo() { Any() as String } -@Test -fun runTest() { +fun box(): String { try { foo() } catch (e: Throwable) { - println("Ok") - return + return "OK" } - println("Fail") + return "Fail" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/basics/expression_as_statement.out b/native/native.tests/testData/codegen/basics/expression_as_statement.out deleted file mode 100644 index 7326d960397..00000000000 --- a/native/native.tests/testData/codegen/basics/expression_as_statement.out +++ /dev/null @@ -1 +0,0 @@ -Ok diff --git a/native/native.tests/testData/codegen/basics/k42000_1.kt b/native/native.tests/testData/codegen/basics/k42000_1.kt index 7f18c7fd110..868001682c6 100644 --- a/native/native.tests/testData/codegen/basics/k42000_1.kt +++ b/native/native.tests/testData/codegen/basics/k42000_1.kt @@ -1,10 +1,9 @@ -package codegen.basics.k42000_1 - import kotlin.test.* -@Test -fun runTest() { +fun box(): String { assertTrue(Reproducer().repro() > 0) + + return "OK" } // Based on https://youtrack.jetbrains.com/issue/KT-42000#focus=Comments-27-4404934.0-0 diff --git a/native/native.tests/testData/codegen/basics/k42000_2.kt b/native/native.tests/testData/codegen/basics/k42000_2.kt index fe264739fe7..4b30759d9d5 100644 --- a/native/native.tests/testData/codegen/basics/k42000_2.kt +++ b/native/native.tests/testData/codegen/basics/k42000_2.kt @@ -1,14 +1,13 @@ -package codegen.basics.k42000_2 - import kotlin.test.* // https://youtrack.jetbrains.com/issue/KT-42000 -@Test -fun runTest() { +fun box(): String { assertFailsWith { when (1) { else -> throw Error() } as String } + + return "OK" } diff --git a/native/native.tests/testData/codegen/basics/local_variable.kt b/native/native.tests/testData/codegen/basics/local_variable.kt index 6ad41164f0f..0ec7b3e170b 100644 --- a/native/native.tests/testData/codegen/basics/local_variable.kt +++ b/native/native.tests/testData/codegen/basics/local_variable.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.basics.local_variable - import kotlin.test.* fun local_variable(a: Int) : Int { @@ -13,7 +11,7 @@ fun local_variable(a: Int) : Int { return b } -@Test -fun runTest() { +fun box(): String { if (local_variable(3) != 14) throw Error() + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/basics/null_check.kt b/native/native.tests/testData/codegen/basics/null_check.kt index 777789d397a..8919729041e 100644 --- a/native/native.tests/testData/codegen/basics/null_check.kt +++ b/native/native.tests/testData/codegen/basics/null_check.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.basics.null_check - import kotlin.test.* //--- Test "eqeq" -------------------------------------------------------------// @@ -31,10 +29,11 @@ fun null_check_eqeqeq2() : Boolean { return check_eqeqeq(null) } -@Test -fun runTest() { - if (null_check_eqeq1()) throw Error() - if (!null_check_eqeq2()) throw Error() - if (null_check_eqeqeq1()) throw Error() - if (!null_check_eqeqeq2()) throw Error() +fun box(): String { + if (null_check_eqeq1()) return "FAIL null_check_eqeq1()" + if (!null_check_eqeq2()) return "FAIL !null_check_eqeq2()" + if (null_check_eqeqeq1()) return "FAIL null_check_eqeqeq1()" + if (!null_check_eqeqeq2()) return "FAIL !null_check_eqeqeq2()" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/basics/safe_cast.kt b/native/native.tests/testData/codegen/basics/safe_cast.kt index 0448e1b3542..c53f7e739b3 100644 --- a/native/native.tests/testData/codegen/basics/safe_cast.kt +++ b/native/native.tests/testData/codegen/basics/safe_cast.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.basics.safe_cast - import kotlin.test.* open class A @@ -23,10 +21,11 @@ fun safe_cast_negative(): Boolean { return foo(c) == null } -@Test -fun runTest() { +fun box(): String { val safeCastPositive = safe_cast_positive().toString() val safeCastNegative = safe_cast_negative().toString() - println("safe_cast_positive: " + safeCastPositive) - println("safe_cast_negative: " + safeCastNegative) + if (safeCastPositive != "true") return "FAIL safeCastPositive" + if (safeCastNegative != "true") return "FAIL safeCastNegative" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/basics/safe_cast.out b/native/native.tests/testData/codegen/basics/safe_cast.out deleted file mode 100644 index 28a70785dea..00000000000 --- a/native/native.tests/testData/codegen/basics/safe_cast.out +++ /dev/null @@ -1,2 +0,0 @@ -safe_cast_positive: true -safe_cast_negative: true diff --git a/native/native.tests/testData/codegen/basics/spread_operator_0.kt b/native/native.tests/testData/codegen/basics/spread_operator_0.kt index 426d750fa75..dffaba2e9cc 100644 --- a/native/native.tests/testData/codegen/basics/spread_operator_0.kt +++ b/native/native.tests/testData/codegen/basics/spread_operator_0.kt @@ -3,16 +3,17 @@ * that can be found in the LICENSE file. */ -package codegen.basics.spread_operator_0 - import kotlin.test.* -@Test -fun runTest() { +fun box(): String { val list0 = _arrayOf("K", "o", "t", "l", "i", "n") val list1 = _arrayOf("l", "a","n", "g", "u", "a", "g", "e") val list = foo(list0, list1) - println(list.toString()) + + val expected = listOf("K", "o", "t", "l", "i", "n", " ", "i", "s", " ", "c", "o", "o", "l", " ", "l", "a", "n", "g", "u", "a", "g", "e") + if (list != expected) + return "FAIL: $list" + return "OK" } diff --git a/native/native.tests/testData/codegen/basics/spread_operator_0.out b/native/native.tests/testData/codegen/basics/spread_operator_0.out deleted file mode 100644 index 0bb4cc104b2..00000000000 --- a/native/native.tests/testData/codegen/basics/spread_operator_0.out +++ /dev/null @@ -1 +0,0 @@ -[K, o, t, l, i, n, , i, s, , c, o, o, l, , l, a, n, g, u, a, g, e] diff --git a/native/native.tests/testData/codegen/basics/superFunCall.kt b/native/native.tests/testData/codegen/basics/superFunCall.kt index b7e7a0b7b8e..896062609c8 100644 --- a/native/native.tests/testData/codegen/basics/superFunCall.kt +++ b/native/native.tests/testData/codegen/basics/superFunCall.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.basics.superFunCall - import kotlin.test.* open class C { @@ -22,8 +20,11 @@ class C3: C2() { override fun f() = super.f() + "" } -@Test -fun runTest() { - println(C1().f()) - println(C3().f()) +fun box(): String { + val c1f = C1().f() + if (c1f != "") return "FAIL 1: $c1f" + val c3f = C3().f() + if (c3f != "") return "FAIL 2: $c3f" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/basics/superFunCall.out b/native/native.tests/testData/codegen/basics/superFunCall.out deleted file mode 100644 index db5d36681fd..00000000000 --- a/native/native.tests/testData/codegen/basics/superFunCall.out +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/native/native.tests/testData/codegen/basics/superGetterCall.kt b/native/native.tests/testData/codegen/basics/superGetterCall.kt index d4820a8b438..5fb5b5ed19e 100644 --- a/native/native.tests/testData/codegen/basics/superGetterCall.kt +++ b/native/native.tests/testData/codegen/basics/superGetterCall.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.basics.superGetterCall - import kotlin.test.* open class C { @@ -22,8 +20,11 @@ class C3: C2() { override val p1 = super.p1 + "" } -@Test -fun runTest() { - println(C1().p1) - println(C3().p1) +fun box(): String { + val c1p1 = C1().p1 + if (c1p1 != "") return "FAIL 1: $c1p1" + val c3p1 = C3().p1 + if (c3p1 != "") return "FAIl 2: $c3p1" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/basics/superGetterCall.out b/native/native.tests/testData/codegen/basics/superGetterCall.out deleted file mode 100644 index f7fa5a233a9..00000000000 --- a/native/native.tests/testData/codegen/basics/superGetterCall.out +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/native/native.tests/testData/codegen/basics/superSetterCall.kt b/native/native.tests/testData/codegen/basics/superSetterCall.kt index f21de91121d..f061df2b4b8 100644 --- a/native/native.tests/testData/codegen/basics/superSetterCall.kt +++ b/native/native.tests/testData/codegen/basics/superSetterCall.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.basics.superSetterCall - import kotlin.test.* open class C { @@ -31,12 +29,15 @@ class C3: C2() { } } -@Test -fun runTest() { +fun box(): String { val c1 = C1() val c3 = C3() c1.p2 = "zzz" c3.p2 = "zzz" - println(c1.p2) - println(c3.p2) + val c1p2 = c1.p2 + if (c1p2 != "zzz") return "FAIL 1: " + val c3p2 = c3.p2 + if (c3p2 != "zzz") return "FAIL 2: " + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/basics/superSetterCall.out b/native/native.tests/testData/codegen/basics/superSetterCall.out deleted file mode 100644 index ad01a64ad11..00000000000 --- a/native/native.tests/testData/codegen/basics/superSetterCall.out +++ /dev/null @@ -1,2 +0,0 @@ -zzz -zzz diff --git a/native/native.tests/testData/codegen/basics/typealias1.kt b/native/native.tests/testData/codegen/basics/typealias1.kt index 6cd60ec3014..910e8da450a 100644 --- a/native/native.tests/testData/codegen/basics/typealias1.kt +++ b/native/native.tests/testData/codegen/basics/typealias1.kt @@ -3,13 +3,12 @@ * that can be found in the LICENSE file. */ -package codegen.basics.typealias1 - import kotlin.test.* -@Test -fun runTest() { - println(Bar(42).x) +fun box(): String { + val x = Bar(42).x + if (x != 42 ) return "FAIL: $x" + return "OK" } class Foo(val x: Int) diff --git a/native/native.tests/testData/codegen/basics/typealias1.out b/native/native.tests/testData/codegen/basics/typealias1.out deleted file mode 100644 index d81cc0710eb..00000000000 --- a/native/native.tests/testData/codegen/basics/typealias1.out +++ /dev/null @@ -1 +0,0 @@ -42 diff --git a/native/native.tests/testData/codegen/basics/unchecked_cast1.kt b/native/native.tests/testData/codegen/basics/unchecked_cast1.kt index ac50d1c73df..55db5e689c3 100644 --- a/native/native.tests/testData/codegen/basics/unchecked_cast1.kt +++ b/native/native.tests/testData/codegen/basics/unchecked_cast1.kt @@ -3,24 +3,26 @@ * that can be found in the LICENSE file. */ -package codegen.basics.unchecked_cast1 - import kotlin.test.* -@Test -fun runTest() { +val sb = StringBuilder() + +fun box(): String { foo("17") bar("17") foo(42) bar(42) + + assertEquals("17\n17\n42\n42\n", sb.toString()) + return "OK" } fun foo(x: Any?) { val y = x as T - println(y.toString()) + sb.appendLine(y.toString()) } fun bar(x: Any?) { val y = x as? T - println(y.toString()) + sb.appendLine(y.toString()) } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/basics/unchecked_cast1.out b/native/native.tests/testData/codegen/basics/unchecked_cast1.out deleted file mode 100644 index 270e65c0f2e..00000000000 --- a/native/native.tests/testData/codegen/basics/unchecked_cast1.out +++ /dev/null @@ -1,4 +0,0 @@ -17 -17 -42 -42 diff --git a/native/native.tests/testData/codegen/basics/unchecked_cast2.kt b/native/native.tests/testData/codegen/basics/unchecked_cast2.kt index 0b938520f31..dec6da39448 100644 --- a/native/native.tests/testData/codegen/basics/unchecked_cast2.kt +++ b/native/native.tests/testData/codegen/basics/unchecked_cast2.kt @@ -2,18 +2,16 @@ * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE file. */ - -package codegen.basics.unchecked_cast2 +// IGNORE_BACKEND: NATIVE import kotlin.test.* -@Test -fun runTest() { +fun box(): String { try { val x = cast(Any()) - println(x.length) + return "FAIL: ${x.length}" } catch (e: Throwable) { - println("Ok") + return "OK" } } diff --git a/native/native.tests/testData/codegen/basics/unchecked_cast2.out b/native/native.tests/testData/codegen/basics/unchecked_cast2.out deleted file mode 100644 index 7326d960397..00000000000 --- a/native/native.tests/testData/codegen/basics/unchecked_cast2.out +++ /dev/null @@ -1 +0,0 @@ -Ok diff --git a/native/native.tests/testData/codegen/basics/unchecked_cast3.kt b/native/native.tests/testData/codegen/basics/unchecked_cast3.kt index bd4557a7739..b7b088c9a60 100644 --- a/native/native.tests/testData/codegen/basics/unchecked_cast3.kt +++ b/native/native.tests/testData/codegen/basics/unchecked_cast3.kt @@ -3,17 +3,14 @@ * that can be found in the LICENSE file. */ -package codegen.basics.unchecked_cast3 - import kotlin.test.* -@Test -fun runTest() { +fun box(): String { testCast(TestKlass(), true) testCast(null, false) testCastToNullable(null, true) - println("Ok") + return "OK" } class TestKlass diff --git a/native/native.tests/testData/codegen/basics/unchecked_cast3.out b/native/native.tests/testData/codegen/basics/unchecked_cast3.out deleted file mode 100644 index 7326d960397..00000000000 --- a/native/native.tests/testData/codegen/basics/unchecked_cast3.out +++ /dev/null @@ -1 +0,0 @@ -Ok diff --git a/native/native.tests/testData/codegen/basics/unchecked_cast4.kt b/native/native.tests/testData/codegen/basics/unchecked_cast4.kt index 39b266cdca6..be791c6a7c4 100644 --- a/native/native.tests/testData/codegen/basics/unchecked_cast4.kt +++ b/native/native.tests/testData/codegen/basics/unchecked_cast4.kt @@ -3,12 +3,9 @@ * that can be found in the LICENSE file. */ -package codegen.basics.unchecked_cast4 - import kotlin.test.* -@Test -fun runTest() { +fun box(): String { CI1I2().uncheckedCast() CI1I2().uncheckedCast() @@ -16,7 +13,7 @@ fun runTest() { Any().uncheckedCast() } - println("Ok") + return "OK" } fun Any?.uncheckedCast() where R : I1, R : I2 { diff --git a/native/native.tests/testData/codegen/basics/unchecked_cast4.out b/native/native.tests/testData/codegen/basics/unchecked_cast4.out deleted file mode 100644 index 7326d960397..00000000000 --- a/native/native.tests/testData/codegen/basics/unchecked_cast4.out +++ /dev/null @@ -1 +0,0 @@ -Ok diff --git a/native/native.tests/testData/codegen/basics/unit1.kt b/native/native.tests/testData/codegen/basics/unit1.kt index 6841a536c6e..983c04d87ce 100644 --- a/native/native.tests/testData/codegen/basics/unit1.kt +++ b/native/native.tests/testData/codegen/basics/unit1.kt @@ -3,11 +3,8 @@ * that can be found in the LICENSE file. */ -package codegen.basics.unit1 - -import kotlin.test.* - -@Test -fun runTest() { - println(println("First").toString()) +fun box(): String { + val unit = println("First") + if (unit.toString() != "kotlin.Unit") return "FAIL 1: $unit" + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/basics/unit1.out b/native/native.tests/testData/codegen/basics/unit1.out deleted file mode 100644 index dcac34d859d..00000000000 --- a/native/native.tests/testData/codegen/basics/unit1.out +++ /dev/null @@ -1,2 +0,0 @@ -First -kotlin.Unit diff --git a/native/native.tests/testData/codegen/basics/unit2.kt b/native/native.tests/testData/codegen/basics/unit2.kt index 83d178e7723..aed3a77c586 100644 --- a/native/native.tests/testData/codegen/basics/unit2.kt +++ b/native/native.tests/testData/codegen/basics/unit2.kt @@ -3,14 +3,10 @@ * that can be found in the LICENSE file. */ -package codegen.basics.unit2 - -import kotlin.test.* - -@Test -fun runTest() { +fun box(): String { val x = foo() - println(x.toString()) + if (x.toString() != "kotlin.Unit") return "FAIL: $x" + return "OK" } fun foo() { diff --git a/native/native.tests/testData/codegen/basics/unit2.out b/native/native.tests/testData/codegen/basics/unit2.out deleted file mode 100644 index 0fd40fc5055..00000000000 --- a/native/native.tests/testData/codegen/basics/unit2.out +++ /dev/null @@ -1 +0,0 @@ -kotlin.Unit diff --git a/native/native.tests/testData/codegen/basics/unit3.kt b/native/native.tests/testData/codegen/basics/unit3.kt index 34776bbe37d..9982ef0defa 100644 --- a/native/native.tests/testData/codegen/basics/unit3.kt +++ b/native/native.tests/testData/codegen/basics/unit3.kt @@ -3,15 +3,12 @@ * that can be found in the LICENSE file. */ -package codegen.basics.unit3 - -import kotlin.test.* - -@Test -fun runTest() { - foo(Unit) +fun box(): String { + val actual = foo(Unit) + if (actual != "kotlin.Unit") return "FAIL: $actual" + return "OK" } -fun foo(x: Any) { - println(x.toString()) +fun foo(x: Any): String { + return x.toString() } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/basics/unit3.out b/native/native.tests/testData/codegen/basics/unit3.out deleted file mode 100644 index 0fd40fc5055..00000000000 --- a/native/native.tests/testData/codegen/basics/unit3.out +++ /dev/null @@ -1 +0,0 @@ -kotlin.Unit diff --git a/native/native.tests/testData/codegen/basics/unit4.kt b/native/native.tests/testData/codegen/basics/unit4.kt index 2ffa8ab7117..28f182bcf86 100644 --- a/native/native.tests/testData/codegen/basics/unit4.kt +++ b/native/native.tests/testData/codegen/basics/unit4.kt @@ -3,16 +3,11 @@ * that can be found in the LICENSE file. */ -package codegen.basics.unit4 - -import kotlin.test.* - -@Test -fun runTest() { +fun box(): String { for (x in 0 .. 8) { foo(x, Unit) } - println("Done") + return "OK" } var global = 42 @@ -39,7 +34,7 @@ fun foo(x: Int, unit: Unit) { } if (y !== Unit) { - println("Fail at x = $x") + throw Error("Fail at x = $x") } } diff --git a/native/native.tests/testData/codegen/basics/unit4.out b/native/native.tests/testData/codegen/basics/unit4.out deleted file mode 100644 index a965a70ed4e..00000000000 --- a/native/native.tests/testData/codegen/basics/unit4.out +++ /dev/null @@ -1 +0,0 @@ -Done diff --git a/native/native.tests/testData/codegen/bce/arraysForLoops.kt b/native/native.tests/testData/codegen/bce/arraysForLoops.kt deleted file mode 100644 index d5ddb723d90..00000000000 --- a/native/native.tests/testData/codegen/bce/arraysForLoops.kt +++ /dev/null @@ -1,622 +0,0 @@ -/* - * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the LICENSE file. - */ -package codegen.bce.arraysForLoops - -import kotlin.test.* -import kotlin.reflect.KProperty - -@Test fun forEachIndexedTest() { - val array = Array(10) { 0 } - - assertFailsWith { - array.forEachIndexed { index, _ -> - array[index + 1] = 1 - } - } -} - -@Test fun forEachIndicies() { - val array = Array(10) { 0 } - val array1 = Array(3) { 0 } - var j = 4 - - assertFailsWith { - for (i in array.indices) { - array[j] = 6 - j++ - } - } - - assertFailsWith { - for (i in array.indices) { - array[i + 1] = 6 - } - } - - assertFailsWith { - for (i in array.indices) { - array1[i] = 6 - } - } -} - -@Test fun forUntilSize() { - val array = Array(10) { 0L } - val array1 = Array(3) { 0L } - var j = 4 - - assertFailsWith { - for (i in 0 until array.size) { - array[j] = 6 - j++ - } - } - - assertFailsWith { - for (i in 0 until array.size) { - array[i - 1] = 6 - } - } - - assertFailsWith { - for (i in 0 until array.size) { - array1[i] = 6 - } - } - - assertFailsWith { - for (i in 0 until array.size + 10) { - array[i] = 6 - } - } -} - -@Test fun forDownToSize() { - val array = Array(10) { 0L } - val array1 = Array(3) { 0L } - var j = 4 - - assertFailsWith { - for (i in array.size - 1 downTo 0) { - array[j] = 6 - j++ - } - } - - assertFailsWith { - for (i in array.size - 1 downTo 0) { - array[i * 2] = 6 - } - } - - assertFailsWith { - for (i in array.size - 1 downTo 0) { - array1[i] = 6 - } - } - - var a = array.size - 1 - val b = ++a - val c = b - - assertFailsWith { - for (i in c downTo 0) { - array[i] = 6 - } - } - - assertFailsWith { - for (i in array.size + 1 downTo 0) { - array[i] = 6 - } - } - - assertFailsWith { - for (i in array.size - 1 downTo -1) { - array[i] = 6 - } - } - - assertFailsWith { - for (i in array.size downTo 0) { - array[i] = 6 - } - } -} - -@Test fun forRangeToSize() { - val array = Array(10) { 0L } - val array1 = Array(3) { 0L } - var j = 4 - - assertFailsWith { - for (i in 0..array.size - 1) { - array[j] = 6 - j++ - } - } - - var length = array.size - 1 - length = 2 * length - assertFailsWith { - for (i in 0..length) { - array[i] = 6 - } - } - - assertFailsWith { - for (i in 0..array.size - 1) { - array[i + 1] = 6 - } - } - - assertFailsWith { - for (i in 0..array.size - 1) { - array1[i] = 6 - } - } - - assertFailsWith { - for (i in 0..array.size + 1) { - array[i] = 6 - } - } - - assertFailsWith { - for (i in -1..array.size - 1) { - array[i] = 6 - } - } - - assertFailsWith { - for (i in 0..array.size) { - array[i] = 6 - } - } -} - -@Test fun forRangeToWithStep() { - val array = Array(10) { 0L } - val array1 = Array(3) { 0L } - var j = 8 - - assertFailsWith { - for (i in 0..array.size - 1 step 2) { - array[j] = 6 - j++ - } - } - - assertFailsWith { - for (i in 0..array.size - 1 step 2) { - array[i - 1] = 6 - } - } - - assertFailsWith { - for (i in 0..array.size - 1 step 2) { - array1[i] = 6 - } - } - - assertFailsWith { - for (i in 0..array.size + 1 step 2) { - array[i] = 6 - } - } - - assertFailsWith { - for (i in -1..array.size - 1 step 2) { - array[i] = 6 - } - } - - assertFailsWith { - for (i in 0..array.size step 2) { - array[i] = 6 - } - } -} - -@Test fun forUntilWithStep() { - val array = CharArray(10) { '0' } - val array1 = CharArray(3) { '0' } - var j = 8 - - assertFailsWith { - for (i in 0 until array.size step 2) { - array[j] = '6' - j++ - } - } - - assertFailsWith { - for (i in 0 until array.size step 2) { - array[i + 3] = '6' - } - } - - assertFailsWith { - for (i in 0 until array.size step 2) { - array1[i] = '6' - } - } - - assertFailsWith { - for (i in 0 until (array.size/0.5).toInt() step 2) { - array[i] = '6' - } - } - - assertFailsWith { - for (i in -array.size until array.size step 2) { - array[i] = '6' - } - } -} - -@Test fun forDownToWithStep() { - val array = UIntArray(10) { 0U } - val array1 = UIntArray(3) { 0U } - var j = 8 - - assertFailsWith { - for (i in array.size - 1 downTo 0 step 2) { - array[j] = 6U - j++ - } - } - - assertFailsWith { - for (i in array.size - 1 downTo 1 step 2) { - array[i + 1] = 6U - } - } - - assertFailsWith { - for (i in array.size - 1 downTo 1 step 2) { - array1[i] = 6U - } - } - - assertFailsWith { - for (i in (array.size / 0.2).toInt() downTo 1 step 2) { - array[i] = 6U - } - } - - assertFailsWith { - for (i in array.size - 1 downTo -3 step 2) { - array[i] = 6U - } - } - - assertFailsWith { - for (i in array.size downTo 1 step 2) { - array[i] = 6U - } - } -} - -@Test fun forIndiciesWithStep() { - val array = Array(10) { 0L } - val array1 = Array(3) { 0L } - var j = 8 - - assertFailsWith { - for (i in array.indices step 2) { - array[j] = 6 - j++ - } - } - - assertFailsWith { - for (i in array.indices step 2) { - array[i - 1] = 6 - } - } - - assertFailsWith { - for (i in array.indices step 2) { - array1[i] = 6 - } - } -} - -@Test fun forWithIndex() { - val array = Array(10) { 100 } - val array1 = Array(3) { 0 } - var j = 8 - - assertFailsWith { - for ((index, value) in array.withIndex()) { - array[j] = 6 - j++ - } - } - - assertFailsWith { - for ((index, value) in array.withIndex()) { - array[index + 1] = 6 - } - } - - assertFailsWith { - for ((index, value) in array.withIndex()) { - array[value] = 6 - } - } - - assertFailsWith { - for ((i, v) in (0..array.size + 30 step 2).withIndex()) { - array[i] = 6 - } - } - - assertFailsWith { - for ((i, v) in (0..array.size).withIndex()) { - array[v] = 8 - } - } -} - -@Test fun forReversed() { - val array = Array(10) { 100 } - val array1 = Array(3) { 0 } - var j = 8 - - assertFailsWith { - for (i in (0..array.size-1).reversed()) { - array[j] = 6 - j++ - } - } - - assertFailsWith { - for (i in (0 until array.size).reversed()) { - array1[i] = 6 - } - } - - assertFailsWith { - for (i in (0..array.size).reversed()) { - array[i] = 6 - } - } - - assertFailsWith { - for (i in (array.size downTo 0).reversed()) { - array[i] = 6 - } - } -} - -fun foo(a: Int, b : Int): Int = a + b * 2 - -@Test fun bceCases() { - val array = Array(10) { 100 } - val array1 = Array(3) { 0 } - var length = array.size - 1 - var sum = 0 - - array.forEach { - sum += it - } - - for (i in array.indices) { - array[i] = 6 - } - - for (i in 0 until array.size) { - array[i] = 7 - } - - for (i in array.size - 1 downTo 1) { - array[i] = 7 - } - - for (it in array) { - sum += it - } - - for (i in 0..array.size - 1 step 2) { - array[i] = 7 - } - - for (i in 0 until array.size step 2) { - array[i] = 7 - } - - for (i in array.indices step 2) { - array[i] = 6 - } - - for (i in array.size - 1 downTo 1 step 2) { - array[i] = 7 - } - - for ((index, value) in array.withIndex()) { - array[index] = 8 - } - - for ((i, v) in (0..array.size - 1 step 2).withIndex()) { - array[v] = 8 - array[i] = 6 - } - for (i in array.reversed()) { - sum += i - } - - for (i in (0..array.size-1).reversed()) { - array [i] = 10 - } - - for (i in 0 until array.size) { - array[i] = 7 - for (j in 0 until array1.size) { - array1[j] = array[i] - } - } - - val size = array.size - 1 - val size1 = size - - for (i in 0..size1) { - foo(array[i], array[i]) - } - - for (i in 0..array.size - 2) { - array[i+1] = array[i] - } -} - -var needSmallArray = true - -class WithGetter() { - val array: Array - get() = if (needSmallArray) - Array(10) { 100 } - else - Array(100) { 100 } -} - -class Delegate { - operator fun getValue(thisRef: Any?, property: KProperty<*>): Array { - return if (needSmallArray) - Array(10) { 100 } - else - Array(100) { 100 } - } -} - -class WithDelegates { - val array by Delegate() -} - -open class Base { - open val array = Array(10) { 100 } - val array1 by Delegate() -} - -class Child : Base() { - override val array: Array - get() = if (needSmallArray) - Array(10) { 100 } - else - Array(100) { 100 } -} - -@Test fun withGetter() { - val obj = WithGetter() - needSmallArray = false - assertFailsWith { - for (i in 0..obj.array.size-1) { - needSmallArray = true - obj.array[i] = 6 - needSmallArray = false - } - } -} - -@Test fun delegatedProperty() { - val obj = WithDelegates() - needSmallArray = false - assertFailsWith { - for (i in 0..obj.array.size-1) { - needSmallArray = true - obj.array[i] = 6 - needSmallArray = false - } - } -} - -@Test fun inheritance() { - val obj = Child() - val base = Base() - needSmallArray = false - assertFailsWith { - for (i in 0..obj.array.size-1) { - needSmallArray = true - obj.array[i] = 6 - needSmallArray = false - } - } - - needSmallArray = false - assertFailsWith { - for (i in 0..obj.array1.size-1) { - needSmallArray = true - obj.array1[i] = 6 - needSmallArray = false - } - } - - needSmallArray = false - assertFailsWith { - for (i in 0..obj.array.size-1) { - needSmallArray = true - base.array[i] = 6 - needSmallArray = false - } - } -} - -val array: Array = arrayOf(1) - get() = if (needSmallArray) field else arrayOf(1, 2, 3) - -@Test fun customeGetter() { - val a = array - needSmallArray = false - assertFailsWith { - for (index in 0 until array.size) { - a[index] = 6 - } - } -} - -class First(initArray: Array) { - val array = initArray -} - -class Second(initArray: Array){ - val first = First(initArray) -} - -class Third(initArray: Array) { - val second = Second(initArray) -} - -@Test fun differentObjects() { - val a = Third(arrayOf(1, 2, 3, 4, 5)) - val b = Third(arrayOf(1, 2)) - - assertFailsWith { - for (i in 0..a.second.first.array.size-1) { - b.second.first.array[i] = 6 - } - } -} - -class Foo(size: Int) { - val array = IntArray(size) -} - -class Bar { - val smallFoo = Foo(1) - val largeFoo = Foo(10) - - val smallArray = smallFoo.array - val largeArray = largeFoo.array -} - -@Test fun differentArrays() { - val bar = Bar() - - assertFailsWith { - for (index in 0 until bar.largeArray.size) { - bar.smallArray[index] = 6 - } - } -} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bce/bceCases.kt b/native/native.tests/testData/codegen/bce/bceCases.kt new file mode 100644 index 00000000000..8811a6c5d39 --- /dev/null +++ b/native/native.tests/testData/codegen/bce/bceCases.kt @@ -0,0 +1,89 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +fun foo(a: Int, b : Int): Int = a + b * 2 + +fun box(): String { + val array = Array(10) { 100 } + val array1 = Array(3) { 0 } + var length = array.size - 1 + var sum = 0 + + array.forEach { + sum += it + } + + for (i in array.indices) { + array[i] = 6 + } + + for (i in 0 until array.size) { + array[i] = 7 + } + + for (i in array.size - 1 downTo 1) { + array[i] = 7 + } + + for (it in array) { + sum += it + } + + for (i in 0..array.size - 1 step 2) { + array[i] = 7 + } + + for (i in 0 until array.size step 2) { + array[i] = 7 + } + + for (i in array.indices step 2) { + array[i] = 6 + } + + for (i in array.size - 1 downTo 1 step 2) { + array[i] = 7 + } + + for ((index, value) in array.withIndex()) { + array[index] = 8 + } + + for ((i, v) in (0..array.size - 1 step 2).withIndex()) { + array[v] = 8 + array[i] = 6 + } + for (i in array.reversed()) { + sum += i + } + + for (i in (0..array.size-1).reversed()) { + array [i] = 10 + } + + for (i in 0 until array.size) { + array[i] = 7 + for (j in 0 until array1.size) { + array1[j] = array[i] + } + } + + val size = array.size - 1 + val size1 = size + + for (i in 0..size1) { + foo(array[i], array[i]) + } + + for (i in 0..array.size - 2) { + array[i+1] = array[i] + } + + if (array.toList() != listOf(7, 7, 7, 7, 7, 7, 7, 7, 7, 7)) return "FAIL 1: ${array.toList()}" + if (array1.toList() != listOf(7, 7, 7)) return "FAIL 2: ${array1.toList()}" + + return "OK" +} diff --git a/native/native.tests/testData/codegen/bce/customGetter.kt b/native/native.tests/testData/codegen/bce/customGetter.kt new file mode 100644 index 00000000000..651639976fc --- /dev/null +++ b/native/native.tests/testData/codegen/bce/customGetter.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +var needSmallArray = true + +val array: Array = arrayOf(1) + get() = if (needSmallArray) field else arrayOf(1, 2, 3) + +fun box(): String { + val a = array + needSmallArray = false + assertFailsWith { + for (index in 0 until array.size) { + a[index] = 6 + } + } + + return "OK" +} diff --git a/native/native.tests/testData/codegen/bce/delegatedProperty.kt b/native/native.tests/testData/codegen/bce/delegatedProperty.kt new file mode 100644 index 00000000000..7b5a101557a --- /dev/null +++ b/native/native.tests/testData/codegen/bce/delegatedProperty.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* +import kotlin.reflect.KProperty + +var needSmallArray = true + +class Delegate { + operator fun getValue(thisRef: Any?, property: KProperty<*>): Array { + return if (needSmallArray) + Array(10) { 100 } + else + Array(100) { 100 } + } +} + +class WithDelegates { + val array by Delegate() +} + +fun box(): String { + val obj = WithDelegates() + needSmallArray = false + assertFailsWith { + for (i in 0..obj.array.size-1) { + needSmallArray = true + obj.array[i] = 6 + needSmallArray = false + } + } + + return "OK" +} diff --git a/native/native.tests/testData/codegen/bce/differentArrays.kt b/native/native.tests/testData/codegen/bce/differentArrays.kt new file mode 100644 index 00000000000..774116b9866 --- /dev/null +++ b/native/native.tests/testData/codegen/bce/differentArrays.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +class Foo(size: Int) { + val array = IntArray(size) +} + +class Bar { + val smallFoo = Foo(1) + val largeFoo = Foo(10) + + val smallArray = smallFoo.array + val largeArray = largeFoo.array +} + +fun box(): String { + val bar = Bar() + + assertFailsWith { + for (index in 0 until bar.largeArray.size) { + bar.smallArray[index] = 6 + } + } + return "OK" +} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bce/differentObjects.kt b/native/native.tests/testData/codegen/bce/differentObjects.kt new file mode 100644 index 00000000000..dbad2d66ae5 --- /dev/null +++ b/native/native.tests/testData/codegen/bce/differentObjects.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +class First(initArray: Array) { + val array = initArray +} + +class Second(initArray: Array){ + val first = First(initArray) +} + +class Third(initArray: Array) { + val second = Second(initArray) +} + +fun box(): String { + val a = Third(arrayOf(1, 2, 3, 4, 5)) + val b = Third(arrayOf(1, 2)) + + assertFailsWith { + for (i in 0..a.second.first.array.size-1) { + b.second.first.array[i] = 6 + } + } + return "OK" +} + +class Foo(size: Int) { + val array = IntArray(size) +} + +class Bar { + val smallFoo = Foo(1) + val largeFoo = Foo(10) + + val smallArray = smallFoo.array + val largeArray = largeFoo.array +} + +@Test fun differentArrays() { + val bar = Bar() + + assertFailsWith { + for (index in 0 until bar.largeArray.size) { + bar.smallArray[index] = 6 + } + } +} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bce/forDownToSize.kt b/native/native.tests/testData/codegen/bce/forDownToSize.kt new file mode 100644 index 00000000000..207807c63e4 --- /dev/null +++ b/native/native.tests/testData/codegen/bce/forDownToSize.kt @@ -0,0 +1,59 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +fun box(): String { + val array = Array(10) { 0L } + val array1 = Array(3) { 0L } + var j = 4 + + assertFailsWith { + for (i in array.size - 1 downTo 0) { + array[j] = 6 + j++ + } + } + + assertFailsWith { + for (i in array.size - 1 downTo 0) { + array[i * 2] = 6 + } + } + + assertFailsWith { + for (i in array.size - 1 downTo 0) { + array1[i] = 6 + } + } + + var a = array.size - 1 + val b = ++a + val c = b + + assertFailsWith { + for (i in c downTo 0) { + array[i] = 6 + } + } + + assertFailsWith { + for (i in array.size + 1 downTo 0) { + array[i] = 6 + } + } + + assertFailsWith { + for (i in array.size - 1 downTo -1) { + array[i] = 6 + } + } + + assertFailsWith { + for (i in array.size downTo 0) { + array[i] = 6 + } + } + return "OK" +} diff --git a/native/native.tests/testData/codegen/bce/forDownToWithStep.kt b/native/native.tests/testData/codegen/bce/forDownToWithStep.kt new file mode 100644 index 00000000000..91f61925e30 --- /dev/null +++ b/native/native.tests/testData/codegen/bce/forDownToWithStep.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +fun box(): String { + val array = UIntArray(10) { 0U } + val array1 = UIntArray(3) { 0U } + var j = 8 + + assertFailsWith { + for (i in array.size - 1 downTo 0 step 2) { + array[j] = 6U + j++ + } + } + + assertFailsWith { + for (i in array.size - 1 downTo 1 step 2) { + array[i + 1] = 6U + } + } + + assertFailsWith { + for (i in array.size - 1 downTo 1 step 2) { + array1[i] = 6U + } + } + + assertFailsWith { + for (i in (array.size / 0.2).toInt() downTo 1 step 2) { + array[i] = 6U + } + } + + assertFailsWith { + for (i in array.size - 1 downTo -3 step 2) { + array[i] = 6U + } + } + + assertFailsWith { + for (i in array.size downTo 1 step 2) { + array[i] = 6U + } + } + return "OK" +} diff --git a/native/native.tests/testData/codegen/bce/forEachIndexedTest.kt b/native/native.tests/testData/codegen/bce/forEachIndexedTest.kt new file mode 100644 index 00000000000..11185ce4a96 --- /dev/null +++ b/native/native.tests/testData/codegen/bce/forEachIndexedTest.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +fun box(): String { + val array = Array(10) { 0 } + + assertFailsWith { + array.forEachIndexed { index, _ -> + array[index + 1] = 1 + } + } + return "OK" +} diff --git a/native/native.tests/testData/codegen/bce/forEachIndicies.kt b/native/native.tests/testData/codegen/bce/forEachIndicies.kt new file mode 100644 index 00000000000..f9563b2ba70 --- /dev/null +++ b/native/native.tests/testData/codegen/bce/forEachIndicies.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +fun box(): String { + val array = Array(10) { 0 } + val array1 = Array(3) { 0 } + var j = 4 + + assertFailsWith { + for (i in array.indices) { + array[j] = 6 + j++ + } + } + + assertFailsWith { + for (i in array.indices) { + array[i + 1] = 6 + } + } + + assertFailsWith { + for (i in array.indices) { + array1[i] = 6 + } + } + return "OK" +} diff --git a/native/native.tests/testData/codegen/bce/forIndiciesWithStep.kt b/native/native.tests/testData/codegen/bce/forIndiciesWithStep.kt new file mode 100644 index 00000000000..ee2238e5577 --- /dev/null +++ b/native/native.tests/testData/codegen/bce/forIndiciesWithStep.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +fun box(): String { + val array = Array(10) { 0L } + val array1 = Array(3) { 0L } + var j = 8 + + assertFailsWith { + for (i in array.indices step 2) { + array[j] = 6 + j++ + } + } + + assertFailsWith { + for (i in array.indices step 2) { + array[i - 1] = 6 + } + } + + assertFailsWith { + for (i in array.indices step 2) { + array1[i] = 6 + } + } + return "OK" +} diff --git a/native/native.tests/testData/codegen/bce/forRangeToSize.kt b/native/native.tests/testData/codegen/bce/forRangeToSize.kt new file mode 100644 index 00000000000..93fcad3a215 --- /dev/null +++ b/native/native.tests/testData/codegen/bce/forRangeToSize.kt @@ -0,0 +1,57 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +fun box(): String { + val array = Array(10) { 0L } + val array1 = Array(3) { 0L } + var j = 4 + + assertFailsWith { + for (i in 0..array.size - 1) { + array[j] = 6 + j++ + } + } + + var length = array.size - 1 + length = 2 * length + assertFailsWith { + for (i in 0..length) { + array[i] = 6 + } + } + + assertFailsWith { + for (i in 0..array.size - 1) { + array[i + 1] = 6 + } + } + + assertFailsWith { + for (i in 0..array.size - 1) { + array1[i] = 6 + } + } + + assertFailsWith { + for (i in 0..array.size + 1) { + array[i] = 6 + } + } + + assertFailsWith { + for (i in -1..array.size - 1) { + array[i] = 6 + } + } + + assertFailsWith { + for (i in 0..array.size) { + array[i] = 6 + } + } + return "OK" +} diff --git a/native/native.tests/testData/codegen/bce/forRangeToWithStep.kt b/native/native.tests/testData/codegen/bce/forRangeToWithStep.kt new file mode 100644 index 00000000000..1ac2f43a26c --- /dev/null +++ b/native/native.tests/testData/codegen/bce/forRangeToWithStep.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +fun box(): String { + val array = Array(10) { 0L } + val array1 = Array(3) { 0L } + var j = 8 + + assertFailsWith { + for (i in 0..array.size - 1 step 2) { + array[j] = 6 + j++ + } + } + + assertFailsWith { + for (i in 0..array.size - 1 step 2) { + array[i - 1] = 6 + } + } + + assertFailsWith { + for (i in 0..array.size - 1 step 2) { + array1[i] = 6 + } + } + + assertFailsWith { + for (i in 0..array.size + 1 step 2) { + array[i] = 6 + } + } + + assertFailsWith { + for (i in -1..array.size - 1 step 2) { + array[i] = 6 + } + } + + assertFailsWith { + for (i in 0..array.size step 2) { + array[i] = 6 + } + } + return "OK" +} diff --git a/native/native.tests/testData/codegen/bce/forReversed.kt b/native/native.tests/testData/codegen/bce/forReversed.kt new file mode 100644 index 00000000000..42def08c47f --- /dev/null +++ b/native/native.tests/testData/codegen/bce/forReversed.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +fun box(): String { + val array = Array(10) { 100 } + val array1 = Array(3) { 0 } + var j = 8 + + assertFailsWith { + for (i in (0..array.size-1).reversed()) { + array[j] = 6 + j++ + } + } + + assertFailsWith { + for (i in (0 until array.size).reversed()) { + array1[i] = 6 + } + } + + assertFailsWith { + for (i in (0..array.size).reversed()) { + array[i] = 6 + } + } + + assertFailsWith { + for (i in (array.size downTo 0).reversed()) { + array[i] = 6 + } + } + return "OK" +} + diff --git a/native/native.tests/testData/codegen/bce/forUntilSize.kt b/native/native.tests/testData/codegen/bce/forUntilSize.kt new file mode 100644 index 00000000000..67117172332 --- /dev/null +++ b/native/native.tests/testData/codegen/bce/forUntilSize.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +fun box(): String { + val array = Array(10) { 0L } + val array1 = Array(3) { 0L } + var j = 4 + + assertFailsWith { + for (i in 0 until array.size) { + array[j] = 6 + j++ + } + } + + assertFailsWith { + for (i in 0 until array.size) { + array[i - 1] = 6 + } + } + + assertFailsWith { + for (i in 0 until array.size) { + array1[i] = 6 + } + } + + assertFailsWith { + for (i in 0 until array.size + 10) { + array[i] = 6 + } + } + return "OK" +} diff --git a/native/native.tests/testData/codegen/bce/forWithIndex.kt b/native/native.tests/testData/codegen/bce/forWithIndex.kt new file mode 100644 index 00000000000..f62d122a9e2 --- /dev/null +++ b/native/native.tests/testData/codegen/bce/forWithIndex.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +fun box(): String { + val array = Array(10) { 100 } + val array1 = Array(3) { 0 } + var j = 8 + + assertFailsWith { + for ((index, value) in array.withIndex()) { + array[j] = 6 + j++ + } + } + + assertFailsWith { + for ((index, value) in array.withIndex()) { + array[index + 1] = 6 + } + } + + assertFailsWith { + for ((index, value) in array.withIndex()) { + array[value] = 6 + } + } + + assertFailsWith { + for ((i, v) in (0..array.size + 30 step 2).withIndex()) { + array[i] = 6 + } + } + + assertFailsWith { + for ((i, v) in (0..array.size).withIndex()) { + array[v] = 8 + } + } + return "OK" +} diff --git a/native/native.tests/testData/codegen/bce/inheritance.kt b/native/native.tests/testData/codegen/bce/inheritance.kt new file mode 100644 index 00000000000..b068f970397 --- /dev/null +++ b/native/native.tests/testData/codegen/bce/inheritance.kt @@ -0,0 +1,62 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.reflect.KProperty +import kotlin.test.* + +var needSmallArray = true + +class Delegate { + operator fun getValue(thisRef: Any?, property: KProperty<*>): Array { + return if (needSmallArray) + Array(10) { 100 } + else + Array(100) { 100 } + } +} + +open class Base { + open val array = Array(10) { 100 } + val array1 by Delegate() +} + +class Child : Base() { + override val array: Array + get() = if (needSmallArray) + Array(10) { 100 } + else + Array(100) { 100 } +} + +fun box(): String { + val obj = Child() + val base = Base() + needSmallArray = false + assertFailsWith { + for (i in 0..obj.array.size-1) { + needSmallArray = true + obj.array[i] = 6 + needSmallArray = false + } + } + + needSmallArray = false + assertFailsWith { + for (i in 0..obj.array1.size-1) { + needSmallArray = true + obj.array1[i] = 6 + needSmallArray = false + } + } + + needSmallArray = false + assertFailsWith { + for (i in 0..obj.array.size-1) { + needSmallArray = true + base.array[i] = 6 + needSmallArray = false + } + } + return "OK" +} diff --git a/native/native.tests/testData/codegen/bce/withGetter.kt b/native/native.tests/testData/codegen/bce/withGetter.kt new file mode 100644 index 00000000000..e84be0e72fe --- /dev/null +++ b/native/native.tests/testData/codegen/bce/withGetter.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ +import kotlin.test.* + +var needSmallArray = true + +class WithGetter() { + val array: Array + get() = if (needSmallArray) + Array(10) { 100 } + else + Array(100) { 100 } +} + +fun box(): String { + val obj = WithGetter() + needSmallArray = false + assertFailsWith { + for (i in 0..obj.array.size-1) { + needSmallArray = true + obj.array[i] = 6 + needSmallArray = false + } + } + + return "OK" +} diff --git a/native/native.tests/testData/codegen/boxing/box_cache0.kt b/native/native.tests/testData/codegen/boxing/box_cache0.kt index 69c79ab9024..d03d93ae0bd 100644 --- a/native/native.tests/testData/codegen/boxing/box_cache0.kt +++ b/native/native.tests/testData/codegen/boxing/box_cache0.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.box_cache0 - import kotlin.test.* fun areSame(arg1: T, arg2: T): Boolean { @@ -15,7 +13,7 @@ fun Boolean.oneIfTrueElseZero(): Int { return if (this) 1 else 0 } -@Test fun runTest() { +fun box(): String { var acc = 0 val range = 1000 @@ -24,35 +22,37 @@ fun Boolean.oneIfTrueElseZero(): Int { acc += areSame(i, j).oneIfTrueElseZero() } } - println(acc) + if (acc != 2) "FAIL 1: $acc" acc = 0 for (i in Byte.MIN_VALUE..Byte.MAX_VALUE) { acc += areSame(i, i).oneIfTrueElseZero() } - println(acc) + if (acc != 256) "FAIL 2: $acc" acc = 0 for (i in Short.MIN_VALUE..Short.MAX_VALUE) { acc += areSame(i, i).oneIfTrueElseZero() } - println(acc) + if (acc != 256) "FAIL 3: $acc" acc = 0 for (i in 0.toChar()..range.toChar()) { acc += areSame(i, i).oneIfTrueElseZero() } - println(acc) + if (acc != 256) "FAIL 4: $acc" acc = 0 for (i in -range..range) { acc += areSame(i, i).oneIfTrueElseZero() } - println(acc) + if (acc != 256) "FAIL 5: $acc" acc = 0 for (i in -range.toLong()..range.toLong()) { acc += areSame(i, i).oneIfTrueElseZero() } - println(acc) + if (acc != 256) "FAIL 6: $acc" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/box_cache0.out b/native/native.tests/testData/codegen/boxing/box_cache0.out deleted file mode 100644 index 9ff26981101..00000000000 --- a/native/native.tests/testData/codegen/boxing/box_cache0.out +++ /dev/null @@ -1,6 +0,0 @@ -2 -256 -256 -256 -256 -256 diff --git a/native/native.tests/testData/codegen/boxing/boxing0.kt b/native/native.tests/testData/codegen/boxing/boxing0.kt index 203ff68674c..5c045ca10a1 100644 --- a/native/native.tests/testData/codegen/boxing/boxing0.kt +++ b/native/native.tests/testData/codegen/boxing/boxing0.kt @@ -3,19 +3,20 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing0 - import kotlin.test.* class Box(t: T) { var value = t } -@Test fun runTest() { +fun box(): String { val box: Box = Box(17) - println(box.value) + if (box.value != 17) return "FAIL 1: ${box.value}" + val nonConst = 17 val box2: Box = Box(nonConst) - println(box2.value) + if (box2.value != 17) return "FAIL 1: ${box2.value}" + + return "OK" } diff --git a/native/native.tests/testData/codegen/boxing/boxing0.out b/native/native.tests/testData/codegen/boxing/boxing0.out deleted file mode 100644 index e6cc5d6c0ed..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing0.out +++ /dev/null @@ -1,2 +0,0 @@ -17 -17 diff --git a/native/native.tests/testData/codegen/boxing/boxing1.kt b/native/native.tests/testData/codegen/boxing/boxing1.kt index 000428eb784..4e0fdde912d 100644 --- a/native/native.tests/testData/codegen/boxing/boxing1.kt +++ b/native/native.tests/testData/codegen/boxing/boxing1.kt @@ -3,15 +3,15 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing1 - import kotlin.test.* +val sb = StringBuilder() + fun foo(arg: Any) { - println(arg.toString()) + sb.appendLine(arg.toString()) } -@Test fun runTest() { +fun box(): String { foo(1) foo(2u) foo(false) @@ -24,4 +24,17 @@ fun foo(arg: Any) { foo(nonConstUInt) foo(nonConstBool) foo(nonConstString) + + assertEquals(""" + 1 + 2 + false + Hello + 1 + 2 + false + Hello + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing1.out b/native/native.tests/testData/codegen/boxing/boxing1.out deleted file mode 100644 index 901bd222426..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing1.out +++ /dev/null @@ -1,8 +0,0 @@ -1 -2 -false -Hello -1 -2 -false -Hello diff --git a/native/native.tests/testData/codegen/boxing/boxing10.kt b/native/native.tests/testData/codegen/boxing/boxing10.kt index b33acbe3ad1..bdb260fc0f9 100644 --- a/native/native.tests/testData/codegen/boxing/boxing10.kt +++ b/native/native.tests/testData/codegen/boxing/boxing10.kt @@ -3,16 +3,15 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing10 - import kotlin.test.* -@Test fun runTest() { +fun box(): String { val FALSE: Boolean? = false if (FALSE != null) { do { - println("Ok") + return "OK" } while (FALSE) } + return "FAIL" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing10.out b/native/native.tests/testData/codegen/boxing/boxing10.out deleted file mode 100644 index 7326d960397..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing10.out +++ /dev/null @@ -1 +0,0 @@ -Ok diff --git a/native/native.tests/testData/codegen/boxing/boxing11.kt b/native/native.tests/testData/codegen/boxing/boxing11.kt index 282952ecc98..b2e8a14d96c 100644 --- a/native/native.tests/testData/codegen/boxing/boxing11.kt +++ b/native/native.tests/testData/codegen/boxing/boxing11.kt @@ -3,11 +3,11 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing11 - import kotlin.test.* -fun printInt(x: Int) = println(x) +val sb = StringBuilder() + +fun printInt(x: Int) = sb.appendLine(x) class Foo(val value: Int?) { fun foo() { @@ -15,7 +15,10 @@ class Foo(val value: Int?) { } } -@Test fun runTest() { +fun box(): String { Foo(17).foo() Foo(null).foo() + + assertEquals("17\n42\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing11.out b/native/native.tests/testData/codegen/boxing/boxing11.out deleted file mode 100644 index c4a9d141e4b..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing11.out +++ /dev/null @@ -1,2 +0,0 @@ -17 -42 diff --git a/native/native.tests/testData/codegen/boxing/boxing12.kt b/native/native.tests/testData/codegen/boxing/boxing12.kt index 6f472463aef..2ba5f7c4d73 100644 --- a/native/native.tests/testData/codegen/boxing/boxing12.kt +++ b/native/native.tests/testData/codegen/boxing/boxing12.kt @@ -3,16 +3,19 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing12 - import kotlin.test.* +val sb = StringBuilder() + fun foo(x: Number) { - println(x.toByte()) + sb.appendLine(x.toByte()) } -@Test fun runTest() { +fun box(): String { foo(18) val nonConst = 18 foo(nonConst) + + assertEquals("18\n18\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing12.out b/native/native.tests/testData/codegen/boxing/boxing12.out deleted file mode 100644 index 43b14c32412..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing12.out +++ /dev/null @@ -1,2 +0,0 @@ -18 -18 diff --git a/native/native.tests/testData/codegen/boxing/boxing13.kt b/native/native.tests/testData/codegen/boxing/boxing13.kt index d45b0fb7a65..24760720565 100644 --- a/native/native.tests/testData/codegen/boxing/boxing13.kt +++ b/native/native.tests/testData/codegen/boxing/boxing13.kt @@ -3,16 +3,16 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing13 - import kotlin.test.* +val sb = StringBuilder() + fun is42(x: Any?) { - println(x == 42) - println(42 == x) + sb.appendLine(x == 42) + sb.appendLine(42 == x) } -@Test fun runTest() { +fun box(): String { is42(16) is42(42) is42("42") @@ -22,4 +22,21 @@ fun is42(x: Any?) { is42(nonConst16) is42(nonConst42) is42(nonConst42String) + + assertEquals(""" + false + false + true + true + false + false + false + false + true + true + false + false + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing13.out b/native/native.tests/testData/codegen/boxing/boxing13.out deleted file mode 100644 index e33febd159a..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing13.out +++ /dev/null @@ -1,12 +0,0 @@ -false -false -true -true -false -false -false -false -true -true -false -false diff --git a/native/native.tests/testData/codegen/boxing/boxing14.kt b/native/native.tests/testData/codegen/boxing/boxing14.kt index fb25d7ee24f..faf8093f87b 100644 --- a/native/native.tests/testData/codegen/boxing/boxing14.kt +++ b/native/native.tests/testData/codegen/boxing/boxing14.kt @@ -3,14 +3,17 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing14 - import kotlin.test.* -@Test fun runTest() { +val sb = StringBuilder() + +fun box(): String { 42.println() val nonConst = 42 nonConst.println() + + assertEquals("42\n42\n", sb.toString()) + return "OK" } -fun T.println() = println(this.toString()) \ No newline at end of file +fun T.println() = sb.appendLine(this) \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing14.out b/native/native.tests/testData/codegen/boxing/boxing14.out deleted file mode 100644 index daaac9e3030..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing14.out +++ /dev/null @@ -1,2 +0,0 @@ -42 -42 diff --git a/native/native.tests/testData/codegen/boxing/boxing15.kt b/native/native.tests/testData/codegen/boxing/boxing15.kt index 255ccf5e3db..fb036c2fbbe 100644 --- a/native/native.tests/testData/codegen/boxing/boxing15.kt +++ b/native/native.tests/testData/codegen/boxing/boxing15.kt @@ -3,14 +3,17 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing15 - import kotlin.test.* -@Test fun runTest() { - println(foo(17)) +fun box(): String { + val res1 = foo(17) + if (res1 != 17) return "FAIL 1: $res1" + val nonConst = 17 - println(foo(nonConst)) + val res2 = foo(nonConst) + if (res2 != 17) return "FAIL 2: $res2" + + return "OK" } fun foo(x: T): Int = x \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing15.out b/native/native.tests/testData/codegen/boxing/boxing15.out deleted file mode 100644 index e6cc5d6c0ed..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing15.out +++ /dev/null @@ -1,2 +0,0 @@ -17 -17 diff --git a/native/native.tests/testData/codegen/boxing/boxing2.kt b/native/native.tests/testData/codegen/boxing/boxing2.kt index c85c7ea0a9c..10fbbb02e7d 100644 --- a/native/native.tests/testData/codegen/boxing/boxing2.kt +++ b/native/native.tests/testData/codegen/boxing/boxing2.kt @@ -3,13 +3,13 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing2 - import kotlin.test.* -fun printInt(x: Int) = println(x) -fun printBoolean(x: Boolean) = println(x) -fun printUInt(x: UInt) = println(x) +val sb = StringBuilder() + +fun printInt(x: Int) = sb.appendLine(x.toString()) +fun printBoolean(x: Boolean) = sb.appendLine(x.toString()) +fun printUInt(x: UInt) = sb.appendLine(x.toString()) fun foo(arg: Any) { if (arg is Int) @@ -19,10 +19,10 @@ fun foo(arg: Any) { else if (arg is UInt) printUInt(arg) else - println("other") + sb.appendLine("other") } -@Test fun runTest() { +fun box(): String { foo(1) foo(2u) foo(true) @@ -35,4 +35,17 @@ fun foo(arg: Any) { foo(nonConstUInt) foo(nonConstBool) foo(nonConstString) + + assertEquals(""" + 1 + 2 + true + other + 1 + 2 + true + other + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing2.out b/native/native.tests/testData/codegen/boxing/boxing2.out deleted file mode 100644 index 99fc0dc75b6..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing2.out +++ /dev/null @@ -1,8 +0,0 @@ -1 -2 -true -other -1 -2 -true -other diff --git a/native/native.tests/testData/codegen/boxing/boxing3.kt b/native/native.tests/testData/codegen/boxing/boxing3.kt index 87c068e30ff..14dc6bcd0d2 100644 --- a/native/native.tests/testData/codegen/boxing/boxing3.kt +++ b/native/native.tests/testData/codegen/boxing/boxing3.kt @@ -3,19 +3,22 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing3 - import kotlin.test.* -fun printInt(x: Int) = println(x) +val sb = StringBuilder() + +fun printInt(x: Int) = sb.appendLine(x) fun foo(arg: Int?) { if (arg != null) printInt(arg) } -@Test fun runTest() { +fun box(): String { foo(42) val nonConst = 42 foo(nonConst) + + assertEquals("42\n42\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing3.out b/native/native.tests/testData/codegen/boxing/boxing3.out deleted file mode 100644 index daaac9e3030..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing3.out +++ /dev/null @@ -1,2 +0,0 @@ -42 -42 diff --git a/native/native.tests/testData/codegen/boxing/boxing4.kt b/native/native.tests/testData/codegen/boxing/boxing4.kt index 63bf3a08e61..81c8ccffc88 100644 --- a/native/native.tests/testData/codegen/boxing/boxing4.kt +++ b/native/native.tests/testData/codegen/boxing/boxing4.kt @@ -3,19 +3,22 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing4 - import kotlin.test.* -fun printInt(x: Int) = println(x) +val sb = StringBuilder() + +fun printInt(x: Int) = sb.appendLine(x) fun foo(arg: Any?) { if (arg is Int? && arg != null) printInt(arg) } -@Test fun runTest() { +fun box(): String { foo(16) val nonConst = 16 foo(nonConst) + + assertEquals("16\n16\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing4.out b/native/native.tests/testData/codegen/boxing/boxing4.out deleted file mode 100644 index d5567d44519..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing4.out +++ /dev/null @@ -1,2 +0,0 @@ -16 -16 diff --git a/native/native.tests/testData/codegen/boxing/boxing5.kt b/native/native.tests/testData/codegen/boxing/boxing5.kt index bb232eb4bdc..c3876ee5930 100644 --- a/native/native.tests/testData/codegen/boxing/boxing5.kt +++ b/native/native.tests/testData/codegen/boxing/boxing5.kt @@ -3,21 +3,24 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing5 - import kotlin.test.* -fun printInt(x: Int) = println(x) +val sb = StringBuilder() + +fun printInt(x: Int) = sb.appendLine(x) fun foo(arg: Int?) { printInt(arg ?: 16) } -@Test fun runTest() { +fun box(): String { foo(null) foo(42) val nonConstNull = null val nonConstInt = 42 foo(nonConstNull) foo(nonConstInt) + + assertEquals("16\n42\n16\n42\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing5.out b/native/native.tests/testData/codegen/boxing/boxing5.out deleted file mode 100644 index cd2b0a0903f..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing5.out +++ /dev/null @@ -1,4 +0,0 @@ -16 -42 -16 -42 diff --git a/native/native.tests/testData/codegen/boxing/boxing6.kt b/native/native.tests/testData/codegen/boxing/boxing6.kt index 92903b1ddd9..021ede3d4e6 100644 --- a/native/native.tests/testData/codegen/boxing/boxing6.kt +++ b/native/native.tests/testData/codegen/boxing/boxing6.kt @@ -3,21 +3,24 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing6 - import kotlin.test.* -fun printInt(x: Int) = println(x) +val sb = StringBuilder() + +fun printInt(x: Int) = sb.appendLine(x) fun foo(arg: Any) { printInt(arg as? Int ?: 16) } -@Test fun runTest() { +fun box(): String { foo(42) foo("Hello") val nonConstInt = 42 val nonConstString = "Hello" foo(nonConstInt) foo(nonConstString) + + assertEquals("42\n16\n42\n16\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing6.out b/native/native.tests/testData/codegen/boxing/boxing6.out deleted file mode 100644 index 1221344683c..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing6.out +++ /dev/null @@ -1,4 +0,0 @@ -42 -16 -42 -16 diff --git a/native/native.tests/testData/codegen/boxing/boxing7.kt b/native/native.tests/testData/codegen/boxing/boxing7.kt index 4778ea10a54..5d5feb19b48 100644 --- a/native/native.tests/testData/codegen/boxing/boxing7.kt +++ b/native/native.tests/testData/codegen/boxing/boxing7.kt @@ -3,11 +3,11 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing7 - import kotlin.test.* -fun printInt(x: Int) = println(x) +val sb = StringBuilder() + +fun printInt(x: Int) = sb.appendLine(x) fun foo(arg: Any) { val argAsInt = try { @@ -18,11 +18,14 @@ fun foo(arg: Any) { printInt(argAsInt) } -@Test fun runTest() { +fun box(): String { foo(1) foo("Hello") val nonConstInt = 1 val nonConstString = "Hello" foo(nonConstInt) foo(nonConstString) + + assertEquals("1\n0\n1\n0\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing7.out b/native/native.tests/testData/codegen/boxing/boxing7.out deleted file mode 100644 index d80fc78e03d..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing7.out +++ /dev/null @@ -1,4 +0,0 @@ -1 -0 -1 -0 diff --git a/native/native.tests/testData/codegen/boxing/boxing8.kt b/native/native.tests/testData/codegen/boxing/boxing8.kt index 9922a29e320..fb39a784142 100644 --- a/native/native.tests/testData/codegen/boxing/boxing8.kt +++ b/native/native.tests/testData/codegen/boxing/boxing8.kt @@ -3,21 +3,34 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing8 - import kotlin.test.* +val sb = StringBuilder() + fun foo(vararg args: Any?) { for (arg in args) { - println(arg.toString()) + sb.appendLine(arg.toString()) } } -@Test fun runTest() { +fun box(): String { foo(1, null, true, "Hello") val nonConstInt = 1 val nonConstNull = null val nonConstBool = true val nonConstString = "Hello" foo(nonConstInt, nonConstNull, nonConstBool, nonConstString) + + assertEquals(""" + 1 + null + true + Hello + 1 + null + true + Hello + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing8.out b/native/native.tests/testData/codegen/boxing/boxing8.out deleted file mode 100644 index 013406ebd4e..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing8.out +++ /dev/null @@ -1,8 +0,0 @@ -1 -null -true -Hello -1 -null -true -Hello diff --git a/native/native.tests/testData/codegen/boxing/boxing9.kt b/native/native.tests/testData/codegen/boxing/boxing9.kt index 82c850a77f2..429c67f2138 100644 --- a/native/native.tests/testData/codegen/boxing/boxing9.kt +++ b/native/native.tests/testData/codegen/boxing/boxing9.kt @@ -3,13 +3,13 @@ * that can be found in the LICENSE file. */ -package codegen.boxing.boxing9 - import kotlin.test.* +val sb = StringBuilder() + fun foo(vararg args: Any?) { for (arg in args) { - println(arg.toString()) + sb.appendLine(arg.toString()) } } @@ -17,6 +17,20 @@ fun bar(vararg args: Any?) { foo(1, *args, 2, *args, 3) } -@Test fun runTest() { +fun box(): String { bar(null, true, "Hello") + + assertEquals(""" + 1 + null + true + Hello + 2 + null + true + Hello + 3 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/boxing/boxing9.out b/native/native.tests/testData/codegen/boxing/boxing9.out deleted file mode 100644 index d335bb41a7b..00000000000 --- a/native/native.tests/testData/codegen/boxing/boxing9.out +++ /dev/null @@ -1,9 +0,0 @@ -1 -null -true -Hello -2 -null -true -Hello -3 diff --git a/native/native.tests/testData/codegen/boxing/kt53100_casts.kt b/native/native.tests/testData/codegen/boxing/kt53100_casts.kt index 71d16a48a7f..ce82aa9547d 100644 --- a/native/native.tests/testData/codegen/boxing/kt53100_casts.kt +++ b/native/native.tests/testData/codegen/boxing/kt53100_casts.kt @@ -3,8 +3,6 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package codegen.boxing.kt53100_casts - import kotlin.test.* // Reproducer is copied from FloatingPointParser.unaryMinus() @@ -16,7 +14,12 @@ inline fun unaryMinus(value: T): T { } } -@Test fun runTest(){ - println(unaryMinus(0.0)) - println(unaryMinus(0.0f)) +fun box(): String { + val res1 = unaryMinus(0.0).toString() + if (res1 != "-0.0") return "FAIL 1: $res1" + + val res2 = unaryMinus(0.0f).toString() + if (res2 != "-0.0") return "FAIL 2: $res2" + + return "OK" } diff --git a/native/native.tests/testData/codegen/boxing/kt53100_casts.out b/native/native.tests/testData/codegen/boxing/kt53100_casts.out deleted file mode 100644 index e6ffe0d430b..00000000000 --- a/native/native.tests/testData/codegen/boxing/kt53100_casts.out +++ /dev/null @@ -1,2 +0,0 @@ --0.0 --0.0 diff --git a/native/native.tests/testData/codegen/branching/advanced_when2.kt b/native/native.tests/testData/codegen/branching/advanced_when2.kt index 1bc3e268502..c04aa7fb2f2 100644 --- a/native/native.tests/testData/codegen/branching/advanced_when2.kt +++ b/native/native.tests/testData/codegen/branching/advanced_when2.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.branching.advanced_when2 - import kotlin.test.* fun advanced_when2(i: Int): Int { @@ -18,6 +16,9 @@ fun advanced_when2(i: Int): Int { return value } -@Test fun runTest() { - if (advanced_when2(10) != 42) throw Error() +fun box(): String { + val res = advanced_when2(10) + if (res != 42) return "FAIL $res" + + return "OK" } diff --git a/native/native.tests/testData/codegen/branching/advanced_when5.kt b/native/native.tests/testData/codegen/branching/advanced_when5.kt index aaf6b20ac05..e4f181d0308 100644 --- a/native/native.tests/testData/codegen/branching/advanced_when5.kt +++ b/native/native.tests/testData/codegen/branching/advanced_when5.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.branching.advanced_when5 - import kotlin.test.* fun advanced_when5(i: Int): Int { @@ -18,6 +16,9 @@ fun advanced_when5(i: Int): Int { } } -@Test fun runTest() { - if (advanced_when5(5) != 24) throw Error() +fun box(): String { + val res = advanced_when5(5) + if (res != 24) return "FAIL $res" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/branching/if_else.kt b/native/native.tests/testData/codegen/branching/if_else.kt index 2aa2577e286..6b4a37735d6 100644 --- a/native/native.tests/testData/codegen/branching/if_else.kt +++ b/native/native.tests/testData/codegen/branching/if_else.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.branching.if_else - import kotlin.test.* fun if_else(b: Boolean): Int { @@ -12,6 +10,9 @@ fun if_else(b: Boolean): Int { else return 24 } -@Test fun runTest() { - if (if_else(false) != 24) throw Error() +fun box(): String { + val res = if_else(false) + if (res != 24) return "FAIL: $res" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/branching/when2.kt b/native/native.tests/testData/codegen/branching/when2.kt index 87c885c7280..19290fd2f14 100644 --- a/native/native.tests/testData/codegen/branching/when2.kt +++ b/native/native.tests/testData/codegen/branching/when2.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.branching.when2 - import kotlin.test.* fun when2(i: Int): Int { @@ -14,6 +12,9 @@ fun when2(i: Int): Int { } } -@Test fun runTest() { - if (when2(0) != 42) throw Error() +fun box(): String { + val res = when2(0) + if (res != 42) return "FAIL $res" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/branching/when4.kt b/native/native.tests/testData/codegen/branching/when4.kt index 32b44a1471e..940809bddfa 100644 --- a/native/native.tests/testData/codegen/branching/when4.kt +++ b/native/native.tests/testData/codegen/branching/when4.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.branching.when4 - import kotlin.test.* fun when5(i: Int): Int { @@ -16,4 +14,11 @@ fun when5(i: Int): Int { 4 -> return 1 } return 24 -} \ No newline at end of file +} + +fun box(): String { + val res = when5(5) + if (res != 24) return "FAIL $res" + + return "OK" +} diff --git a/native/native.tests/testData/codegen/branching/when5.kt b/native/native.tests/testData/codegen/branching/when5.kt index 8401132e4ef..fd638cdcd66 100644 --- a/native/native.tests/testData/codegen/branching/when5.kt +++ b/native/native.tests/testData/codegen/branching/when5.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.branching.when5 - import kotlin.test.* fun when5(i: Int): Int { @@ -18,6 +16,9 @@ fun when5(i: Int): Int { } } -@Test fun runTest() { - if (when5(2) != 3) throw Error() +fun box(): String { + val res = when5(2) + if (res != 3) return "FAIL $res" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/branching/when6.kt b/native/native.tests/testData/codegen/branching/when6.kt index 352e59fdd9d..c8043e65fe2 100644 --- a/native/native.tests/testData/codegen/branching/when6.kt +++ b/native/native.tests/testData/codegen/branching/when6.kt @@ -3,13 +3,13 @@ * that can be found in the LICENSE file. */ -package codegen.branching.when6 - import kotlin.test.* fun foo() { } -@Test fun runTest() { +fun box(): String { if (true) foo() else foo() + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/branching/when7.kt b/native/native.tests/testData/codegen/branching/when7.kt index 65de6be8274..cbdc517b855 100644 --- a/native/native.tests/testData/codegen/branching/when7.kt +++ b/native/native.tests/testData/codegen/branching/when7.kt @@ -3,12 +3,12 @@ * that can be found in the LICENSE file. */ -package codegen.branching.when7 - import kotlin.test.* -@Test fun runTest() { +fun box(): String { main(emptyArray()) + + return "OK" } fun main(args: Array) { diff --git a/native/native.tests/testData/codegen/branching/when8.kt b/native/native.tests/testData/codegen/branching/when8.kt index be9b52a0250..13d153b4c21 100644 --- a/native/native.tests/testData/codegen/branching/when8.kt +++ b/native/native.tests/testData/codegen/branching/when8.kt @@ -3,13 +3,11 @@ * that can be found in the LICENSE file. */ -package codegen.branching.when8 - import kotlin.test.* -@Test fun runTest() { +fun box(): String { when (true) { - true -> println("true") - false -> println("false") + true -> return "OK" + false -> return "FAIL" } } diff --git a/native/native.tests/testData/codegen/branching/when8.out b/native/native.tests/testData/codegen/branching/when8.out deleted file mode 100644 index 27ba77ddaf6..00000000000 --- a/native/native.tests/testData/codegen/branching/when8.out +++ /dev/null @@ -1 +0,0 @@ -true diff --git a/native/native.tests/testData/codegen/branching/when9.kt b/native/native.tests/testData/codegen/branching/when9.kt index 84702808e43..466e274ba79 100644 --- a/native/native.tests/testData/codegen/branching/when9.kt +++ b/native/native.tests/testData/codegen/branching/when9.kt @@ -3,13 +3,11 @@ * that can be found in the LICENSE file. */ -package codegen.branching.when9 - import kotlin.test.* -@Test fun runTest() { +fun box(): String { foo(0) - println("Ok") + return "OK" } fun foo(x: Int) { diff --git a/native/native.tests/testData/codegen/branching/when9.out b/native/native.tests/testData/codegen/branching/when9.out deleted file mode 100644 index 7326d960397..00000000000 --- a/native/native.tests/testData/codegen/branching/when9.out +++ /dev/null @@ -1 +0,0 @@ -Ok diff --git a/native/native.tests/testData/codegen/branching/when_through.kt b/native/native.tests/testData/codegen/branching/when_through.kt index 16a6fbc92fd..6148d74cec4 100644 --- a/native/native.tests/testData/codegen/branching/when_through.kt +++ b/native/native.tests/testData/codegen/branching/when_through.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.branching.when_through - import kotlin.test.* fun when_through(i: Int): Int { @@ -18,6 +16,9 @@ fun when_through(i: Int): Int { return value } -@Test fun runTest() { - if (when_through(2) != 1) throw Error() +fun box(): String { + val res = when_through(2) + if (res != 1) return "FAIL $res" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/branching/when_with_try1.kt b/native/native.tests/testData/codegen/branching/when_with_try1.kt index e10c2416143..76551bb0eea 100644 --- a/native/native.tests/testData/codegen/branching/when_with_try1.kt +++ b/native/native.tests/testData/codegen/branching/when_with_try1.kt @@ -3,14 +3,17 @@ * that can be found in the LICENSE file. */ -package codegen.branching.when_with_try1 - import kotlin.test.* -@Test fun runTest() { - println(foo(Any())) - println(foo("zzz")) - println(foo("42")) +fun box(): String { + val res1 = foo(Any()) + if (res1 != null) return "FAIL 1: $res1" + val res2 = foo("zzz") + if (res2 != null) return "FAIL 2: $res2" + val res3 = foo("42") + if (res3 != 42) return "FAIL 3: $res3" + + return "OK" } fun foo(value: Any): Int? { diff --git a/native/native.tests/testData/codegen/branching/when_with_try1.out b/native/native.tests/testData/codegen/branching/when_with_try1.out deleted file mode 100644 index a2bc2c3a6b5..00000000000 --- a/native/native.tests/testData/codegen/branching/when_with_try1.out +++ /dev/null @@ -1,3 +0,0 @@ -null -null -42 diff --git a/native/native.tests/testData/codegen/bridges/nativePointed.kt b/native/native.tests/testData/codegen/bridges/nativePointed.kt index c2a815119d6..a3228b139dc 100644 --- a/native/native.tests/testData/codegen/bridges/nativePointed.kt +++ b/native/native.tests/testData/codegen/bridges/nativePointed.kt @@ -3,7 +3,6 @@ * that can be found in the LICENSE file. */ @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) -package codegen.bridges.nativePointed import kotlinx.cinterop.* import kotlin.test.* @@ -16,8 +15,10 @@ class CImpl : C() { override fun foo(x: Int) = null } -@Test fun runTest() { +fun box(): String { val c: C = CImpl() assertNull(c.foo(42)) + + return "OK" } diff --git a/native/native.tests/testData/codegen/bridges/returnTypeSignature.kt b/native/native.tests/testData/codegen/bridges/returnTypeSignature.kt index d9e0e8d5aff..96a5d40b6b6 100644 --- a/native/native.tests/testData/codegen/bridges/returnTypeSignature.kt +++ b/native/native.tests/testData/codegen/bridges/returnTypeSignature.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.signature - import kotlin.test.* class A { } @@ -29,6 +27,8 @@ abstract class AbstractClass(): ExtendsInterface { public override fun parse(source: A): C = C() } -@Test fun runTest() { +fun box(): String { val array = object : AbstractClass() { }.parse(B()) + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/special.kt b/native/native.tests/testData/codegen/bridges/special.kt index 0a685a4f8f3..4db8a0b9848 100644 --- a/native/native.tests/testData/codegen/bridges/special.kt +++ b/native/native.tests/testData/codegen/bridges/special.kt @@ -3,7 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.special import kotlin.test.* @@ -28,19 +27,15 @@ private object NotEmptyMap : MutableMap { fun box(): String { val n = NotEmptyMap as MutableMap - if (n.get(null) != null) return "fail 1" - if (n.containsKey(null)) return "fail 2" - if (n.containsValue(null)) return "fail 3" - if (n.remove(null) != null) return "fail 4" + if (n.get(null) != null) return "FAIL 1: $n" + if (n.containsKey(null)) return "FAIL 2: $n" + if (n.containsValue(null)) return "FAIL 3: $n" + if (n.remove(null) != null) return "FAIL 4: $n" - if (n.get(1) == null) return "fail 5" - if (!n.containsKey("")) return "fail 6" - if (!n.containsValue(3)) return "fail 7" - if (n.remove("") == null) return "fail 8" + if (n.get(1) == null) return "FAIL 5: $n" + if (!n.containsKey("")) return "FAIL 6: $n" + if (!n.containsValue(3)) return "FAIL 7: $n" + if (n.remove("") == null) return "FAIL 8: $n" - return "Ok" + return "OK" } - -@Test fun runTest() { - println(box()) -} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/special.out b/native/native.tests/testData/codegen/bridges/special.out deleted file mode 100644 index 7326d960397..00000000000 --- a/native/native.tests/testData/codegen/bridges/special.out +++ /dev/null @@ -1 +0,0 @@ -Ok diff --git a/native/native.tests/testData/codegen/bridges/specialGeneric.kt b/native/native.tests/testData/codegen/bridges/specialGeneric.kt index 5749dc36dba..18df558ab7a 100644 --- a/native/native.tests/testData/codegen/bridges/specialGeneric.kt +++ b/native/native.tests/testData/codegen/bridges/specialGeneric.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.specialGeneric - import kotlin.test.* interface Element { @@ -35,10 +33,11 @@ internal class MySet : Set { fun set(): Set = MySet() -@Test -fun testMySet() { +fun box(): String { val set = set() - assertFalse(set.contains(Any())) - assertFalse(set.contains(NotContainedElement)) - assertTrue(set.contains(ContainedElement)) + if (set.contains(Any())) return "FAIL 1: $set" + if (set.contains(NotContainedElement)) return "FAIL 2: $set" + if (!set.contains(ContainedElement)) return "FAIL 3: $set" + + return "OK" } diff --git a/native/native.tests/testData/codegen/bridges/test0.kt b/native/native.tests/testData/codegen/bridges/test0.kt index 41a28b75383..e6ec2d2226e 100644 --- a/native/native.tests/testData/codegen/bridges/test0.kt +++ b/native/native.tests/testData/codegen/bridges/test0.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test0 - import kotlin.test.* // vtable call @@ -16,9 +14,13 @@ open class C : A() { override fun foo(): Int = 42 } -@Test fun runTest() { +fun box(): String { val c = C() val a: A = c - println(c.foo().toString()) - println(a.foo().toString()) + val res1 = c.foo().toString() + if (res1 != "42") return "FAIL 1: $res1" + val res2 = a.foo().toString() + if (res2 != "42") return "FAIL 2: $res2" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test0.out b/native/native.tests/testData/codegen/bridges/test0.out deleted file mode 100644 index daaac9e3030..00000000000 --- a/native/native.tests/testData/codegen/bridges/test0.out +++ /dev/null @@ -1,2 +0,0 @@ -42 -42 diff --git a/native/native.tests/testData/codegen/bridges/test1.kt b/native/native.tests/testData/codegen/bridges/test1.kt index 9c677232844..94dd70c9243 100644 --- a/native/native.tests/testData/codegen/bridges/test1.kt +++ b/native/native.tests/testData/codegen/bridges/test1.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test1 - import kotlin.test.* // interface call, bridge overridden @@ -20,8 +18,11 @@ open class B : A() { override fun foo(x: Int) : Int = 42 } -@Test fun runTest() { +fun box(): String { val z1: A = B() - println((z1.foo(1) + 1000).toString()) + val res = (z1.foo(1) + 1000).toString() + if (res != "1042") return "FAIL: $res" + + return "OK" } diff --git a/native/native.tests/testData/codegen/bridges/test1.out b/native/native.tests/testData/codegen/bridges/test1.out deleted file mode 100644 index e3c00fddd36..00000000000 --- a/native/native.tests/testData/codegen/bridges/test1.out +++ /dev/null @@ -1 +0,0 @@ -1042 diff --git a/native/native.tests/testData/codegen/bridges/test10.kt b/native/native.tests/testData/codegen/bridges/test10.kt index 8a6c0b62f79..ca8f64e9f81 100644 --- a/native/native.tests/testData/codegen/bridges/test10.kt +++ b/native/native.tests/testData/codegen/bridges/test10.kt @@ -3,13 +3,13 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test10 - import kotlin.test.* +val sb = StringBuilder() + open class A { open fun foo(x: T) { - println(x.toString()) + sb.appendLine(x.toString()) } } @@ -28,10 +28,13 @@ fun zzz(a: A) { a.foo(42) } -@Test fun runTest() { +fun box(): String { val b = B() zzz(b) val a = A() zzz(a) - println(b.z) + sb.appendLine(b.z.toString()) + + assertEquals("42\n42\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test10.out b/native/native.tests/testData/codegen/bridges/test10.out deleted file mode 100644 index daaac9e3030..00000000000 --- a/native/native.tests/testData/codegen/bridges/test10.out +++ /dev/null @@ -1,2 +0,0 @@ -42 -42 diff --git a/native/native.tests/testData/codegen/bridges/test11.kt b/native/native.tests/testData/codegen/bridges/test11.kt index eed0d47b2c9..78964ca383b 100644 --- a/native/native.tests/testData/codegen/bridges/test11.kt +++ b/native/native.tests/testData/codegen/bridges/test11.kt @@ -3,10 +3,10 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test11 - import kotlin.test.* +val sb = StringBuilder() + interface I { fun foo(x: Int) } @@ -16,14 +16,20 @@ abstract class A { } class B : A(), I { - override fun foo(x: Int) = println(x) + override fun foo(x: Int) { + sb.appendLine(x) + Unit + } } -@Test fun runTest() { +fun box(): String { val b = B() val a: A = b val c: I = b b.foo(42) a.foo(42) c.foo(42) + + assertEquals("42\n42\n42\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test11.out b/native/native.tests/testData/codegen/bridges/test11.out deleted file mode 100644 index bda709ecfb4..00000000000 --- a/native/native.tests/testData/codegen/bridges/test11.out +++ /dev/null @@ -1,3 +0,0 @@ -42 -42 -42 diff --git a/native/native.tests/testData/codegen/bridges/test12.kt b/native/native.tests/testData/codegen/bridges/test12.kt index 61b203bf347..467bd85e6cd 100644 --- a/native/native.tests/testData/codegen/bridges/test12.kt +++ b/native/native.tests/testData/codegen/bridges/test12.kt @@ -3,23 +3,23 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test12 - import kotlin.test.* +val sb = StringBuilder() + abstract class A { abstract fun foo(x: T) } class B : A() { override fun foo(x: Int) { - println("B: $x") + sb.appendLine("B: $x") } } class C : A() { override fun foo(x: Any) { - println("C: $x") + sb.appendLine("C: $x") } } @@ -27,7 +27,10 @@ fun foo(arg: A) { arg.foo(42) } -@Test fun runTest() { +fun box(): String { foo(B()) foo(C()) + + assertEquals("B: 42\nC: 42\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test12.out b/native/native.tests/testData/codegen/bridges/test12.out deleted file mode 100644 index 6b31c5bd07f..00000000000 --- a/native/native.tests/testData/codegen/bridges/test12.out +++ /dev/null @@ -1,2 +0,0 @@ -B: 42 -C: 42 diff --git a/native/native.tests/testData/codegen/bridges/test13.kt b/native/native.tests/testData/codegen/bridges/test13.kt index f564ae68c34..a0a15928425 100644 --- a/native/native.tests/testData/codegen/bridges/test13.kt +++ b/native/native.tests/testData/codegen/bridges/test13.kt @@ -3,13 +3,13 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test13 - import kotlin.test.* +val sb = StringBuilder() + open class A { open fun T.foo() { - println(this.toString()) + sb.appendLine(this.toString()) } fun bar(x: T) { @@ -19,13 +19,16 @@ open class A { open class B: A() { override fun Int.foo() { - println(this) + sb.appendLine(this.toString()) } } -@Test fun runTest() { +fun box(): String { val b = B() val a = A() b.bar(42) a.bar(42) + + assertEquals("42\n42\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test13.out b/native/native.tests/testData/codegen/bridges/test13.out deleted file mode 100644 index daaac9e3030..00000000000 --- a/native/native.tests/testData/codegen/bridges/test13.out +++ /dev/null @@ -1,2 +0,0 @@ -42 -42 diff --git a/native/native.tests/testData/codegen/bridges/test14.kt b/native/native.tests/testData/codegen/bridges/test14.kt index 738deb16f12..a6316cf95b1 100644 --- a/native/native.tests/testData/codegen/bridges/test14.kt +++ b/native/native.tests/testData/codegen/bridges/test14.kt @@ -3,14 +3,14 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test14 - import kotlin.test.* +val sb = StringBuilder() + open class A { open fun foo(x: T, y: U) { - println(x.toString()) - println(y.toString()) + sb.appendLine(x.toString()) + sb.appendLine(y.toString()) } } @@ -35,19 +35,32 @@ fun zzz(a: A) { a.foo(42, 56) } -@Test fun runTest() { +fun box(): String { val b = B() zzz(b) val a = A() zzz(a) - println(b.z) - println(b.q) + sb.appendLine(b.z.toString()) + sb.appendLine(b.q.toString()) val i1: I1 = b i1.foo(56, 42) - println(b.z) - println(b.q) + sb.appendLine(b.z.toString()) + sb.appendLine(b.q.toString()) val i2: I2 = b i2.foo(156, 142) - println(b.z) - println(b.q) + sb.appendLine(b.z.toString()) + sb.appendLine(b.q.toString()) + + assertEquals(""" + 42 + 56 + 42 + 56 + 56 + 42 + 156 + 142 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test14.out b/native/native.tests/testData/codegen/bridges/test14.out deleted file mode 100644 index c87ec05715d..00000000000 --- a/native/native.tests/testData/codegen/bridges/test14.out +++ /dev/null @@ -1,8 +0,0 @@ -42 -56 -42 -56 -56 -42 -156 -142 diff --git a/native/native.tests/testData/codegen/bridges/test15.kt b/native/native.tests/testData/codegen/bridges/test15.kt index 7e53ac2598b..98f9f60fe0c 100644 --- a/native/native.tests/testData/codegen/bridges/test15.kt +++ b/native/native.tests/testData/codegen/bridges/test15.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test15 - import kotlin.test.* // non-generic interface, generic impl, vtable call + interface call @@ -38,7 +36,3 @@ fun box(): String { return "OK" } - -@Test fun runTest() { - println(box()) -} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test15.out b/native/native.tests/testData/codegen/bridges/test15.out deleted file mode 100644 index d86bac9de59..00000000000 --- a/native/native.tests/testData/codegen/bridges/test15.out +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/native/native.tests/testData/codegen/bridges/test16.kt b/native/native.tests/testData/codegen/bridges/test16.kt index b691a585c82..ae06a51e026 100644 --- a/native/native.tests/testData/codegen/bridges/test16.kt +++ b/native/native.tests/testData/codegen/bridges/test16.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test16 - import kotlin.test.* interface A { @@ -21,9 +19,14 @@ open class B: C() { fun bar(c: C) = c.foo() -@Test fun runTest() { +fun box(): String { val b = B() val c: C = b - println(bar(b)) - println(bar(c)) + val barb = bar(b) + if (barb != "OK") return "FAIL b: $barb" + + val barc = bar(c) + if (barc != "OK") return "FAIL c: $barc" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test16.out b/native/native.tests/testData/codegen/bridges/test16.out deleted file mode 100644 index 2c94e483710..00000000000 --- a/native/native.tests/testData/codegen/bridges/test16.out +++ /dev/null @@ -1,2 +0,0 @@ -OK -OK diff --git a/native/native.tests/testData/codegen/bridges/test17.kt b/native/native.tests/testData/codegen/bridges/test17.kt index 21af6f99e2d..cadfc509edc 100644 --- a/native/native.tests/testData/codegen/bridges/test17.kt +++ b/native/native.tests/testData/codegen/bridges/test17.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test17 - import kotlin.test.* // abstract bridge @@ -22,13 +20,19 @@ class D: C() { } } -@Test fun runTest() { +fun box(): String { val d = D() val c: C = d val b: B = d val a: A = d - println(d.foo()) - println(c.foo()) - println(b.foo()) - println(a.foo()) + val foo0 = d.foo() + if (foo0 != 42) return "FAIL d: $foo0" + val foo1 = c.foo() + if (foo1 != 42) return "FAIL c: $foo1" + val foo2 = b.foo() + if (foo2 != 42) return "FAIL b: $foo2" + val foo3 = a.foo() + if (foo3 != 42) return "FAIL a: $foo3" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test17.out b/native/native.tests/testData/codegen/bridges/test17.out deleted file mode 100644 index 8fb8a08e3f9..00000000000 --- a/native/native.tests/testData/codegen/bridges/test17.out +++ /dev/null @@ -1,4 +0,0 @@ -42 -42 -42 -42 diff --git a/native/native.tests/testData/codegen/bridges/test18.kt b/native/native.tests/testData/codegen/bridges/test18.kt index c6d47b73475..12a642d6fb1 100644 --- a/native/native.tests/testData/codegen/bridges/test18.kt +++ b/native/native.tests/testData/codegen/bridges/test18.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test18 - import kotlin.test.* // overriden function returns Unit @@ -16,7 +14,9 @@ open class B: A() { override fun foo(): Unit { } } -@Test fun runTest() { +fun box(): String { val a: A = B() - println(a.foo()) + val afoo = a.foo() + if (afoo != Unit) return "FAIL $afoo" + return "OK" } diff --git a/native/native.tests/testData/codegen/bridges/test18.out b/native/native.tests/testData/codegen/bridges/test18.out deleted file mode 100644 index 0fd40fc5055..00000000000 --- a/native/native.tests/testData/codegen/bridges/test18.out +++ /dev/null @@ -1 +0,0 @@ -kotlin.Unit diff --git a/native/native.tests/testData/codegen/bridges/test2.kt b/native/native.tests/testData/codegen/bridges/test2.kt index df13d9d14b0..90a6fde7b68 100644 --- a/native/native.tests/testData/codegen/bridges/test2.kt +++ b/native/native.tests/testData/codegen/bridges/test2.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test2 - import kotlin.test.* // vtable call, bridge inherited @@ -18,9 +16,13 @@ open class C : A() { open class D: C() -@Test fun runTest() { +fun box(): String { val c = D() val a: A = c - println(c.foo().toString()) - println(a.foo().toString()) + val res1 = c.foo().toString() + if (res1 != "42") return "FAIL 1: $res1" + val res2 = a.foo().toString() + if (res2 != "42") return "FAIL 2: $res2" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test2.out b/native/native.tests/testData/codegen/bridges/test2.out deleted file mode 100644 index daaac9e3030..00000000000 --- a/native/native.tests/testData/codegen/bridges/test2.out +++ /dev/null @@ -1,2 +0,0 @@ -42 -42 diff --git a/native/native.tests/testData/codegen/bridges/test3.kt b/native/native.tests/testData/codegen/bridges/test3.kt index 60e88a22909..a887dd03800 100644 --- a/native/native.tests/testData/codegen/bridges/test3.kt +++ b/native/native.tests/testData/codegen/bridges/test3.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test3 - import kotlin.test.* // non-generic interface, generic impl, non-virtual call + interface call @@ -33,7 +31,3 @@ fun box(): String { return "OK" } - -@Test fun runTest() { - println(box()) -} diff --git a/native/native.tests/testData/codegen/bridges/test3.out b/native/native.tests/testData/codegen/bridges/test3.out deleted file mode 100644 index d86bac9de59..00000000000 --- a/native/native.tests/testData/codegen/bridges/test3.out +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/native/native.tests/testData/codegen/bridges/test4.kt b/native/native.tests/testData/codegen/bridges/test4.kt index 68092d868f0..7ae9c618dff 100644 --- a/native/native.tests/testData/codegen/bridges/test4.kt +++ b/native/native.tests/testData/codegen/bridges/test4.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test4 - import kotlin.test.* // vtable call + interface call @@ -22,9 +20,13 @@ open class A { open class B: A(), Z, Y -@Test fun runTest() { +fun box(): String { val z: Z = B() val y: Y = z as Y - println(z.foo().toString()) - println(y.foo().toString()) + val res1 = z.foo().toString() + if (res1 != "42") return "FAIL 1: $res1" + val res2 = y.foo().toString() + if (res2 != "42") return "FAIL 2: $res2" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test4.out b/native/native.tests/testData/codegen/bridges/test4.out deleted file mode 100644 index daaac9e3030..00000000000 --- a/native/native.tests/testData/codegen/bridges/test4.out +++ /dev/null @@ -1,2 +0,0 @@ -42 -42 diff --git a/native/native.tests/testData/codegen/bridges/test5.kt b/native/native.tests/testData/codegen/bridges/test5.kt index d96af81e848..89eab74cc21 100644 --- a/native/native.tests/testData/codegen/bridges/test5.kt +++ b/native/native.tests/testData/codegen/bridges/test5.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test5 - import kotlin.test.* // non-generic interface, generic impl, vtable call + interface call @@ -33,7 +31,3 @@ fun box(): String { return "OK" } - -@Test fun runTest() { - println(box()) -} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test5.out b/native/native.tests/testData/codegen/bridges/test5.out deleted file mode 100644 index d86bac9de59..00000000000 --- a/native/native.tests/testData/codegen/bridges/test5.out +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/native/native.tests/testData/codegen/bridges/test6.kt b/native/native.tests/testData/codegen/bridges/test6.kt index d2ac309edc9..c74a1d0fed0 100644 --- a/native/native.tests/testData/codegen/bridges/test6.kt +++ b/native/native.tests/testData/codegen/bridges/test6.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test6 - import kotlin.test.* // vtable call + interface call @@ -26,15 +24,17 @@ open class C : A() { open class D: C(), Y, Z -@Test fun runTest() { +fun box(): String { val d = D() val y: Y = d val z: Z = d val c: C = d val a: A = d - println(d.foo().toString()) - println(y.foo().toString()) - println(z.foo().toString()) - println(c.foo().toString()) - println(a.foo().toString()) + if (d.foo().toString() != "42") return "FAIL 1" + if (y.foo().toString() != "42") return "FAIL 2" + if (z.foo().toString() != "42") return "FAIL 3" + if (c.foo().toString() != "42") return "FAIL 4" + if (a.foo().toString() != "42") return "FAIL 5" + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test6.out b/native/native.tests/testData/codegen/bridges/test6.out deleted file mode 100644 index 08adcfe27a1..00000000000 --- a/native/native.tests/testData/codegen/bridges/test6.out +++ /dev/null @@ -1,5 +0,0 @@ -42 -42 -42 -42 -42 diff --git a/native/native.tests/testData/codegen/bridges/test7.kt b/native/native.tests/testData/codegen/bridges/test7.kt index 943756ebc31..e2a88125d5f 100644 --- a/native/native.tests/testData/codegen/bridges/test7.kt +++ b/native/native.tests/testData/codegen/bridges/test7.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test7 - import kotlin.test.* // generic interface, non-generic impl, vtable call + interface call @@ -33,7 +31,3 @@ fun box(): String { return "OK" } - -@Test fun runTest() { - println(box()) -} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test7.out b/native/native.tests/testData/codegen/bridges/test7.out deleted file mode 100644 index d86bac9de59..00000000000 --- a/native/native.tests/testData/codegen/bridges/test7.out +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/native/native.tests/testData/codegen/bridges/test8.kt b/native/native.tests/testData/codegen/bridges/test8.kt index a401382a272..7fa7b70ed17 100644 --- a/native/native.tests/testData/codegen/bridges/test8.kt +++ b/native/native.tests/testData/codegen/bridges/test8.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test8 - import kotlin.test.* // generic interface, non-generic impl, non-virtual call + interface call @@ -33,7 +31,3 @@ fun box(): String { return "OK" } - -@Test fun runTest() { - println(box()) -} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test8.out b/native/native.tests/testData/codegen/bridges/test8.out deleted file mode 100644 index d86bac9de59..00000000000 --- a/native/native.tests/testData/codegen/bridges/test8.out +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/native/native.tests/testData/codegen/bridges/test9.kt b/native/native.tests/testData/codegen/bridges/test9.kt index 176ceae69b7..63028d8ddcc 100644 --- a/native/native.tests/testData/codegen/bridges/test9.kt +++ b/native/native.tests/testData/codegen/bridges/test9.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.bridges.test9 - import kotlin.test.* // abstract class vtable call @@ -30,7 +28,3 @@ fun box(): String { else -> "OK" } } - -@Test fun runTest() { - println(box()) -} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/bridges/test9.out b/native/native.tests/testData/codegen/bridges/test9.out deleted file mode 100644 index d86bac9de59..00000000000 --- a/native/native.tests/testData/codegen/bridges/test9.out +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/native/native.tests/testData/codegen/classDelegation/generic.kt b/native/native.tests/testData/codegen/classDelegation/generic.kt index 022696b8824..a79c39d6a1c 100644 --- a/native/native.tests/testData/codegen/classDelegation/generic.kt +++ b/native/native.tests/testData/codegen/classDelegation/generic.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.classDelegation.generic - import kotlin.test.* open class Content() { @@ -24,7 +22,3 @@ object Impl : ContentBox { class ContentBoxDelegate() : ContentBox by (Impl as ContentBox) fun box() = ContentBoxDelegate().get().toString() - -@Test fun runTest() { - println(box()) -} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/classDelegation/generic.out b/native/native.tests/testData/codegen/classDelegation/generic.out deleted file mode 100644 index d86bac9de59..00000000000 --- a/native/native.tests/testData/codegen/classDelegation/generic.out +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/native/native.tests/testData/codegen/classDelegation/method.kt b/native/native.tests/testData/codegen/classDelegation/method.kt index 1b013f831de..07a0fcb6ceb 100644 --- a/native/native.tests/testData/codegen/classDelegation/method.kt +++ b/native/native.tests/testData/codegen/classDelegation/method.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.classDelegation.method - import kotlin.test.* interface A { @@ -20,9 +18,9 @@ class C(a: A) : A by a fun box(): String { val c = C(B()) val a: A = c - return c.foo() + a.foo() + val cfoo = c.foo() + if (cfoo != "OK") return "FAIL cfoo: $cfoo" + val afoo = a.foo() + if (afoo != "OK") return "FAIL afoo: $afoo" + return "OK" } - -@Test fun runTest() { - println(box()) -} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/classDelegation/method.out b/native/native.tests/testData/codegen/classDelegation/method.out deleted file mode 100644 index d65874ef665..00000000000 --- a/native/native.tests/testData/codegen/classDelegation/method.out +++ /dev/null @@ -1 +0,0 @@ -OKOK diff --git a/native/native.tests/testData/codegen/classDelegation/property.kt b/native/native.tests/testData/codegen/classDelegation/property.kt index a55a5458a17..f01f87d09ef 100644 --- a/native/native.tests/testData/codegen/classDelegation/property.kt +++ b/native/native.tests/testData/codegen/classDelegation/property.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.classDelegation.property - import kotlin.test.* interface A { @@ -20,9 +18,7 @@ class Q(a: A): A by a fun box(): String { val q = Q(C()) val a: A = q - return q.x.toString() + a.x.toString() + if (q.x != 42) return "FAIL q.x=${q.x}" + if (a.x != 42) return "FAIL a.x=${a.x}" + return "OK" } - -@Test fun runTest() { - println(box()) -} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/classDelegation/property.out b/native/native.tests/testData/codegen/classDelegation/property.out deleted file mode 100644 index 36fade77193..00000000000 --- a/native/native.tests/testData/codegen/classDelegation/property.out +++ /dev/null @@ -1 +0,0 @@ -4242 diff --git a/native/native.tests/testData/codegen/classDelegation/withBridge.kt b/native/native.tests/testData/codegen/classDelegation/withBridge.kt index 60112822c3c..045d52d4795 100644 --- a/native/native.tests/testData/codegen/classDelegation/withBridge.kt +++ b/native/native.tests/testData/codegen/classDelegation/withBridge.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.classDelegation.withBridge - import kotlin.test.* interface A { @@ -31,7 +29,3 @@ fun box(): String { else -> "OK" } } - -@Test fun runTest() { - println(box()) -} \ No newline at end of file diff --git a/native/native.tests/testData/codegen/classDelegation/withBridge.out b/native/native.tests/testData/codegen/classDelegation/withBridge.out deleted file mode 100644 index d86bac9de59..00000000000 --- a/native/native.tests/testData/codegen/classDelegation/withBridge.out +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/native/native.tests/testData/codegen/contracts/contractForCast.kt b/native/native.tests/testData/codegen/contracts/contractForCast.kt new file mode 100644 index 00000000000..8fdffd43965 --- /dev/null +++ b/native/native.tests/testData/codegen/contracts/contractForCast.kt @@ -0,0 +1,20 @@ +import kotlin.test.* +import kotlin.contracts.* + +open class S +class P(val str: String = "P") : S() + +@OptIn(kotlin.contracts.ExperimentalContracts::class) +fun check(actual: Boolean) { + contract { returns() implies actual } + assertTrue(actual) +} + +fun box(): String { + val s: S = P() + + check(s is P) + assertEquals(s.str, "P") + + return "OK" +} diff --git a/native/native.tests/testData/codegen/contracts/contracts.kt b/native/native.tests/testData/codegen/contracts/contracts.kt deleted file mode 100644 index cf87b973605..00000000000 --- a/native/native.tests/testData/codegen/contracts/contracts.kt +++ /dev/null @@ -1,47 +0,0 @@ -import kotlin.test.* -import kotlin.contracts.* - -open class S -class P(val str: String = "P") : S() - -@OptIn(kotlin.contracts.ExperimentalContracts::class) -fun check(actual: Boolean) { - contract { returns() implies actual } - assertTrue(actual) -} - -@Test fun testContractForCast() { - val s: S = P() - - check(s is P) - assertEquals(s.str, "P") -} - -@Test fun testRequire() { - val s: S = P() - - require(s is P) - assertEquals(s.str, "P") -} - -@Test fun testNonNullSmartCast() { - val i: Int? = 1234 - requireNotNull(i) - assertEquals(i, 1234) -} - -@Test fun testRunLambdaForVal() { - val x: Int - run { - x = 42 - } - assertEquals(x, 42) -} - -@Test fun testIsNullString() { - assertEquals("STR", nullableString("str")) - - assertEquals("", nullableString(null)) -} - -private fun nullableString(string: String?): String = if (string.isNullOrBlank()) "" else "STR" \ No newline at end of file diff --git a/native/native.tests/testData/codegen/contracts/isNullString.kt b/native/native.tests/testData/codegen/contracts/isNullString.kt new file mode 100644 index 00000000000..e28cd3af45d --- /dev/null +++ b/native/native.tests/testData/codegen/contracts/isNullString.kt @@ -0,0 +1,21 @@ +import kotlin.test.* +import kotlin.contracts.* + +open class S +class P(val str: String = "P") : S() + +@OptIn(kotlin.contracts.ExperimentalContracts::class) +fun check(actual: Boolean) { + contract { returns() implies actual } + assertTrue(actual) +} + +fun box(): String { + assertEquals("STR", nullableString("str")) + + assertEquals("", nullableString(null)) + + return "OK" +} + +private fun nullableString(string: String?): String = if (string.isNullOrBlank()) "" else "STR" \ No newline at end of file diff --git a/native/native.tests/testData/codegen/contracts/nonNullSmartCast.kt b/native/native.tests/testData/codegen/contracts/nonNullSmartCast.kt new file mode 100644 index 00000000000..0263d75ec4a --- /dev/null +++ b/native/native.tests/testData/codegen/contracts/nonNullSmartCast.kt @@ -0,0 +1,19 @@ +import kotlin.test.* +import kotlin.contracts.* + +open class S +class P(val str: String = "P") : S() + +@OptIn(kotlin.contracts.ExperimentalContracts::class) +fun check(actual: Boolean) { + contract { returns() implies actual } + assertTrue(actual) +} + +fun box(): String { + val i: Int? = 1234 + requireNotNull(i) + assertEquals(i, 1234) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/contracts/require.kt b/native/native.tests/testData/codegen/contracts/require.kt new file mode 100644 index 00000000000..2cc3176a5f0 --- /dev/null +++ b/native/native.tests/testData/codegen/contracts/require.kt @@ -0,0 +1,20 @@ +import kotlin.test.* +import kotlin.contracts.* + +open class S +class P(val str: String = "P") : S() + +@OptIn(kotlin.contracts.ExperimentalContracts::class) +fun check(actual: Boolean) { + contract { returns() implies actual } + assertTrue(actual) +} + +fun box(): String { + val s: S = P() + + require(s is P) + assertEquals(s.str, "P") + + return "OK" +} diff --git a/native/native.tests/testData/codegen/contracts/runLambdaForVal.kt b/native/native.tests/testData/codegen/contracts/runLambdaForVal.kt new file mode 100644 index 00000000000..db34448dca7 --- /dev/null +++ b/native/native.tests/testData/codegen/contracts/runLambdaForVal.kt @@ -0,0 +1,21 @@ +import kotlin.test.* +import kotlin.contracts.* + +open class S +class P(val str: String = "P") : S() + +@OptIn(kotlin.contracts.ExperimentalContracts::class) +fun check(actual: Boolean) { + contract { returns() implies actual } + assertTrue(actual) +} + +fun box(): String { + val x: Int + run { + x = 42 + } + assertEquals(x, 42) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/controlflow/break.kt b/native/native.tests/testData/codegen/controlflow/break.kt index 46a230b4662..0631ed2c5b0 100644 --- a/native/native.tests/testData/codegen/controlflow/break.kt +++ b/native/native.tests/testData/codegen/controlflow/break.kt @@ -3,18 +3,18 @@ * that can be found in the LICENSE file. */ -package codegen.controlflow.`break` - import kotlin.test.* +val sb = StringBuilder() + fun foo() { var i = 0 l1@while (true) { - println("foo@l1") + sb.appendLine("foo@l1") try { l2@while (true) { if ((i++ % 2) == 0) continue@l2 - println("foo@l2") + sb.appendLine("foo@l2") if (i > 4) break@l1 } } finally { @@ -26,12 +26,12 @@ fun bar() { var i = 0 l1@do { try { - println("bar@l1") + sb.appendLine("bar@l1") throw Exception() } catch (e: Exception) { l2@do { if ((i++ % 2) == 0) continue@l2 - println("bar@l2") + sb.appendLine("bar@l2") if (i > 4) break@l1 } while (true) } @@ -41,21 +41,38 @@ fun bar() { fun qux() { l1@for (i in 1..6) { t1@try { - println("qux@t1") + sb.appendLine("qux@t1") throw Exception() } finally { l2@ for (j in 1..6) { if ((j % 2) == 0) continue@l2 - println("qux@l2") + sb.appendLine("qux@l2") if (j > 4) break@l1 } } } } -@Test fun runTest() { +fun box(): String { foo() bar() qux() + + assertEquals(""" + foo@l1 + foo@l2 + foo@l2 + foo@l2 + bar@l1 + bar@l2 + bar@l2 + bar@l2 + qux@t1 + qux@l2 + qux@l2 + qux@l2 + + """.trimIndent(), sb.toString()) + return "OK" } diff --git a/native/native.tests/testData/codegen/controlflow/break.out b/native/native.tests/testData/codegen/controlflow/break.out deleted file mode 100644 index 678d6620e61..00000000000 --- a/native/native.tests/testData/codegen/controlflow/break.out +++ /dev/null @@ -1,12 +0,0 @@ -foo@l1 -foo@l2 -foo@l2 -foo@l2 -bar@l1 -bar@l2 -bar@l2 -bar@l2 -qux@t1 -qux@l2 -qux@l2 -qux@l2 diff --git a/native/native.tests/testData/codegen/controlflow/break1.kt b/native/native.tests/testData/codegen/controlflow/break1.kt index b9aac1dbd05..c7db461746d 100644 --- a/native/native.tests/testData/codegen/controlflow/break1.kt +++ b/native/native.tests/testData/codegen/controlflow/break1.kt @@ -3,14 +3,17 @@ * that can be found in the LICENSE file. */ -package codegen.controlflow.break1 - import kotlin.test.* -@Test fun runTest() { +val sb = StringBuilder() + +fun box(): String { loop@ while (true) { - println("Body") + sb.appendLine("Body") break } - println("Done") + sb.appendLine("Done") + + assertEquals("Body\nDone\n", sb.toString()) + return "OK" } diff --git a/native/native.tests/testData/codegen/controlflow/break1.out b/native/native.tests/testData/codegen/controlflow/break1.out deleted file mode 100644 index 733adc12a15..00000000000 --- a/native/native.tests/testData/codegen/controlflow/break1.out +++ /dev/null @@ -1,2 +0,0 @@ -Body -Done diff --git a/native/native.tests/testData/codegen/controlflow/for_loops.kt b/native/native.tests/testData/codegen/controlflow/for_loops.kt index 124441eb91d..55e45f9f392 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops.kt @@ -3,81 +3,102 @@ * that can be found in the LICENSE file. */ -package codegen.controlflow.for_loops - import kotlin.test.* -@Test fun runTest() { +val sb = StringBuilder() + +fun box(): String { // Simple loops for (i in 0..4) { - print(i) + sb.append(i) } - println() + sb.appendLine() for (i in 0 until 4) { - print(i) + sb.append(i) } - println() + sb.appendLine() for (i in 4 downTo 0) { - print(i) + sb.append(i) } - println() - println() + sb.appendLine() + sb.appendLine() // Steps for (i in 0..4 step 2) { - print(i) + sb.append(i) } - println() + sb.appendLine() for (i in 0 until 4 step 2) { - print(i) + sb.append(i) } - println() + sb.appendLine() for (i in 4 downTo 0 step 2) { - print(i) + sb.append(i) } - println() - println() + sb.appendLine() + sb.appendLine() // Two steps for (i in 0..6 step 2 step 3) { - print(i) + sb.append(i) } - println() + sb.appendLine() for (i in 0 until 6 step 2 step 3) { - print(i) + sb.append(i) } - println() + sb.appendLine() for (i in 6 downTo 0 step 2 step 3) { - print(i) + sb.append(i) } - println() - println() + sb.appendLine() + sb.appendLine() // Without constants val a = 0 val b = 4 val s = 2 for (i in a..b step s) { - print(i) + sb.append(i) } - println() + sb.appendLine() for (i in a until b step s) { - print(i) + sb.append(i) } - println() + sb.appendLine() for (i in b downTo a step s) { - print(i) + sb.append(i) } - println() - println() + sb.appendLine() + sb.appendLine() + + assertEquals(""" + 01234 + 0123 + 43210 + + 024 + 02 + 420 + + 036 + 03 + 630 + + 024 + 02 + 420 + + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops.out b/native/native.tests/testData/codegen/controlflow/for_loops.out deleted file mode 100644 index 395ee50dde4..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops.out +++ /dev/null @@ -1,16 +0,0 @@ -01234 -0123 -43210 - -024 -02 -420 - -036 -03 -630 - -024 -02 -420 - diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_array.kt b/native/native.tests/testData/codegen/controlflow/for_loops_array.kt index 68cec2fed38..fdb15da5afd 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_array.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_array.kt @@ -1,7 +1,7 @@ -package codegen.controlflow.for_loops_array - import kotlin.test.* +val sb = StringBuilder() + fun genericArray(data : T): Int { var sum = 0 for (element in data) { @@ -18,23 +18,28 @@ fun IntArray.sum(): Int { return sum } -@Test fun runTest() { +fun box(): String { val intArray = intArrayOf(4, 0, 3, 5) val emptyArray = arrayOf() for (element in intArray) { - print(element) + sb.append(element) } - println() + sb.appendLine() for (element in emptyArray) { - print(element) + sb.append(element) } - println() + sb.appendLine() val byteArray = byteArrayOf(1, -1) - println(genericArray(byteArray)) + sb.append(genericArray(byteArray)) + sb.appendLine() val fives = intArrayOf(5, 5, 5, -5, -5, -5) - println(fives.sum()) + sb.append(fives.sum()) + sb.appendLine() + + assertEquals("4035\n\n0\n0\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_array.out b/native/native.tests/testData/codegen/controlflow/for_loops_array.out deleted file mode 100644 index f8097b81672..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_array.out +++ /dev/null @@ -1,4 +0,0 @@ -4035 - -0 -0 diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_array_break_continue.kt b/native/native.tests/testData/codegen/controlflow/for_loops_array_break_continue.kt index d107a550726..5ce552fc237 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_array_break_continue.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_array_break_continue.kt @@ -1,21 +1,24 @@ -package codegen.controlflow.for_loops_array_break_continue - import kotlin.test.* -@Test fun runTest() { +val sb = StringBuilder() + +fun box(): String { val intArray = intArrayOf(4, 0, 3, 5) val emptyArray = arrayOf() for (element in intArray) { - print(element) + sb.append(element) if (element == 3) { break } } - println() + sb.appendLine() for (element in emptyArray) { - print(element) + sb.append(element) } - println() + sb.appendLine() + + assertEquals("403\n\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_array_break_continue.out b/native/native.tests/testData/codegen/controlflow/for_loops_array_break_continue.out deleted file mode 100644 index 47683305fa8..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_array_break_continue.out +++ /dev/null @@ -1,2 +0,0 @@ -403 - diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_array_indices.kt b/native/native.tests/testData/codegen/controlflow/for_loops_array_indices.kt index 89d21c2892e..646129cdc10 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_array_indices.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_array_indices.kt @@ -1,18 +1,21 @@ -package codegen.controlflow.for_loops_array_indices - import kotlin.test.* -@Test fun runTest() { +val sb = StringBuilder() + +fun box(): String { val intArray = intArrayOf(4, 0, 3, 5) val emptyArray = arrayOf() for (index in intArray.indices) { - print(index) + sb.append(index) } - println() + sb.appendLine() for (index in emptyArray.indices) { - print(index) + sb.append(index) } - println() + sb.appendLine() + + assertEquals("0123\n\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_array_indices.out b/native/native.tests/testData/codegen/controlflow/for_loops_array_indices.out deleted file mode 100644 index 1f615173db1..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_array_indices.out +++ /dev/null @@ -1,2 +0,0 @@ -0123 - diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_array_mutation.kt b/native/native.tests/testData/codegen/controlflow/for_loops_array_mutation.kt index 0d1c5b707e8..fdfe513b781 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_array_mutation.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_array_mutation.kt @@ -1,13 +1,16 @@ -package codegen.controlflow.for_loops_array_mutation - import kotlin.test.* -@Test fun runTest() { +val sb = StringBuilder() + +fun box(): String { val intArray = arrayOf(4, 0, 3, 5) for (element in intArray) { intArray[2] = 0 intArray[3] = 0 - print(element) + sb.append(element) } + + assertEquals("4000", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_array_mutation.out b/native/native.tests/testData/codegen/controlflow/for_loops_array_mutation.out deleted file mode 100644 index a2113715a3e..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_array_mutation.out +++ /dev/null @@ -1 +0,0 @@ -4000 \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_array_nested.kt b/native/native.tests/testData/codegen/controlflow/for_loops_array_nested.kt index 9ecf83bca48..c4b435a8a3f 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_array_nested.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_array_nested.kt @@ -1,8 +1,8 @@ -package codegen.controlflow.for_loops_array_nested - import kotlin.test.* -@Test fun arrayOfArrays() { +val sb = StringBuilder() + +fun box(): String { val metaArray = arrayOf( arrayOf(1, 2, 3), arrayOf("Hello"), @@ -13,13 +13,22 @@ import kotlin.test.* inner@for (elem in array) { if (elem is IntProgression) { for (i in elem) { - print(i) + sb.append(i) } continue@inner } else { - print(elem) + sb.append(elem) } } - println() + sb.appendLine() } + + assertEquals(""" + 123 + Hello + + 12345678910 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_array_nested.out b/native/native.tests/testData/codegen/controlflow/for_loops_array_nested.out deleted file mode 100644 index 0db872924d0..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_array_nested.out +++ /dev/null @@ -1,4 +0,0 @@ -123 -Hello - -12345678910 diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_array_nullable.kt b/native/native.tests/testData/codegen/controlflow/for_loops_array_nullable.kt index 032f54bf312..1c4e9cdf825 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_array_nullable.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_array_nullable.kt @@ -1,16 +1,19 @@ -package codegen.controlflow.for_loops_array_nullable - import kotlin.test.* +val sb = StringBuilder() + private fun nullableArray(a: Array): Array? { return a } -@Test fun nullable() { +fun box(): String { val array = arrayOf(1, 2, 3) nullableArray(array)?.let { for (elem in it) { - print(elem) + sb.append(elem) } } + + assertEquals("123", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_array_nullable.out b/native/native.tests/testData/codegen/controlflow/for_loops_array_nullable.out deleted file mode 100644 index d800886d9c8..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_array_nullable.out +++ /dev/null @@ -1 +0,0 @@ -123 \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_array_side_effects.kt b/native/native.tests/testData/codegen/controlflow/for_loops_array_side_effects.kt index 28222f046e5..339dace4049 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_array_side_effects.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_array_side_effects.kt @@ -1,23 +1,33 @@ -package codegen.controlflow.for_loops_array_side_effects - import kotlin.test.* +val sb = StringBuilder() + private fun sideEffect(array: T): T { - println("side-effect") + sb.appendLine("side-effect") return array } -@Test fun runTest() { +fun box(): String { val intArray = intArrayOf(4, 0, 3, 5) val emptyArray = arrayOf() for (element in sideEffect(intArray)) { - print(element) + sb.append(element.toString()) } - println() + sb.appendLine() for (element in sideEffect(emptyArray)) { - print(element) + sb.append(element.toString()) } - println() + sb.appendLine() + + assertEquals(""" + side-effect + 4035 + side-effect + + + """.trimIndent(), sb.toString()) + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_array_side_effects.out b/native/native.tests/testData/codegen/controlflow/for_loops_array_side_effects.out deleted file mode 100644 index 715b12aaa4c..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_array_side_effects.out +++ /dev/null @@ -1,4 +0,0 @@ -side-effect -4035 -side-effect - diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_call_order.kt b/native/native.tests/testData/codegen/controlflow/for_loops_call_order.kt index 47b1802fdac..5ed80609b0e 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_call_order.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_call_order.kt @@ -3,17 +3,25 @@ * that can be found in the LICENSE file. */ -package codegen.controlflow.for_loops_call_order - import kotlin.test.* -fun f1(): Int { print("1"); return 0 } -fun f2(): Int { print("2"); return 6 } -fun f3(): Int { print("3"); return 2 } -fun f4(): Int { print("4"); return 3 } +val sb = StringBuilder() -@Test fun runTest() { - for (i in f1()..f2() step f3() step f4()) { }; println() - for (i in f1() until f2() step f3() step f4()) {}; println() - for (i in f2() downTo f1() step f3() step f4()) {}; println() +fun f1(): Int { sb.append(1); return 0 } +fun f2(): Int { sb.append(2); return 6 } +fun f3(): Int { sb.append(3); return 2 } +fun f4(): Int { sb.append(4); return 3 } + +fun box(): String { + for (i in f1()..f2() step f3() step f4()) { }; sb.appendLine() + for (i in f1() until f2() step f3() step f4()) {}; sb.appendLine() + for (i in f2() downTo f1() step f3() step f4()) {}; sb.appendLine() + + assertEquals(""" + 1234 + 1234 + 2134 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_call_order.out b/native/native.tests/testData/codegen/controlflow/for_loops_call_order.out deleted file mode 100644 index 3f9e4e21407..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_call_order.out +++ /dev/null @@ -1,3 +0,0 @@ -1234 -1234 -2134 diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_coroutines.kt b/native/native.tests/testData/codegen/controlflow/for_loops_coroutines.kt index d05faedee5b..234f489d404 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_coroutines.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_coroutines.kt @@ -3,19 +3,29 @@ * that can be found in the LICENSE file. */ -package codegen.controlflow.for_loops_coroutines - import kotlin.test.* import kotlin.coroutines.* -@Test fun runTest() { +val sb = StringBuilder() + +fun box(): String { val sq = sequence { for (i in 0..6 step 2) { - print("before: $i ") + sb.append("before: $i ") yield(i) - println("after: $i") + sb.appendLine("after: $i") } } - println("Got: ${sq.joinToString(separator = " ")}") + sb.appendLine("Got: ${sq.joinToString(separator = " ")}") + + assertEquals(""" + before: 0 after: 0 + before: 2 after: 2 + before: 4 after: 4 + before: 6 after: 6 + Got: 0 2 4 6 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_coroutines.out b/native/native.tests/testData/codegen/controlflow/for_loops_coroutines.out deleted file mode 100644 index b4abc699731..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_coroutines.out +++ /dev/null @@ -1,5 +0,0 @@ -before: 0 after: 0 -before: 2 after: 2 -before: 4 after: 4 -before: 6 after: 6 -Got: 0 2 4 6 diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_empty_range.kt b/native/native.tests/testData/codegen/controlflow/for_loops_empty_range.kt index 457c0a2eaf0..fa408030cbd 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_empty_range.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_empty_range.kt @@ -3,23 +3,21 @@ * that can be found in the LICENSE file. */ -package codegen.controlflow.for_loops_empty_range - import kotlin.test.* -@Test fun runTest() { +fun box(): String { // Simple loops - for (i in 4..0) { print(i) } - for (i in 4 until 0) { print(i) } - for (i in 0 downTo 4) { print(i) } + for (i in 4..0) { return "FAIL 11 $i" } + for (i in 4 until 0) { return "FAIL 12 $i" } + for (i in 0 downTo 4) { return "FAIL 13 $i" } // Steps - for (i in 4..0 step 2) { print(i) } - for (i in 4 until 0 step 2) { print(i) } - for (i in 0 downTo 4 step 2) { print(i) } + for (i in 4..0 step 2) { return "FAIL 21 $i" } + for (i in 4 until 0 step 2) { return "FAIL 22 $i" } + for (i in 0 downTo 4 step 2) { return "FAIL 23 $i" } // Two steps - for (i in 6..0 step 2 step 3) { print(i) } - for (i in 6 until 0 step 2 step 3) { print(i) } - for (i in 0 downTo 6 step 2 step 3) { print(i) } + for (i in 6..0 step 2 step 3) { return "FAIL 31 $i" } + for (i in 6 until 0 step 2 step 3) { return "FAIL 32 $i" } + for (i in 0 downTo 6 step 2 step 3) { return "FAIL 33 $i" } - println("OK") + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_empty_range.out b/native/native.tests/testData/codegen/controlflow/for_loops_empty_range.out deleted file mode 100644 index d86bac9de59..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_empty_range.out +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_errors.kt b/native/native.tests/testData/codegen/controlflow/for_loops_errors.kt index e39fc2a2ef5..593deebd9fe 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_errors.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_errors.kt @@ -3,58 +3,56 @@ * that can be found in the LICENSE file. */ -package codegen.controlflow.for_loops_errors - import kotlin.test.* -@Test fun runTest() { +fun box(): String { // Negative step. try { - for (i in 0 .. 4 step -2) print(i); println() + for (i in 0 .. 4 step -2) return "FAIL 1 $i" throw AssertionError() } catch (e: IllegalArgumentException) {} try { - for (i in 0 until 4 step -2) print(i); println() + for (i in 0 until 4 step -2) return "FAIL 2 $i" throw AssertionError() } catch (e: IllegalArgumentException) {} try { - for (i in 4 downTo 0 step -2) print(i); println() + for (i in 4 downTo 0 step -2) return "FAIL 3 $i" throw AssertionError() } catch (e: IllegalArgumentException) {} // Zero step. try { - for (i in 0 .. 4 step 0) print(i); println() + for (i in 0 .. 4 step 0) return "FAIL 4 $i" throw AssertionError() } catch (e: IllegalArgumentException) {} try { - for (i in 0 until 4 step 0) print(i); println() + for (i in 0 until 4 step 0) return "FAIL 5 $i" throw AssertionError() } catch (e: IllegalArgumentException) {} try { - for (i in 4 downTo 0 step 0) print(i); println() + for (i in 4 downTo 0 step 0) return "FAIL 6 $i" throw AssertionError() } catch (e: IllegalArgumentException) {} // Two steps, one is negative. try { - for (i in 0 .. 4 step -2 step 3) print(i); println() + for (i in 0 .. 4 step -2 step 3) return "FAIL 7 $i" throw AssertionError() } catch (e: IllegalArgumentException) {} try { - for (i in 0 until 4 step -2 step 3) print(i); println() + for (i in 0 until 4 step -2 step 3) return "FAIL 8 $i" throw AssertionError() } catch (e: IllegalArgumentException) {} try { - for (i in 4 downTo 0 step -2 step 3) print(i); println() + for (i in 4 downTo 0 step -2 step 3) return "FAIL 9 $i" throw AssertionError() } catch (e: IllegalArgumentException) {} - println("OK") + return "OK" } diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_errors.out b/native/native.tests/testData/codegen/controlflow/for_loops_errors.out deleted file mode 100644 index d86bac9de59..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_errors.out +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_let_with_nullable.kt b/native/native.tests/testData/codegen/controlflow/for_loops_let_with_nullable.kt index 26045afcd48..fa2a8d277b4 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_let_with_nullable.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_let_with_nullable.kt @@ -3,154 +3,186 @@ * that can be found in the LICENSE file. */ -package codegen.controlflow.for_loops_let_with_nullable - import kotlin.test.* +val sb = StringBuilder() + // Github issue #1012 fun testInt(left: Int?, right: Int?, step: Int?) { right?.let { - for (i in 0..it) { print(i) } + for (i in 0..it) { sb.append(i) } } - println() + sb.appendLine() left?.let { - for (i in it..5) { print(i) } + for (i in it..5) { sb.append(i) } } - println() + sb.appendLine() step?.let { - for (i in 0..5 step it) { print(i) } + for (i in 0..5 step it) { sb.append(i) } } - println() + sb.appendLine() right?.let { - for (i in 0 until it) { print(i) } + for (i in 0 until it) { sb.append(i) } } - println() + sb.appendLine() left?.let { - for (i in it until 5) { print(i) } + for (i in it until 5) { sb.append(i) } } - println() + sb.appendLine() step?.let { - for (i in 0 until 5 step it) { print(i) } + for (i in 0 until 5 step it) { sb.append(i) } } - println() + sb.appendLine() right?.let { - for (i in it downTo 0) { print(i) } + for (i in it downTo 0) { sb.append(i) } } - println() + sb.appendLine() left?.let { - for (i in 5 downTo it) { print(i) } + for (i in 5 downTo it) { sb.append(i) } } - println() + sb.appendLine() step?.let { - for (i in 5 downTo 0 step it) { print(i) } + for (i in 5 downTo 0 step it) { sb.append(i) } } - println() + sb.appendLine() } fun testLong(left: Long?, right: Long?, step: Long?) { right?.let { - for (i in 0..it) { print(i) } + for (i in 0..it) { sb.append(i) } } - println() + sb.appendLine() left?.let { - for (i in it..5) { print(i) } + for (i in it..5) { sb.append(i) } } - println() + sb.appendLine() step?.let { - for (i in 0..5L step it) { print(i) } + for (i in 0..5L step it) { sb.append(i) } } - println() + sb.appendLine() right?.let { - for (i in 0 until it) { print(i) } + for (i in 0 until it) { sb.append(i) } } - println() + sb.appendLine() left?.let { - for (i in it until 5) { print(i) } + for (i in it until 5) { sb.append(i) } } - println() + sb.appendLine() step?.let { - for (i in 0 until 5L step it) { print(i) } + for (i in 0 until 5L step it) { sb.append(i) } } - println() + sb.appendLine() right?.let { - for (i in it downTo 0) { print(i) } + for (i in it downTo 0) { sb.append(i) } } - println() + sb.appendLine() left?.let { - for (i in 5 downTo it) { print(i) } + for (i in 5 downTo it) { sb.append(i) } } - println() + sb.appendLine() step?.let { - for (i in 5 downTo 0L step it) { print(i) } + for (i in 5 downTo 0L step it) { sb.append(i) } } - println() + sb.appendLine() } fun testChar(left: Char?, right: Char?, step: Int?) { right?.let { - for (i in 'a'..it) { print(i) } + for (i in 'a'..it) { sb.append(i) } } - println() + sb.appendLine() left?.let { - for (i in it..'f') { print(i) } + for (i in it..'f') { sb.append(i) } } - println() + sb.appendLine() step?.let { - for (i in 'a'..'f' step it) { print(i) } + for (i in 'a'..'f' step it) { sb.append(i) } } - println() + sb.appendLine() right?.let { - for (i in 'a' until it) { print(i) } + for (i in 'a' until it) { sb.append(i) } } - println() + sb.appendLine() left?.let { - for (i in it until 'f') { print(i) } + for (i in it until 'f') { sb.append(i) } } - println() + sb.appendLine() step?.let { - for (i in 'a' until 'f' step it) { print(i) } + for (i in 'a' until 'f' step it) { sb.append(i) } } - println() + sb.appendLine() right?.let { - for (i in it downTo 'a') { print(i) } + for (i in it downTo 'a') { sb.append(i) } } - println() + sb.appendLine() left?.let { - for (i in 'f' downTo it) { print(i) } + for (i in 'f' downTo it) { sb.append(i) } } - println() + sb.appendLine() step?.let { - for (i in 'f' downTo 'a' step it) { print(i) } + for (i in 'f' downTo 'a' step it) { sb.append(i) } } - println() + sb.appendLine() } -@Test fun runTest() { +fun box(): String { testInt(0, 5, 2) testLong(0, 5, 2) testChar('a', 'f', 2) + + assertEquals(""" + 012345 + 012345 + 024 + 01234 + 01234 + 024 + 543210 + 543210 + 531 + 012345 + 012345 + 024 + 01234 + 01234 + 024 + 543210 + 543210 + 531 + abcdef + abcdef + ace + abcde + abcde + ace + fedcba + fedcba + fdb + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_let_with_nullable.out b/native/native.tests/testData/codegen/controlflow/for_loops_let_with_nullable.out deleted file mode 100644 index 232bc84ace1..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_let_with_nullable.out +++ /dev/null @@ -1,27 +0,0 @@ -012345 -012345 -024 -01234 -01234 -024 -543210 -543210 -531 -012345 -012345 -024 -01234 -01234 -024 -543210 -543210 -531 -abcdef -abcdef -ace -abcde -abcde -ace -fedcba -fedcba -fdb diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_nested.kt b/native/native.tests/testData/codegen/controlflow/for_loops_nested.kt index 1c7deacfd00..6f59e576ce6 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_nested.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_nested.kt @@ -3,66 +3,78 @@ * that can be found in the LICENSE file. */ -package codegen.controlflow.for_loops_nested - import kotlin.test.* -@Test fun runTest() { +val sb = StringBuilder() + +fun box(): String { // Simple for (i in 0..2) { for (j in 0..2) { - print("$i$j ") + sb.append("$i$j ") } } - println() + sb.appendLine() // Break l1@for (i in 0..2) { l2@for (j in 0..2) { - print("$i$j ") + sb.append("$i$j ") if (j == 1) break } } - println() + sb.appendLine() l1@for (i in 0..2) { l2@for (j in 0..2) { - print("$i$j ") + sb.append("$i$j ") if (j == 1) break@l2 } } - println() + sb.appendLine() l1@for (i in 0..2) { l2@for (j in 0..2) { - print("$i$j ") + sb.append("$i$j ") if (j == 1) break@l1 } } - println() + sb.appendLine() // Continue l1@for (i in 0..2) { l2@for (j in 0..2) { if (j == 1) continue - print("$i$j ") + sb.append("$i$j ") } } - println() + sb.appendLine() l1@for (i in 0..2) { l2@for (j in 0..2) { if (j == 1) continue@l2 - print("$i$j ") + sb.append("$i$j ") } } - println() + sb.appendLine() l1@for (i in 0..2) { l2@for (j in 0..2) { if (j == 1) continue@l1 - print("$i$j ") + sb.append("$i$j ") } } - println() + sb.appendLine() + + assertEquals(""" + 00 01 02 10 11 12 20 21 22 + 00 01 10 11 20 21 + 00 01 10 11 20 21 + 00 01 + 00 02 10 12 20 22 + 00 02 10 12 20 22 + 00 10 20 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_nested.out b/native/native.tests/testData/codegen/controlflow/for_loops_nested.out deleted file mode 100644 index 9d213d78e37..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_nested.out +++ /dev/null @@ -1,7 +0,0 @@ -00 01 02 10 11 12 20 21 22 -00 01 10 11 20 21 -00 01 10 11 20 21 -00 01 -00 02 10 12 20 22 -00 02 10 12 20 22 -00 10 20 diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_overflow.kt b/native/native.tests/testData/codegen/controlflow/for_loops_overflow.kt index a6c89058e12..bf3fa2c8347 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_overflow.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_overflow.kt @@ -3,29 +3,38 @@ * that can be found in the LICENSE file. */ -package codegen.controlflow.for_loops_overflow - import kotlin.test.* -@Test fun runTest() { - for (i in Int.MAX_VALUE - 1 .. Int.MAX_VALUE) { print(i); print(' ') }; println() - for (i in Int.MAX_VALUE - 1 until Int.MAX_VALUE) { print(i); print(' ') }; println() - for (i in Int.MIN_VALUE + 1 downTo Int.MIN_VALUE) { print(i); print(' ') }; println() +val sb = StringBuilder() + +fun box(): String { + for (i in Int.MAX_VALUE - 1 .. Int.MAX_VALUE) { sb.append(i); sb.append(' ') }; sb.appendLine() + for (i in Int.MAX_VALUE - 1 until Int.MAX_VALUE) { sb.append(i); sb.append(' ') }; sb.appendLine() + for (i in Int.MIN_VALUE + 1 downTo Int.MIN_VALUE) { sb.append(i); sb.append(' ') }; sb.appendLine() // Empty loops - for (i in Byte.MIN_VALUE until Byte.MIN_VALUE) { print(i); print(' ') } - for (i in Short.MIN_VALUE until Short.MIN_VALUE) { print(i); print(' ') } - for (i in Int.MIN_VALUE until Int.MIN_VALUE) { print(i); print(' ') } - for (i in Long.MIN_VALUE until Long.MIN_VALUE) { print(i); print(' ') } - for (i in 0.toChar() until 0.toChar()) { print(i); print(' ') } + for (i in Byte.MIN_VALUE until Byte.MIN_VALUE) { sb.append(i); sb.append(' ') } + for (i in Short.MIN_VALUE until Short.MIN_VALUE) { sb.append(i); sb.append(' ') } + for (i in Int.MIN_VALUE until Int.MIN_VALUE) { sb.append(i); sb.append(' ') } + for (i in Long.MIN_VALUE until Long.MIN_VALUE) { sb.append(i); sb.append(' ') } + for (i in 0.toChar() until 0.toChar()) { sb.append(i); sb.append(' ') } - for (i in 0 until Byte.MIN_VALUE) { print(i); print(' ') } - for (i in 0 until Short.MIN_VALUE) { print(i); print(' ') } - for (i in 0 until Int.MIN_VALUE) { print(i); print(' ') } - for (i in 0 until Long.MIN_VALUE) { print(i); print(' ') } - for (i in 'a' until 0.toChar()) { print(i); print(' ') } + for (i in 0 until Byte.MIN_VALUE) { sb.append(i); sb.append(' ') } + for (i in 0 until Short.MIN_VALUE) { sb.append(i); sb.append(' ') } + for (i in 0 until Int.MIN_VALUE) { sb.append(i); sb.append(' ') } + for (i in 0 until Long.MIN_VALUE) { sb.append(i); sb.append(' ') } + for (i in 'a' until 0.toChar()) { sb.append(i); sb.append(' ') } val M = Int.MAX_VALUE / 2 - for (i in M + 4..M + 10 step M) { print(i); print(' ') }; println() + for (i in M + 4..M + 10 step M) { sb.append(i); sb.append(' ') }; sb.appendLine() + + assertEquals(""" + 2147483646 2147483647 + 2147483646 + -2147483647 -2147483648 + 1073741827 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_overflow.out b/native/native.tests/testData/codegen/controlflow/for_loops_overflow.out deleted file mode 100644 index 2d5fd1ab349..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_overflow.out +++ /dev/null @@ -1,4 +0,0 @@ -2147483646 2147483647 -2147483646 --2147483647 -2147483648 -1073741827 diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_types.kt b/native/native.tests/testData/codegen/controlflow/for_loops_types.kt index 0e7fbafe362..c8fbd432ebc 100644 --- a/native/native.tests/testData/codegen/controlflow/for_loops_types.kt +++ b/native/native.tests/testData/codegen/controlflow/for_loops_types.kt @@ -3,112 +3,219 @@ * that can be found in the LICENSE file. */ -package codegen.controlflow.for_loops_types - import kotlin.test.* -@Test fun runTest() { - for (i in 0.toByte() .. 4.toByte()) print(i); println() - for (i in 0.toByte() .. 4.toShort()) print(i); println() - for (i in 0.toByte() .. 4.toInt()) print(i); println() - for (i in 0.toByte() .. 4.toLong()) print(i); println() - for (i in 0.toShort() .. 4.toByte()) print(i); println() - for (i in 0.toShort() .. 4.toShort()) print(i); println() - for (i in 0.toShort() .. 4.toInt()) print(i); println() - for (i in 0.toShort() .. 4.toLong()) print(i); println() - for (i in 0.toInt() .. 4.toByte()) print(i); println() - for (i in 0.toInt() .. 4.toShort()) print(i); println() - for (i in 0.toInt() .. 4.toInt()) print(i); println() - for (i in 0.toInt() .. 4.toLong()) print(i); println() - for (i in 0.toLong() .. 4.toByte()) print(i); println() - for (i in 0.toLong() .. 4.toShort()) print(i); println() - for (i in 0.toLong() .. 4.toInt()) print(i); println() - for (i in 0.toLong() .. 4.toLong()) print(i); println() - for (i in 0.toByte() until 4.toByte()) print(i); println() - for (i in 0.toByte() until 4.toShort()) print(i); println() - for (i in 0.toByte() until 4.toInt()) print(i); println() - for (i in 0.toByte() until 4.toLong()) print(i); println() - for (i in 0.toShort() until 4.toByte()) print(i); println() - for (i in 0.toShort() until 4.toShort()) print(i); println() - for (i in 0.toShort() until 4.toInt()) print(i); println() - for (i in 0.toShort() until 4.toLong()) print(i); println() - for (i in 0.toInt() until 4.toByte()) print(i); println() - for (i in 0.toInt() until 4.toShort()) print(i); println() - for (i in 0.toInt() until 4.toInt()) print(i); println() - for (i in 0.toInt() until 4.toLong()) print(i); println() - for (i in 0.toLong() until 4.toByte()) print(i); println() - for (i in 0.toLong() until 4.toShort()) print(i); println() - for (i in 0.toLong() until 4.toInt()) print(i); println() - for (i in 0.toLong() until 4.toLong()) print(i); println() - for (i in 4.toByte() downTo 0.toByte()) print(i); println() - for (i in 4.toByte() downTo 0.toShort()) print(i); println() - for (i in 4.toByte() downTo 0.toInt()) print(i); println() - for (i in 4.toByte() downTo 0.toLong()) print(i); println() - for (i in 4.toShort() downTo 0.toByte()) print(i); println() - for (i in 4.toShort() downTo 0.toShort()) print(i); println() - for (i in 4.toShort() downTo 0.toInt()) print(i); println() - for (i in 4.toShort() downTo 0.toLong()) print(i); println() - for (i in 4.toInt() downTo 0.toByte()) print(i); println() - for (i in 4.toInt() downTo 0.toShort()) print(i); println() - for (i in 4.toInt() downTo 0.toInt()) print(i); println() - for (i in 4.toInt() downTo 0.toLong()) print(i); println() - for (i in 4.toLong() downTo 0.toByte()) print(i); println() - for (i in 4.toLong() downTo 0.toShort()) print(i); println() - for (i in 4.toLong() downTo 0.toInt()) print(i); println() - for (i in 4.toLong() downTo 0.toLong()) print(i); println() - for (i in 'a' .. 'd') print(i); println() - for (i in 'a' until 'd') print(i); println() - for (i in 'd' downTo 'a') print(i); println() +val sb = StringBuilder() - for (i in 0.toByte() .. 4.toByte() step 2) print(i); println() - for (i in 0.toByte() .. 4.toShort() step 2) print(i); println() - for (i in 0.toByte() .. 4.toInt() step 2) print(i); println() - for (i in 0.toByte() .. 4.toLong() step 2L) print(i); println() - for (i in 0.toShort() .. 4.toByte() step 2) print(i); println() - for (i in 0.toShort() .. 4.toShort() step 2) print(i); println() - for (i in 0.toShort() .. 4.toInt() step 2) print(i); println() - for (i in 0.toShort() .. 4.toLong() step 2L) print(i); println() - for (i in 0.toInt() .. 4.toByte() step 2) print(i); println() - for (i in 0.toInt() .. 4.toShort() step 2) print(i); println() - for (i in 0.toInt() .. 4.toInt() step 2) print(i); println() - for (i in 0.toInt() .. 4.toLong() step 2L) print(i); println() - for (i in 0.toLong() .. 4.toByte() step 2L) print(i); println() - for (i in 0.toLong() .. 4.toShort() step 2L) print(i); println() - for (i in 0.toLong() .. 4.toInt() step 2L) print(i); println() - for (i in 0.toLong() .. 4.toLong() step 2L) print(i); println() - for (i in 0.toByte() until 4.toByte() step 2) print(i); println() - for (i in 0.toByte() until 4.toShort() step 2) print(i); println() - for (i in 0.toByte() until 4.toInt() step 2) print(i); println() - for (i in 0.toByte() until 4.toLong() step 2L) print(i); println() - for (i in 0.toShort() until 4.toByte() step 2) print(i); println() - for (i in 0.toShort() until 4.toShort() step 2) print(i); println() - for (i in 0.toShort() until 4.toInt() step 2) print(i); println() - for (i in 0.toShort() until 4.toLong() step 2L) print(i); println() - for (i in 0.toInt() until 4.toByte() step 2) print(i); println() - for (i in 0.toInt() until 4.toShort() step 2) print(i); println() - for (i in 0.toInt() until 4.toInt() step 2) print(i); println() - for (i in 0.toInt() until 4.toLong() step 2L) print(i); println() - for (i in 0.toLong() until 4.toByte() step 2L) print(i); println() - for (i in 0.toLong() until 4.toShort() step 2L) print(i); println() - for (i in 0.toLong() until 4.toInt() step 2L) print(i); println() - for (i in 0.toLong() until 4.toLong() step 2L) print(i); println() - for (i in 4.toByte() downTo 0.toByte() step 2) print(i); println() - for (i in 4.toByte() downTo 0.toShort() step 2) print(i); println() - for (i in 4.toByte() downTo 0.toInt() step 2) print(i); println() - for (i in 4.toByte() downTo 0.toLong() step 2L) print(i); println() - for (i in 4.toShort() downTo 0.toByte() step 2) print(i); println() - for (i in 4.toShort() downTo 0.toShort() step 2) print(i); println() - for (i in 4.toShort() downTo 0.toInt() step 2) print(i); println() - for (i in 4.toShort() downTo 0.toLong() step 2L) print(i); println() - for (i in 4.toInt() downTo 0.toByte() step 2) print(i); println() - for (i in 4.toInt() downTo 0.toShort() step 2) print(i); println() - for (i in 4.toInt() downTo 0.toInt() step 2) print(i); println() - for (i in 4.toInt() downTo 0.toLong() step 2L) print(i); println() - for (i in 4.toLong() downTo 0.toByte() step 2L) print(i); println() - for (i in 4.toLong() downTo 0.toShort() step 2L) print(i); println() - for (i in 4.toLong() downTo 0.toInt() step 2L) print(i); println() - for (i in 4.toLong() downTo 0.toLong() step 2L) print(i); println() - for (i in 'a' .. 'd' step 2) print(i); println() - for (i in 'a' until 'd' step 2) print(i); println() - for (i in 'd' downTo 'a' step 2) print(i); println() +fun box(): String { + for (i in 0.toByte() .. 4.toByte()) sb.append(i); sb.appendLine() + for (i in 0.toByte() .. 4.toShort()) sb.append(i); sb.appendLine() + for (i in 0.toByte() .. 4.toInt()) sb.append(i); sb.appendLine() + for (i in 0.toByte() .. 4.toLong()) sb.append(i); sb.appendLine() + for (i in 0.toShort() .. 4.toByte()) sb.append(i); sb.appendLine() + for (i in 0.toShort() .. 4.toShort()) sb.append(i); sb.appendLine() + for (i in 0.toShort() .. 4.toInt()) sb.append(i); sb.appendLine() + for (i in 0.toShort() .. 4.toLong()) sb.append(i); sb.appendLine() + for (i in 0.toInt() .. 4.toByte()) sb.append(i); sb.appendLine() + for (i in 0.toInt() .. 4.toShort()) sb.append(i); sb.appendLine() + for (i in 0.toInt() .. 4.toInt()) sb.append(i); sb.appendLine() + for (i in 0.toInt() .. 4.toLong()) sb.append(i); sb.appendLine() + for (i in 0.toLong() .. 4.toByte()) sb.append(i); sb.appendLine() + for (i in 0.toLong() .. 4.toShort()) sb.append(i); sb.appendLine() + for (i in 0.toLong() .. 4.toInt()) sb.append(i); sb.appendLine() + for (i in 0.toLong() .. 4.toLong()) sb.append(i); sb.appendLine() + for (i in 0.toByte() until 4.toByte()) sb.append(i); sb.appendLine() + for (i in 0.toByte() until 4.toShort()) sb.append(i); sb.appendLine() + for (i in 0.toByte() until 4.toInt()) sb.append(i); sb.appendLine() + for (i in 0.toByte() until 4.toLong()) sb.append(i); sb.appendLine() + for (i in 0.toShort() until 4.toByte()) sb.append(i); sb.appendLine() + for (i in 0.toShort() until 4.toShort()) sb.append(i); sb.appendLine() + for (i in 0.toShort() until 4.toInt()) sb.append(i); sb.appendLine() + for (i in 0.toShort() until 4.toLong()) sb.append(i); sb.appendLine() + for (i in 0.toInt() until 4.toByte()) sb.append(i); sb.appendLine() + for (i in 0.toInt() until 4.toShort()) sb.append(i); sb.appendLine() + for (i in 0.toInt() until 4.toInt()) sb.append(i); sb.appendLine() + for (i in 0.toInt() until 4.toLong()) sb.append(i); sb.appendLine() + for (i in 0.toLong() until 4.toByte()) sb.append(i); sb.appendLine() + for (i in 0.toLong() until 4.toShort()) sb.append(i); sb.appendLine() + for (i in 0.toLong() until 4.toInt()) sb.append(i); sb.appendLine() + for (i in 0.toLong() until 4.toLong()) sb.append(i); sb.appendLine() + for (i in 4.toByte() downTo 0.toByte()) sb.append(i); sb.appendLine() + for (i in 4.toByte() downTo 0.toShort()) sb.append(i); sb.appendLine() + for (i in 4.toByte() downTo 0.toInt()) sb.append(i); sb.appendLine() + for (i in 4.toByte() downTo 0.toLong()) sb.append(i); sb.appendLine() + for (i in 4.toShort() downTo 0.toByte()) sb.append(i); sb.appendLine() + for (i in 4.toShort() downTo 0.toShort()) sb.append(i); sb.appendLine() + for (i in 4.toShort() downTo 0.toInt()) sb.append(i); sb.appendLine() + for (i in 4.toShort() downTo 0.toLong()) sb.append(i); sb.appendLine() + for (i in 4.toInt() downTo 0.toByte()) sb.append(i); sb.appendLine() + for (i in 4.toInt() downTo 0.toShort()) sb.append(i); sb.appendLine() + for (i in 4.toInt() downTo 0.toInt()) sb.append(i); sb.appendLine() + for (i in 4.toInt() downTo 0.toLong()) sb.append(i); sb.appendLine() + for (i in 4.toLong() downTo 0.toByte()) sb.append(i); sb.appendLine() + for (i in 4.toLong() downTo 0.toShort()) sb.append(i); sb.appendLine() + for (i in 4.toLong() downTo 0.toInt()) sb.append(i); sb.appendLine() + for (i in 4.toLong() downTo 0.toLong()) sb.append(i); sb.appendLine() + for (i in 'a' .. 'd') sb.append(i); sb.appendLine() + for (i in 'a' until 'd') sb.append(i); sb.appendLine() + for (i in 'd' downTo 'a') sb.append(i); sb.appendLine() + + for (i in 0.toByte() .. 4.toByte() step 2) sb.append(i); sb.appendLine() + for (i in 0.toByte() .. 4.toShort() step 2) sb.append(i); sb.appendLine() + for (i in 0.toByte() .. 4.toInt() step 2) sb.append(i); sb.appendLine() + for (i in 0.toByte() .. 4.toLong() step 2L) sb.append(i); sb.appendLine() + for (i in 0.toShort() .. 4.toByte() step 2) sb.append(i); sb.appendLine() + for (i in 0.toShort() .. 4.toShort() step 2) sb.append(i); sb.appendLine() + for (i in 0.toShort() .. 4.toInt() step 2) sb.append(i); sb.appendLine() + for (i in 0.toShort() .. 4.toLong() step 2L) sb.append(i); sb.appendLine() + for (i in 0.toInt() .. 4.toByte() step 2) sb.append(i); sb.appendLine() + for (i in 0.toInt() .. 4.toShort() step 2) sb.append(i); sb.appendLine() + for (i in 0.toInt() .. 4.toInt() step 2) sb.append(i); sb.appendLine() + for (i in 0.toInt() .. 4.toLong() step 2L) sb.append(i); sb.appendLine() + for (i in 0.toLong() .. 4.toByte() step 2L) sb.append(i); sb.appendLine() + for (i in 0.toLong() .. 4.toShort() step 2L) sb.append(i); sb.appendLine() + for (i in 0.toLong() .. 4.toInt() step 2L) sb.append(i); sb.appendLine() + for (i in 0.toLong() .. 4.toLong() step 2L) sb.append(i); sb.appendLine() + for (i in 0.toByte() until 4.toByte() step 2) sb.append(i); sb.appendLine() + for (i in 0.toByte() until 4.toShort() step 2) sb.append(i); sb.appendLine() + for (i in 0.toByte() until 4.toInt() step 2) sb.append(i); sb.appendLine() + for (i in 0.toByte() until 4.toLong() step 2L) sb.append(i); sb.appendLine() + for (i in 0.toShort() until 4.toByte() step 2) sb.append(i); sb.appendLine() + for (i in 0.toShort() until 4.toShort() step 2) sb.append(i); sb.appendLine() + for (i in 0.toShort() until 4.toInt() step 2) sb.append(i); sb.appendLine() + for (i in 0.toShort() until 4.toLong() step 2L) sb.append(i); sb.appendLine() + for (i in 0.toInt() until 4.toByte() step 2) sb.append(i); sb.appendLine() + for (i in 0.toInt() until 4.toShort() step 2) sb.append(i); sb.appendLine() + for (i in 0.toInt() until 4.toInt() step 2) sb.append(i); sb.appendLine() + for (i in 0.toInt() until 4.toLong() step 2L) sb.append(i); sb.appendLine() + for (i in 0.toLong() until 4.toByte() step 2L) sb.append(i); sb.appendLine() + for (i in 0.toLong() until 4.toShort() step 2L) sb.append(i); sb.appendLine() + for (i in 0.toLong() until 4.toInt() step 2L) sb.append(i); sb.appendLine() + for (i in 0.toLong() until 4.toLong() step 2L) sb.append(i); sb.appendLine() + for (i in 4.toByte() downTo 0.toByte() step 2) sb.append(i); sb.appendLine() + for (i in 4.toByte() downTo 0.toShort() step 2) sb.append(i); sb.appendLine() + for (i in 4.toByte() downTo 0.toInt() step 2) sb.append(i); sb.appendLine() + for (i in 4.toByte() downTo 0.toLong() step 2L) sb.append(i); sb.appendLine() + for (i in 4.toShort() downTo 0.toByte() step 2) sb.append(i); sb.appendLine() + for (i in 4.toShort() downTo 0.toShort() step 2) sb.append(i); sb.appendLine() + for (i in 4.toShort() downTo 0.toInt() step 2) sb.append(i); sb.appendLine() + for (i in 4.toShort() downTo 0.toLong() step 2L) sb.append(i); sb.appendLine() + for (i in 4.toInt() downTo 0.toByte() step 2) sb.append(i); sb.appendLine() + for (i in 4.toInt() downTo 0.toShort() step 2) sb.append(i); sb.appendLine() + for (i in 4.toInt() downTo 0.toInt() step 2) sb.append(i); sb.appendLine() + for (i in 4.toInt() downTo 0.toLong() step 2L) sb.append(i); sb.appendLine() + for (i in 4.toLong() downTo 0.toByte() step 2L) sb.append(i); sb.appendLine() + for (i in 4.toLong() downTo 0.toShort() step 2L) sb.append(i); sb.appendLine() + for (i in 4.toLong() downTo 0.toInt() step 2L) sb.append(i); sb.appendLine() + for (i in 4.toLong() downTo 0.toLong() step 2L) sb.append(i); sb.appendLine() + for (i in 'a' .. 'd' step 2) sb.append(i); sb.appendLine() + for (i in 'a' until 'd' step 2) sb.append(i); sb.appendLine() + for (i in 'd' downTo 'a' step 2) sb.append(i); sb.appendLine() + + assertEquals(""" + 01234 + 01234 + 01234 + 01234 + 01234 + 01234 + 01234 + 01234 + 01234 + 01234 + 01234 + 01234 + 01234 + 01234 + 01234 + 01234 + 0123 + 0123 + 0123 + 0123 + 0123 + 0123 + 0123 + 0123 + 0123 + 0123 + 0123 + 0123 + 0123 + 0123 + 0123 + 0123 + 43210 + 43210 + 43210 + 43210 + 43210 + 43210 + 43210 + 43210 + 43210 + 43210 + 43210 + 43210 + 43210 + 43210 + 43210 + 43210 + abcd + abc + dcba + 024 + 024 + 024 + 024 + 024 + 024 + 024 + 024 + 024 + 024 + 024 + 024 + 024 + 024 + 024 + 024 + 02 + 02 + 02 + 02 + 02 + 02 + 02 + 02 + 02 + 02 + 02 + 02 + 02 + 02 + 02 + 02 + 420 + 420 + 420 + 420 + 420 + 420 + 420 + 420 + 420 + 420 + 420 + 420 + 420 + 420 + 420 + 420 + ac + ac + db + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/for_loops_types.out b/native/native.tests/testData/codegen/controlflow/for_loops_types.out deleted file mode 100644 index ef2c62e6237..00000000000 --- a/native/native.tests/testData/codegen/controlflow/for_loops_types.out +++ /dev/null @@ -1,102 +0,0 @@ -01234 -01234 -01234 -01234 -01234 -01234 -01234 -01234 -01234 -01234 -01234 -01234 -01234 -01234 -01234 -01234 -0123 -0123 -0123 -0123 -0123 -0123 -0123 -0123 -0123 -0123 -0123 -0123 -0123 -0123 -0123 -0123 -43210 -43210 -43210 -43210 -43210 -43210 -43210 -43210 -43210 -43210 -43210 -43210 -43210 -43210 -43210 -43210 -abcd -abc -dcba -024 -024 -024 -024 -024 -024 -024 -024 -024 -024 -024 -024 -024 -024 -024 -024 -02 -02 -02 -02 -02 -02 -02 -02 -02 -02 -02 -02 -02 -02 -02 -02 -420 -420 -420 -420 -420 -420 -420 -420 -420 -420 -420 -420 -420 -420 -420 -420 -ac -ac -db diff --git a/native/native.tests/testData/codegen/controlflow/unreachable1.kt b/native/native.tests/testData/codegen/controlflow/unreachable1.kt index 05fcfa06a13..feed37d4c95 100644 --- a/native/native.tests/testData/codegen/controlflow/unreachable1.kt +++ b/native/native.tests/testData/codegen/controlflow/unreachable1.kt @@ -3,15 +3,18 @@ * that can be found in the LICENSE file. */ -package codegen.controlflow.unreachable1 - import kotlin.test.* -@Test fun runTest() { - println(foo()) +val sb = StringBuilder() + +fun box(): String { + sb.append(foo()) + + assertEquals("1", sb.toString()) + return "OK" } fun foo(): Int { return 1 - println("After return") + sb.appendLine("After return") } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/controlflow/unreachable1.out b/native/native.tests/testData/codegen/controlflow/unreachable1.out deleted file mode 100644 index d00491fd7e5..00000000000 --- a/native/native.tests/testData/codegen/controlflow/unreachable1.out +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/native/native.tests/testData/codegen/coroutines/anonymousObject.kt b/native/native.tests/testData/codegen/coroutines/anonymousObject.kt index 172580524b1..c8998ea9014 100644 --- a/native/native.tests/testData/codegen/coroutines/anonymousObject.kt +++ b/native/native.tests/testData/codegen/coroutines/anonymousObject.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.anonymousObject - import kotlin.test.* import kotlin.coroutines.* @@ -41,10 +39,14 @@ fun create() = object: I { } } -@Test fun runTest() { +fun box(): String { + val sb = StringBuilder() + builder { val z = create() - z.foo { suspendHere(); println(it) } + z.foo { suspendHere(); sb.append(it) } z.bar("zzz") } + assertEquals("zzz", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/anonymousObject.out b/native/native.tests/testData/codegen/coroutines/anonymousObject.out deleted file mode 100644 index b1a17ba1369..00000000000 --- a/native/native.tests/testData/codegen/coroutines/anonymousObject.out +++ /dev/null @@ -1 +0,0 @@ -zzz diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_chain.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_chain.kt index 4b14bdf5681..4bd90b61c2c 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_chain.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_chain.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_chain - import kotlin.test.* import kotlin.coroutines.* @@ -25,13 +23,14 @@ fun builder(c: suspend () -> Unit) { } // See https://github.com/JetBrains/kotlin-native/issues/3476 -@Test fun runTest() { +fun box(): String { var result = 0 builder { foo().bar() result = 1 } assertEquals(1, result) + return "OK" } class Foo { diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_finally1.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_finally1.kt index 2f3e47dd8ca..ffded84c4be 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_finally1.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_finally1.kt @@ -3,36 +3,36 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_finally1 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -53,5 +53,12 @@ fun builder(c: suspend () -> Unit) { } } - println(result) + sb.appendLine(result) + assertEquals(""" + f1 + s1 + 117 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_finally1.out b/native/native.tests/testData/codegen/coroutines/controlFlow_finally1.out deleted file mode 100644 index 7dd6de5b410..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_finally1.out +++ /dev/null @@ -1,3 +0,0 @@ -f1 -s1 -117 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_finally2.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_finally2.kt index 3aa49853d04..d60c5e93403 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_finally2.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_finally2.kt @@ -3,36 +3,36 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_finally2 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -54,5 +54,14 @@ fun builder(c: suspend () -> Unit) { result = x } - println(result) + sb.appendLine(result) + + assertEquals(""" + f1 + s1 + 117 + + """.trimIndent(), sb.toString()) + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_finally2.out b/native/native.tests/testData/codegen/coroutines/controlFlow_finally2.out deleted file mode 100644 index 7dd6de5b410..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_finally2.out +++ /dev/null @@ -1,3 +0,0 @@ -f1 -s1 -117 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_finally3.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_finally3.kt index d5104bd45b7..e408f296843 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_finally3.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_finally3.kt @@ -3,36 +3,36 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_finally3 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -53,5 +53,14 @@ fun builder(c: suspend () -> Unit) { } } - println(result) + sb.appendLine(result) + + assertEquals(""" + f1 + s1 + 117 + + """.trimIndent(), sb.toString()) + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_finally3.out b/native/native.tests/testData/codegen/coroutines/controlFlow_finally3.out deleted file mode 100644 index 7dd6de5b410..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_finally3.out +++ /dev/null @@ -1,3 +0,0 @@ -f1 -s1 -117 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_finally4.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_finally4.kt index c46d87a62d9..90b5aeda5cc 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_finally4.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_finally4.kt @@ -3,36 +3,36 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_finally4 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -49,9 +49,18 @@ fun builder(c: suspend () -> Unit) { } catch (t: Throwable) { result = f2() } finally { - println("finally") + sb.appendLine("finally") } } - println(result) + sb.appendLine(result) + + assertEquals(""" + s1 + finally + 42 + + """.trimIndent(), sb.toString()) + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_finally4.out b/native/native.tests/testData/codegen/coroutines/controlFlow_finally4.out deleted file mode 100644 index 88f401cf394..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_finally4.out +++ /dev/null @@ -1,3 +0,0 @@ -s1 -finally -42 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_finally5.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_finally5.kt index 3ff1aabc669..3f039b978af 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_finally5.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_finally5.kt @@ -3,36 +3,36 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_finally5 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resumeWithException(Error()) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -49,9 +49,19 @@ fun builder(c: suspend () -> Unit) { } catch (t: Throwable) { result = f2() } finally { - println("finally") + sb.appendLine("finally") } } - println(result) + sb.appendLine(result) + + assertEquals(""" + s1 + f2 + finally + 1 + + """.trimIndent(), sb.toString()) + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_finally5.out b/native/native.tests/testData/codegen/coroutines/controlFlow_finally5.out deleted file mode 100644 index 42ed6256650..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_finally5.out +++ /dev/null @@ -1,4 +0,0 @@ -s1 -f2 -finally -1 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_finally6.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_finally6.kt index 98a26d33baf..092429ccaed 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_finally6.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_finally6.kt @@ -3,36 +3,36 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_finally6 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resumeWithException(Error("error")) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -50,13 +50,23 @@ fun builder(c: suspend () -> Unit) { } catch (t: ClassCastException) { result = f2() } finally { - println("finally") + sb.appendLine("finally") } } catch(t: Error) { - println(t.message) + sb.appendLine(t.message) } } - println(result) + sb.appendLine(result) + + assertEquals(""" + s1 + finally + error + 0 + + """.trimIndent(), sb.toString()) + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_finally6.out b/native/native.tests/testData/codegen/coroutines/controlFlow_finally6.out deleted file mode 100644 index c7aa0114a50..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_finally6.out +++ /dev/null @@ -1,4 +0,0 @@ -s1 -finally -error -0 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_finally7.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_finally7.kt index a3fc579569e..3010d7cec46 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_finally7.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_finally7.kt @@ -3,42 +3,42 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_finally7 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resumeWithException(Error()) COROUTINE_SUSPENDED } suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s2") + sb.appendLine("s2") x.resume(42) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -46,7 +46,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -56,13 +56,25 @@ fun builder(c: suspend () -> Unit) { } catch (t: Throwable) { result = f2() } finally { - println("finally1") + sb.appendLine("finally1") result = s2() } } finally { - println("finally2") + sb.appendLine("finally2") } } - println(result) + sb.appendLine(result) + + assertEquals(""" + s1 + f2 + finally1 + s2 + finally2 + 42 + + """.trimIndent(), sb.toString()) + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_finally7.out b/native/native.tests/testData/codegen/coroutines/controlFlow_finally7.out deleted file mode 100644 index cee098de202..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_finally7.out +++ /dev/null @@ -1,6 +0,0 @@ -s1 -f2 -finally1 -s2 -finally2 -42 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_if1.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_if1.kt index 21976de2248..ab374a03a15 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_if1.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_if1.kt @@ -3,36 +3,36 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_if1 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -40,12 +40,22 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { result = f3(if (f1() > 100) s1() else f2(), 42) } - println(result) + sb.appendLine(result) + + assertEquals(""" + f1 + s1 + f3 + 84 + + """.trimIndent(), sb.toString()) + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_if1.out b/native/native.tests/testData/codegen/coroutines/controlFlow_if1.out deleted file mode 100644 index 29b24620084..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_if1.out +++ /dev/null @@ -1,4 +0,0 @@ -f1 -s1 -f3 -84 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_if2.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_if2.kt index b1b7f643037..89f57e9a2b2 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_if2.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_if2.kt @@ -3,36 +3,36 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_if2 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -50,5 +50,15 @@ fun builder(c: suspend () -> Unit) { result = 42 } - println(result) + sb.appendLine(result) + + assertEquals(""" + f1 + s1 + f2 + 43 + + """.trimIndent(), sb.toString()) + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_if2.out b/native/native.tests/testData/codegen/coroutines/controlFlow_if2.out deleted file mode 100644 index 6afbb351959..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_if2.out +++ /dev/null @@ -1,4 +0,0 @@ -f1 -s1 -f2 -43 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_inline1.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_inline1.kt index 5703c9c7e7d..18ab2794a80 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_inline1.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_inline1.kt @@ -3,20 +3,20 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_inline1 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } @@ -29,12 +29,15 @@ inline suspend fun inline_s2(): Int { return 42 } -@Test fun runTest() { +fun box(): String { var result = 0 builder { result = inline_s2() } - println(result) + sb.appendLine(result) + + assertEquals("42\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_inline1.out b/native/native.tests/testData/codegen/coroutines/controlFlow_inline1.out deleted file mode 100644 index d81cc0710eb..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_inline1.out +++ /dev/null @@ -1 +0,0 @@ -42 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_inline2.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_inline2.kt index 8d99a8acc81..f543f43e982 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_inline2.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_inline2.kt @@ -3,20 +3,20 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_inline2 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } @@ -30,12 +30,19 @@ inline suspend fun inline_s2(): Int { return x } -@Test fun runTest() { +fun box(): String { var result = 0 builder { result = inline_s2() } - println(result) + sb.appendLine(result) + + assertEquals(""" + s1 + 42 + + """.trimIndent(), sb.toString()) + return "OK" } diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_inline2.out b/native/native.tests/testData/codegen/coroutines/controlFlow_inline2.out deleted file mode 100644 index 8b837844a05..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_inline2.out +++ /dev/null @@ -1,2 +0,0 @@ -s1 -42 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_inline3.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_inline3.kt index 69f59f9b50e..86cc684ebd2 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_inline3.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_inline3.kt @@ -3,20 +3,20 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_inline3 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } @@ -26,12 +26,12 @@ fun builder(c: suspend () -> Unit) { } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } @@ -43,12 +43,20 @@ inline suspend fun inline_s2(): Int { return x } -@Test fun runTest() { +fun box(): String { var result = 0 builder { result = inline_s2() } - println(result) + sb.appendLine(result) + + assertEquals(""" + f1 + s1 + 42 + + """.trimIndent(), sb.toString()) + return "OK" } diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_inline3.out b/native/native.tests/testData/codegen/coroutines/controlFlow_inline3.out deleted file mode 100644 index 1bc6efd249e..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_inline3.out +++ /dev/null @@ -1,3 +0,0 @@ -f1 -s1 -42 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch1.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch1.kt index 685b48a78b8..2b921f24f1c 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch1.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch1.kt @@ -3,36 +3,36 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_tryCatch1 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -52,5 +52,12 @@ fun builder(c: suspend () -> Unit) { result = x } - println(result) + sb.appendLine(result) + + assertEquals(""" + s1 + 42 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch1.out b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch1.out deleted file mode 100644 index 8b837844a05..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch1.out +++ /dev/null @@ -1,2 +0,0 @@ -s1 -42 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch2.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch2.kt index 2f0c4bf13a4..baa5d95dddb 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch2.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch2.kt @@ -3,36 +3,36 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_tryCatch2 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -51,5 +51,12 @@ fun builder(c: suspend () -> Unit) { } } - println(result) + sb.appendLine(result) + + assertEquals(""" + s1 + 42 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch2.out b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch2.out deleted file mode 100644 index 8b837844a05..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch2.out +++ /dev/null @@ -1,2 +0,0 @@ -s1 -42 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch3.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch3.kt index 371ed5fd866..4f8afa6c2d0 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch3.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch3.kt @@ -3,42 +3,42 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_tryCatch3 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s2") + sb.appendLine("s2") x.resumeWithException(Error()) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -46,7 +46,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -57,5 +57,13 @@ fun builder(c: suspend () -> Unit) { } } - println(result) + sb.appendLine(result) + + assertEquals(""" + s2 + f2 + 1 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch3.out b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch3.out deleted file mode 100644 index a7413bde36b..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch3.out +++ /dev/null @@ -1,3 +0,0 @@ -s2 -f2 -1 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch4.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch4.kt index 919bbd29c90..3142b5ccf82 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch4.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch4.kt @@ -3,42 +3,42 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_tryCatch4 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s2") + sb.appendLine("s2") x.resumeWithException(Error()) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -46,7 +46,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -58,5 +58,13 @@ fun builder(c: suspend () -> Unit) { result = x } - println(result) + sb.appendLine(result) + + assertEquals(""" + s2 + f2 + 1 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch4.out b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch4.out deleted file mode 100644 index a7413bde36b..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch4.out +++ /dev/null @@ -1,3 +0,0 @@ -s2 -f2 -1 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch5.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch5.kt index 458a371c863..61aec89a295 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch5.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch5.kt @@ -3,42 +3,42 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_tryCatch5 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s2") + sb.appendLine("s2") x.resumeWithException(Error("Error")) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -46,7 +46,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -54,10 +54,19 @@ fun builder(c: suspend () -> Unit) { s2() } catch (t: Throwable) { val x = s1() - println(t.message) + sb.appendLine(t.message) x } } - println(result) + sb.appendLine(result) + + assertEquals(""" + s2 + s1 + Error + 42 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch5.out b/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch5.out deleted file mode 100644 index 39812c11bf8..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_tryCatch5.out +++ /dev/null @@ -1,4 +0,0 @@ -s2 -s1 -Error -42 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_while1.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_while1.kt index b7946119f44..51124427665 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_while1.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_while1.kt @@ -3,48 +3,48 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_while1 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s2") + sb.appendLine("s2") x.resumeWithException(Error("Error")) COROUTINE_SUSPENDED } suspend fun s3(value: Int): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s3") + sb.appendLine("s3") x.resume(value) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -52,7 +52,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -60,5 +60,15 @@ fun builder(c: suspend () -> Unit) { ++result } - println(result) + sb.appendLine(result) + + assertEquals(""" + s3 + s3 + s3 + s3 + 3 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_while1.out b/native/native.tests/testData/codegen/coroutines/controlFlow_while1.out deleted file mode 100644 index 55f6b4ed27c..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_while1.out +++ /dev/null @@ -1,5 +0,0 @@ -s3 -s3 -s3 -s3 -3 diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_while2.kt b/native/native.tests/testData/codegen/coroutines/controlFlow_while2.kt index c2f7880fab1..507bca0f1ff 100644 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_while2.kt +++ b/native/native.tests/testData/codegen/coroutines/controlFlow_while2.kt @@ -3,48 +3,48 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.controlFlow_while2 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s2") + sb.appendLine("s2") x.resumeWithException(Error("Error")) COROUTINE_SUSPENDED } suspend fun s3(value: Int): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s3") + sb.appendLine("s3") x.resume(value) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } fun f3(x: Int, y: Int): Int { - println("f3") + sb.appendLine("f3") return x + y } @@ -52,7 +52,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { @@ -60,5 +60,14 @@ fun builder(c: suspend () -> Unit) { result = s3(result) + 1 } - println(result) + sb.appendLine(result) + + assertEquals(""" + s3 + s3 + s3 + 3 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/controlFlow_while2.out b/native/native.tests/testData/codegen/coroutines/controlFlow_while2.out deleted file mode 100644 index b882ed8cf03..00000000000 --- a/native/native.tests/testData/codegen/coroutines/controlFlow_while2.out +++ /dev/null @@ -1,4 +0,0 @@ -s3 -s3 -s3 -3 diff --git a/native/native.tests/testData/codegen/coroutines/coroutineContext1.kt b/native/native.tests/testData/codegen/coroutines/coroutineContext1.kt index 2bc57a602d6..fec69e0999d 100644 --- a/native/native.tests/testData/codegen/coroutines/coroutineContext1.kt +++ b/native/native.tests/testData/codegen/coroutines/coroutineContext1.kt @@ -3,13 +3,13 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.coroutineContext1 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } @@ -19,6 +19,12 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { - builder { println(coroutineContext) } +fun box(): String { + builder { sb.appendLine(coroutineContext) } + + assertEquals(""" + EmptyCoroutineContext + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/coroutineContext1.out b/native/native.tests/testData/codegen/coroutines/coroutineContext1.out deleted file mode 100644 index 226b070bb28..00000000000 --- a/native/native.tests/testData/codegen/coroutines/coroutineContext1.out +++ /dev/null @@ -1 +0,0 @@ -EmptyCoroutineContext diff --git a/native/native.tests/testData/codegen/coroutines/coroutineContext2.kt b/native/native.tests/testData/codegen/coroutines/coroutineContext2.kt index 1d96d8d6797..0a3f1520930 100644 --- a/native/native.tests/testData/codegen/coroutines/coroutineContext2.kt +++ b/native/native.tests/testData/codegen/coroutines/coroutineContext2.kt @@ -3,13 +3,13 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.coroutineContext2 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } @@ -21,6 +21,12 @@ fun builder(c: suspend () -> Unit) { suspend fun foo() = coroutineContext -@Test fun runTest() { - builder { println(foo()) } +fun box(): String { + builder { sb.appendLine(foo()) } + + assertEquals(""" + EmptyCoroutineContext + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/coroutineContext2.out b/native/native.tests/testData/codegen/coroutines/coroutineContext2.out deleted file mode 100644 index 226b070bb28..00000000000 --- a/native/native.tests/testData/codegen/coroutines/coroutineContext2.out +++ /dev/null @@ -1 +0,0 @@ -EmptyCoroutineContext diff --git a/native/native.tests/testData/codegen/coroutines/correctOrder1.kt b/native/native.tests/testData/codegen/coroutines/correctOrder1.kt index 6be6b1d2846..635a60649de 100644 --- a/native/native.tests/testData/codegen/coroutines/correctOrder1.kt +++ b/native/native.tests/testData/codegen/coroutines/correctOrder1.kt @@ -3,31 +3,31 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.correctOrder1 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(42) COROUTINE_SUSPENDED } fun f1(): Int { - println("f1") + sb.appendLine("f1") return 117 } fun f2(): Int { - println("f2") + sb.appendLine("f2") return 1 } @@ -35,12 +35,21 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { result = f1() + s1() + f2() } - println(result) + sb.appendLine(result) + + assertEquals(""" + f1 + s1 + f2 + 160 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/correctOrder1.out b/native/native.tests/testData/codegen/coroutines/correctOrder1.out deleted file mode 100644 index 025d917d9b7..00000000000 --- a/native/native.tests/testData/codegen/coroutines/correctOrder1.out +++ /dev/null @@ -1,4 +0,0 @@ -f1 -s1 -f2 -160 diff --git a/native/native.tests/testData/codegen/coroutines/degenerate1.kt b/native/native.tests/testData/codegen/coroutines/degenerate1.kt index d73de5a7213..dd4d3470bd0 100644 --- a/native/native.tests/testData/codegen/coroutines/degenerate1.kt +++ b/native/native.tests/testData/codegen/coroutines/degenerate1.kt @@ -3,28 +3,34 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.degenerate1 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1() { - println("s1") + sb.appendLine("s1") } fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { builder { s1() } + + assertEquals(""" + s1 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/degenerate1.out b/native/native.tests/testData/codegen/coroutines/degenerate1.out deleted file mode 100644 index 655c6e645cc..00000000000 --- a/native/native.tests/testData/codegen/coroutines/degenerate1.out +++ /dev/null @@ -1 +0,0 @@ -s1 diff --git a/native/native.tests/testData/codegen/coroutines/degenerate2.kt b/native/native.tests/testData/codegen/coroutines/degenerate2.kt index 4281162b780..019388e3dcf 100644 --- a/native/native.tests/testData/codegen/coroutines/degenerate2.kt +++ b/native/native.tests/testData/codegen/coroutines/degenerate2.kt @@ -3,26 +3,26 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.degenerate2 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Unit = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(Unit) COROUTINE_SUSPENDED } suspend fun s2() { - println("s2") + sb.appendLine("s2") s1() } @@ -30,8 +30,15 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { builder { s2() } + + assertEquals(""" + s2 + s1 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/degenerate2.out b/native/native.tests/testData/codegen/coroutines/degenerate2.out deleted file mode 100644 index 7d52dbf7e90..00000000000 --- a/native/native.tests/testData/codegen/coroutines/degenerate2.out +++ /dev/null @@ -1,2 +0,0 @@ -s2 -s1 diff --git a/native/native.tests/testData/codegen/coroutines/functionReference_eqeq_name.kt b/native/native.tests/testData/codegen/coroutines/functionReference_eqeq_name.kt index 600284984de..23bc6cfc7ca 100644 --- a/native/native.tests/testData/codegen/coroutines/functionReference_eqeq_name.kt +++ b/native/native.tests/testData/codegen/coroutines/functionReference_eqeq_name.kt @@ -3,17 +3,17 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.functionReference_eqeq_name - import kotlin.test.* +val sb = StringBuilder() + suspend fun foo(x: Int) = x class Foo(val x: Int) { suspend fun bar() = x } -@Test fun runTest() { +fun box(): String { val ref1 = ::foo val rec = Foo(42) val ref2 = rec::bar @@ -29,4 +29,6 @@ class Foo(val x: Int) { assertFalse(ref2 == ref4) assertTrue(ref2 == ref5) assertFalse(ref6 == ref2) + + return "OK" } diff --git a/native/native.tests/testData/codegen/coroutines/functionReference_eqeq_name.out b/native/native.tests/testData/codegen/coroutines/functionReference_eqeq_name.out deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/native/native.tests/testData/codegen/coroutines/functionReference_invokeAsFunction.kt b/native/native.tests/testData/codegen/coroutines/functionReference_invokeAsFunction.kt index 0d64ac94c97..9fddb06a084 100644 --- a/native/native.tests/testData/codegen/coroutines/functionReference_invokeAsFunction.kt +++ b/native/native.tests/testData/codegen/coroutines/functionReference_invokeAsFunction.kt @@ -3,13 +3,13 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.functionReference_invokeAsFunction - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } @@ -21,8 +21,14 @@ class Foo(val x: Int) { suspend fun foo(x: Int) = x -@Test fun runTest() { +fun box(): String { val ref = Foo(42)::bar - println((ref as Function2, Any?>)(117, EmptyContinuation)) + sb.appendLine((ref as Function2, Any?>)(117, EmptyContinuation)) + + assertEquals(""" + 159 + + """.trimIndent(), sb.toString()) + return "OK" } diff --git a/native/native.tests/testData/codegen/coroutines/functionReference_invokeAsFunction.out b/native/native.tests/testData/codegen/coroutines/functionReference_invokeAsFunction.out deleted file mode 100644 index 3f7d1915f71..00000000000 --- a/native/native.tests/testData/codegen/coroutines/functionReference_invokeAsFunction.out +++ /dev/null @@ -1 +0,0 @@ -159 diff --git a/native/native.tests/testData/codegen/coroutines/functionReference_lambdaAsSuspendLambda.kt b/native/native.tests/testData/codegen/coroutines/functionReference_lambdaAsSuspendLambda.kt index df9eb23b52a..dfa59474333 100644 --- a/native/native.tests/testData/codegen/coroutines/functionReference_lambdaAsSuspendLambda.kt +++ b/native/native.tests/testData/codegen/coroutines/functionReference_lambdaAsSuspendLambda.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.functionReference_lambdaAsSuspendLambda - import kotlin.test.* import kotlin.coroutines.* @@ -14,6 +12,8 @@ fun foo(block: (Continuation) -> Any?) { block as (suspend () -> Unit) } -@Test fun runTest() { +fun box(): String { foo {} + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/functionReference_lambdaAsSuspendLambda.out b/native/native.tests/testData/codegen/coroutines/functionReference_lambdaAsSuspendLambda.out deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/native/native.tests/testData/codegen/coroutines/functionReference_simple.kt b/native/native.tests/testData/codegen/coroutines/functionReference_simple.kt index d574dc9d373..6e5e5056667 100644 --- a/native/native.tests/testData/codegen/coroutines/functionReference_simple.kt +++ b/native/native.tests/testData/codegen/coroutines/functionReference_simple.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.functionReference_simple - import kotlin.test.* import kotlin.coroutines.* @@ -26,7 +24,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 val ref = ::suspendHere @@ -35,5 +33,6 @@ fun builder(c: suspend () -> Unit) { result = foo(ref) } - println(result) + assertEquals(42, result) + return "OK" } diff --git a/native/native.tests/testData/codegen/coroutines/functionReference_simple.out b/native/native.tests/testData/codegen/coroutines/functionReference_simple.out deleted file mode 100644 index d81cc0710eb..00000000000 --- a/native/native.tests/testData/codegen/coroutines/functionReference_simple.out +++ /dev/null @@ -1 +0,0 @@ -42 diff --git a/native/native.tests/testData/codegen/coroutines/inheritance.kt b/native/native.tests/testData/codegen/coroutines/inheritance.kt index df48169e28f..380ac723094 100644 --- a/native/native.tests/testData/codegen/coroutines/inheritance.kt +++ b/native/native.tests/testData/codegen/coroutines/inheritance.kt @@ -3,8 +3,6 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package codegen.coroutines.inheritance - import kotlin.test.* import kotlin.coroutines.* @@ -35,15 +33,16 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { result = SuspendHere()() } - println(result) + assertEquals(42, result) builder { result = SuspendHereLegacy()() } - println(result) + assertEquals(43, result) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/inheritance.out b/native/native.tests/testData/codegen/coroutines/inheritance.out deleted file mode 100644 index 6fe5c7f6a8f..00000000000 --- a/native/native.tests/testData/codegen/coroutines/inheritance.out +++ /dev/null @@ -1,2 +0,0 @@ -42 -43 diff --git a/native/native.tests/testData/codegen/coroutines/kt41394.kt b/native/native.tests/testData/codegen/coroutines/kt41394.kt index 60908e9009c..a79916aaa19 100644 --- a/native/native.tests/testData/codegen/coroutines/kt41394.kt +++ b/native/native.tests/testData/codegen/coroutines/kt41394.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.kt41394 - import kotlin.test.* import kotlin.coroutines.* @@ -29,7 +27,7 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = "" builder { @@ -37,4 +35,6 @@ fun builder(c: suspend () -> Unit) { } assertEquals("zzz42", result) + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/kt41394.out b/native/native.tests/testData/codegen/coroutines/kt41394.out deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/native/native.tests/testData/codegen/coroutines/returnsNothing1.kt b/native/native.tests/testData/codegen/coroutines/returnsNothing1.kt index 7f74e03b535..02808d890c3 100644 --- a/native/native.tests/testData/codegen/coroutines/returnsNothing1.kt +++ b/native/native.tests/testData/codegen/coroutines/returnsNothing1.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.returnsNothing1 - import kotlin.test.* import kotlin.coroutines.* @@ -32,9 +30,9 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { builder { bar() } - println("OK") + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/returnsNothing1.out b/native/native.tests/testData/codegen/coroutines/returnsNothing1.out deleted file mode 100644 index d86bac9de59..00000000000 --- a/native/native.tests/testData/codegen/coroutines/returnsNothing1.out +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/native/native.tests/testData/codegen/coroutines/returnsUnit1.kt b/native/native.tests/testData/codegen/coroutines/returnsUnit1.kt index 0a3fa3b8964..001798fbb33 100644 --- a/native/native.tests/testData/codegen/coroutines/returnsUnit1.kt +++ b/native/native.tests/testData/codegen/coroutines/returnsUnit1.kt @@ -3,20 +3,20 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.returnsUnit1 - import kotlin.test.* import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* +val sb = StringBuilder() + open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { companion object : EmptyContinuation() override fun resumeWith(result: Result) { result.getOrThrow() } } suspend fun s1(): Unit = suspendCoroutineUninterceptedOrReturn { x -> - println("s1") + sb.appendLine("s1") x.resume(Unit) COROUTINE_SUSPENDED } @@ -26,7 +26,7 @@ fun builder(c: suspend () -> Unit) { } inline suspend fun inline_s2(x: Int): Unit { - println(x) + sb.appendLine(x) s1() } @@ -34,12 +34,20 @@ suspend fun s3(x: Int) { inline_s2(x) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { s3(117) } - println(result) + sb.appendLine(result) + + assertEquals(""" + 117 + s1 + 0 + + """.trimIndent(), sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/returnsUnit1.out b/native/native.tests/testData/codegen/coroutines/returnsUnit1.out deleted file mode 100644 index 4dc5a1f0c0a..00000000000 --- a/native/native.tests/testData/codegen/coroutines/returnsUnit1.out +++ /dev/null @@ -1,3 +0,0 @@ -117 -s1 -0 diff --git a/native/native.tests/testData/codegen/coroutines/simple.kt b/native/native.tests/testData/codegen/coroutines/simple.kt index ff90298307e..4c66284db9b 100644 --- a/native/native.tests/testData/codegen/coroutines/simple.kt +++ b/native/native.tests/testData/codegen/coroutines/simple.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.simple - import kotlin.test.* import kotlin.coroutines.* @@ -24,12 +22,13 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { result = suspendHere() } - println(result) + assertEquals(42, result) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/simple.out b/native/native.tests/testData/codegen/coroutines/simple.out deleted file mode 100644 index d81cc0710eb..00000000000 --- a/native/native.tests/testData/codegen/coroutines/simple.out +++ /dev/null @@ -1 +0,0 @@ -42 diff --git a/native/native.tests/testData/codegen/coroutines/suspendConversion.kt b/native/native.tests/testData/codegen/coroutines/suspendConversion.kt index 12c66352e7e..9415b04c116 100644 --- a/native/native.tests/testData/codegen/coroutines/suspendConversion.kt +++ b/native/native.tests/testData/codegen/coroutines/suspendConversion.kt @@ -17,11 +17,13 @@ fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } -fun main() { +fun box(): String { var result = 0 val f: () -> Unit = { result = 42 } builder(f) assertEquals(42, result) + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/suspendConversion.out b/native/native.tests/testData/codegen/coroutines/suspendConversion.out deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/native/native.tests/testData/codegen/coroutines/withReceiver.kt b/native/native.tests/testData/codegen/coroutines/withReceiver.kt index cf841061a25..963980dd515 100644 --- a/native/native.tests/testData/codegen/coroutines/withReceiver.kt +++ b/native/native.tests/testData/codegen/coroutines/withReceiver.kt @@ -3,8 +3,6 @@ * that can be found in the LICENSE file. */ -package codegen.coroutines.withReceiver - import kotlin.test.* import kotlin.coroutines.* @@ -26,12 +24,13 @@ fun builder(c: suspend Controller.() -> Unit) { c.startCoroutine(Controller(), EmptyContinuation) } -@Test fun runTest() { +fun box(): String { var result = 0 builder { result = suspendHere() } - println(result) + assertEquals(42, result) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/coroutines/withReceiver.out b/native/native.tests/testData/codegen/coroutines/withReceiver.out deleted file mode 100644 index d81cc0710eb..00000000000 --- a/native/native.tests/testData/codegen/coroutines/withReceiver.out +++ /dev/null @@ -1 +0,0 @@ -42 diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenLocalTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenLocalTestGenerated.java index e541ecaa385..6e875a32f37 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenLocalTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenLocalTestGenerated.java @@ -63,9 +63,57 @@ public class FirNativeCodegenLocalTestGenerated extends AbstractNativeCodegenBox } @Test - @TestMetadata("basic.kt") - public void testBasic() throws Exception { - runTest("native/native.tests/testData/codegen/arithmetic/basic.kt"); + @TestMetadata("basic_charConversions.kt") + public void testBasic_charConversions() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_charConversions.kt"); + } + + @Test + @TestMetadata("basic_charCornerCases.kt") + public void testBasic_charCornerCases() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_charCornerCases.kt"); + } + + @Test + @TestMetadata("basic_compareIntToFloat.kt") + public void testBasic_compareIntToFloat() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_compareIntToFloat.kt"); + } + + @Test + @TestMetadata("basic_doubleBasic.kt") + public void testBasic_doubleBasic() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_doubleBasic.kt"); + } + + @Test + @TestMetadata("basic_integralToFloat.kt") + public void testBasic_integralToFloat() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_integralToFloat.kt"); + } + + @Test + @TestMetadata("basic_kt37412.kt") + public void testBasic_kt37412() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_kt37412.kt"); + } + + @Test + @TestMetadata("basic_selfComparison.kt") + public void testBasic_selfComparison() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_selfComparison.kt"); + } + + @Test + @TestMetadata("basic_shifts.kt") + public void testBasic_shifts() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_shifts.kt"); + } + + @Test + @TestMetadata("basic_uintTests.kt") + public void testBasic_uintTests() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_uintTests.kt"); } @Test @@ -94,9 +142,21 @@ public class FirNativeCodegenLocalTestGenerated extends AbstractNativeCodegenBox } @Test - @TestMetadata("associatedObjects1.kt") - public void testAssociatedObjects1() throws Exception { - runTest("native/native.tests/testData/codegen/associatedObjects/associatedObjects1.kt"); + @TestMetadata("associatedObjects1_testBasics1.kt") + public void testAssociatedObjects1_testBasics1() throws Exception { + runTest("native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testBasics1.kt"); + } + + @Test + @TestMetadata("associatedObjects1_testGlobalOptimizations1.kt") + public void testAssociatedObjects1_testGlobalOptimizations1() throws Exception { + runTest("native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testGlobalOptimizations1.kt"); + } + + @Test + @TestMetadata("associatedObjects1_testGlobalOptimizations2.kt") + public void testAssociatedObjects1_testGlobalOptimizations2() throws Exception { + runTest("native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testGlobalOptimizations2.kt"); } } @@ -288,9 +348,105 @@ public class FirNativeCodegenLocalTestGenerated extends AbstractNativeCodegenBox } @Test - @TestMetadata("arraysForLoops.kt") - public void testArraysForLoops() throws Exception { - runTest("native/native.tests/testData/codegen/bce/arraysForLoops.kt"); + @TestMetadata("bceCases.kt") + public void testBceCases() throws Exception { + runTest("native/native.tests/testData/codegen/bce/bceCases.kt"); + } + + @Test + @TestMetadata("customGetter.kt") + public void testCustomGetter() throws Exception { + runTest("native/native.tests/testData/codegen/bce/customGetter.kt"); + } + + @Test + @TestMetadata("delegatedProperty.kt") + public void testDelegatedProperty() throws Exception { + runTest("native/native.tests/testData/codegen/bce/delegatedProperty.kt"); + } + + @Test + @TestMetadata("differentArrays.kt") + public void testDifferentArrays() throws Exception { + runTest("native/native.tests/testData/codegen/bce/differentArrays.kt"); + } + + @Test + @TestMetadata("differentObjects.kt") + public void testDifferentObjects() throws Exception { + runTest("native/native.tests/testData/codegen/bce/differentObjects.kt"); + } + + @Test + @TestMetadata("forDownToSize.kt") + public void testForDownToSize() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forDownToSize.kt"); + } + + @Test + @TestMetadata("forDownToWithStep.kt") + public void testForDownToWithStep() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forDownToWithStep.kt"); + } + + @Test + @TestMetadata("forEachIndexedTest.kt") + public void testForEachIndexedTest() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forEachIndexedTest.kt"); + } + + @Test + @TestMetadata("forEachIndicies.kt") + public void testForEachIndicies() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forEachIndicies.kt"); + } + + @Test + @TestMetadata("forIndiciesWithStep.kt") + public void testForIndiciesWithStep() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forIndiciesWithStep.kt"); + } + + @Test + @TestMetadata("forRangeToSize.kt") + public void testForRangeToSize() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forRangeToSize.kt"); + } + + @Test + @TestMetadata("forRangeToWithStep.kt") + public void testForRangeToWithStep() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forRangeToWithStep.kt"); + } + + @Test + @TestMetadata("forReversed.kt") + public void testForReversed() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forReversed.kt"); + } + + @Test + @TestMetadata("forUntilSize.kt") + public void testForUntilSize() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forUntilSize.kt"); + } + + @Test + @TestMetadata("forWithIndex.kt") + public void testForWithIndex() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forWithIndex.kt"); + } + + @Test + @TestMetadata("inheritance.kt") + public void testInheritance() throws Exception { + runTest("native/native.tests/testData/codegen/bce/inheritance.kt"); + } + + @Test + @TestMetadata("withGetter.kt") + public void testWithGetter() throws Exception { + runTest("native/native.tests/testData/codegen/bce/withGetter.kt"); } } @@ -512,30 +668,6 @@ public class FirNativeCodegenLocalTestGenerated extends AbstractNativeCodegenBox KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/codegen/bridges"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); } - @Test - @TestMetadata("linkTest2_lib.kt") - public void testLinkTest2_lib() throws Exception { - runTest("native/native.tests/testData/codegen/bridges/linkTest2_lib.kt"); - } - - @Test - @TestMetadata("linkTest2_main.kt") - public void testLinkTest2_main() throws Exception { - runTest("native/native.tests/testData/codegen/bridges/linkTest2_main.kt"); - } - - @Test - @TestMetadata("linkTest_lib.kt") - public void testLinkTest_lib() throws Exception { - runTest("native/native.tests/testData/codegen/bridges/linkTest_lib.kt"); - } - - @Test - @TestMetadata("linkTest_main.kt") - public void testLinkTest_main() throws Exception { - runTest("native/native.tests/testData/codegen/bridges/linkTest_main.kt"); - } - @Test @TestMetadata("nativePointed.kt") public void testNativePointed() throws Exception { @@ -693,18 +825,6 @@ public class FirNativeCodegenLocalTestGenerated extends AbstractNativeCodegenBox runTest("native/native.tests/testData/codegen/classDelegation/generic.kt"); } - @Test - @TestMetadata("linkTest_lib.kt") - public void testLinkTest_lib() throws Exception { - runTest("native/native.tests/testData/codegen/classDelegation/linkTest_lib.kt"); - } - - @Test - @TestMetadata("linkTest_main.kt") - public void testLinkTest_main() throws Exception { - runTest("native/native.tests/testData/codegen/classDelegation/linkTest_main.kt"); - } - @Test @TestMetadata("method.kt") public void testMethod() throws Exception { @@ -737,9 +857,33 @@ public class FirNativeCodegenLocalTestGenerated extends AbstractNativeCodegenBox } @Test - @TestMetadata("contracts.kt") - public void testContracts() throws Exception { - runTest("native/native.tests/testData/codegen/contracts/contracts.kt"); + @TestMetadata("contractForCast.kt") + public void testContractForCast() throws Exception { + runTest("native/native.tests/testData/codegen/contracts/contractForCast.kt"); + } + + @Test + @TestMetadata("isNullString.kt") + public void testIsNullString() throws Exception { + runTest("native/native.tests/testData/codegen/contracts/isNullString.kt"); + } + + @Test + @TestMetadata("nonNullSmartCast.kt") + public void testNonNullSmartCast() throws Exception { + runTest("native/native.tests/testData/codegen/contracts/nonNullSmartCast.kt"); + } + + @Test + @TestMetadata("require.kt") + public void testRequire() throws Exception { + runTest("native/native.tests/testData/codegen/contracts/require.kt"); + } + + @Test + @TestMetadata("runLambdaForVal.kt") + public void testRunLambdaForVal() throws Exception { + runTest("native/native.tests/testData/codegen/contracts/runLambdaForVal.kt"); } } diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenLocalTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenLocalTestGenerated.java index 6f93a489e27..07cb4ea7920 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenLocalTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenLocalTestGenerated.java @@ -55,9 +55,57 @@ public class NativeCodegenLocalTestGenerated extends AbstractNativeCodegenBoxTes } @Test - @TestMetadata("basic.kt") - public void testBasic() throws Exception { - runTest("native/native.tests/testData/codegen/arithmetic/basic.kt"); + @TestMetadata("basic_charConversions.kt") + public void testBasic_charConversions() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_charConversions.kt"); + } + + @Test + @TestMetadata("basic_charCornerCases.kt") + public void testBasic_charCornerCases() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_charCornerCases.kt"); + } + + @Test + @TestMetadata("basic_compareIntToFloat.kt") + public void testBasic_compareIntToFloat() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_compareIntToFloat.kt"); + } + + @Test + @TestMetadata("basic_doubleBasic.kt") + public void testBasic_doubleBasic() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_doubleBasic.kt"); + } + + @Test + @TestMetadata("basic_integralToFloat.kt") + public void testBasic_integralToFloat() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_integralToFloat.kt"); + } + + @Test + @TestMetadata("basic_kt37412.kt") + public void testBasic_kt37412() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_kt37412.kt"); + } + + @Test + @TestMetadata("basic_selfComparison.kt") + public void testBasic_selfComparison() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_selfComparison.kt"); + } + + @Test + @TestMetadata("basic_shifts.kt") + public void testBasic_shifts() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_shifts.kt"); + } + + @Test + @TestMetadata("basic_uintTests.kt") + public void testBasic_uintTests() throws Exception { + runTest("native/native.tests/testData/codegen/arithmetic/basic_uintTests.kt"); } @Test @@ -84,9 +132,21 @@ public class NativeCodegenLocalTestGenerated extends AbstractNativeCodegenBoxTes } @Test - @TestMetadata("associatedObjects1.kt") - public void testAssociatedObjects1() throws Exception { - runTest("native/native.tests/testData/codegen/associatedObjects/associatedObjects1.kt"); + @TestMetadata("associatedObjects1_testBasics1.kt") + public void testAssociatedObjects1_testBasics1() throws Exception { + runTest("native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testBasics1.kt"); + } + + @Test + @TestMetadata("associatedObjects1_testGlobalOptimizations1.kt") + public void testAssociatedObjects1_testGlobalOptimizations1() throws Exception { + runTest("native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testGlobalOptimizations1.kt"); + } + + @Test + @TestMetadata("associatedObjects1_testGlobalOptimizations2.kt") + public void testAssociatedObjects1_testGlobalOptimizations2() throws Exception { + runTest("native/native.tests/testData/codegen/associatedObjects/associatedObjects1_testGlobalOptimizations2.kt"); } } @@ -274,9 +334,105 @@ public class NativeCodegenLocalTestGenerated extends AbstractNativeCodegenBoxTes } @Test - @TestMetadata("arraysForLoops.kt") - public void testArraysForLoops() throws Exception { - runTest("native/native.tests/testData/codegen/bce/arraysForLoops.kt"); + @TestMetadata("bceCases.kt") + public void testBceCases() throws Exception { + runTest("native/native.tests/testData/codegen/bce/bceCases.kt"); + } + + @Test + @TestMetadata("customGetter.kt") + public void testCustomGetter() throws Exception { + runTest("native/native.tests/testData/codegen/bce/customGetter.kt"); + } + + @Test + @TestMetadata("delegatedProperty.kt") + public void testDelegatedProperty() throws Exception { + runTest("native/native.tests/testData/codegen/bce/delegatedProperty.kt"); + } + + @Test + @TestMetadata("differentArrays.kt") + public void testDifferentArrays() throws Exception { + runTest("native/native.tests/testData/codegen/bce/differentArrays.kt"); + } + + @Test + @TestMetadata("differentObjects.kt") + public void testDifferentObjects() throws Exception { + runTest("native/native.tests/testData/codegen/bce/differentObjects.kt"); + } + + @Test + @TestMetadata("forDownToSize.kt") + public void testForDownToSize() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forDownToSize.kt"); + } + + @Test + @TestMetadata("forDownToWithStep.kt") + public void testForDownToWithStep() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forDownToWithStep.kt"); + } + + @Test + @TestMetadata("forEachIndexedTest.kt") + public void testForEachIndexedTest() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forEachIndexedTest.kt"); + } + + @Test + @TestMetadata("forEachIndicies.kt") + public void testForEachIndicies() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forEachIndicies.kt"); + } + + @Test + @TestMetadata("forIndiciesWithStep.kt") + public void testForIndiciesWithStep() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forIndiciesWithStep.kt"); + } + + @Test + @TestMetadata("forRangeToSize.kt") + public void testForRangeToSize() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forRangeToSize.kt"); + } + + @Test + @TestMetadata("forRangeToWithStep.kt") + public void testForRangeToWithStep() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forRangeToWithStep.kt"); + } + + @Test + @TestMetadata("forReversed.kt") + public void testForReversed() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forReversed.kt"); + } + + @Test + @TestMetadata("forUntilSize.kt") + public void testForUntilSize() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forUntilSize.kt"); + } + + @Test + @TestMetadata("forWithIndex.kt") + public void testForWithIndex() throws Exception { + runTest("native/native.tests/testData/codegen/bce/forWithIndex.kt"); + } + + @Test + @TestMetadata("inheritance.kt") + public void testInheritance() throws Exception { + runTest("native/native.tests/testData/codegen/bce/inheritance.kt"); + } + + @Test + @TestMetadata("withGetter.kt") + public void testWithGetter() throws Exception { + runTest("native/native.tests/testData/codegen/bce/withGetter.kt"); } } @@ -492,30 +648,6 @@ public class NativeCodegenLocalTestGenerated extends AbstractNativeCodegenBoxTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/codegen/bridges"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); } - @Test - @TestMetadata("linkTest2_lib.kt") - public void testLinkTest2_lib() throws Exception { - runTest("native/native.tests/testData/codegen/bridges/linkTest2_lib.kt"); - } - - @Test - @TestMetadata("linkTest2_main.kt") - public void testLinkTest2_main() throws Exception { - runTest("native/native.tests/testData/codegen/bridges/linkTest2_main.kt"); - } - - @Test - @TestMetadata("linkTest_lib.kt") - public void testLinkTest_lib() throws Exception { - runTest("native/native.tests/testData/codegen/bridges/linkTest_lib.kt"); - } - - @Test - @TestMetadata("linkTest_main.kt") - public void testLinkTest_main() throws Exception { - runTest("native/native.tests/testData/codegen/bridges/linkTest_main.kt"); - } - @Test @TestMetadata("nativePointed.kt") public void testNativePointed() throws Exception { @@ -671,18 +803,6 @@ public class NativeCodegenLocalTestGenerated extends AbstractNativeCodegenBoxTes runTest("native/native.tests/testData/codegen/classDelegation/generic.kt"); } - @Test - @TestMetadata("linkTest_lib.kt") - public void testLinkTest_lib() throws Exception { - runTest("native/native.tests/testData/codegen/classDelegation/linkTest_lib.kt"); - } - - @Test - @TestMetadata("linkTest_main.kt") - public void testLinkTest_main() throws Exception { - runTest("native/native.tests/testData/codegen/classDelegation/linkTest_main.kt"); - } - @Test @TestMetadata("method.kt") public void testMethod() throws Exception { @@ -713,9 +833,33 @@ public class NativeCodegenLocalTestGenerated extends AbstractNativeCodegenBoxTes } @Test - @TestMetadata("contracts.kt") - public void testContracts() throws Exception { - runTest("native/native.tests/testData/codegen/contracts/contracts.kt"); + @TestMetadata("contractForCast.kt") + public void testContractForCast() throws Exception { + runTest("native/native.tests/testData/codegen/contracts/contractForCast.kt"); + } + + @Test + @TestMetadata("isNullString.kt") + public void testIsNullString() throws Exception { + runTest("native/native.tests/testData/codegen/contracts/isNullString.kt"); + } + + @Test + @TestMetadata("nonNullSmartCast.kt") + public void testNonNullSmartCast() throws Exception { + runTest("native/native.tests/testData/codegen/contracts/nonNullSmartCast.kt"); + } + + @Test + @TestMetadata("require.kt") + public void testRequire() throws Exception { + runTest("native/native.tests/testData/codegen/contracts/require.kt"); + } + + @Test + @TestMetadata("runLambdaForVal.kt") + public void testRunLambdaForVal() throws Exception { + runTest("native/native.tests/testData/codegen/contracts/runLambdaForVal.kt"); } }