diff --git a/native/native.tests/testData/codegen/basics/statements0.kt b/native/native.tests/testData/codegen/basics/statements0.kt index 8011155b17b..c07aab4b37e 100644 --- a/native/native.tests/testData/codegen/basics/statements0.kt +++ b/native/native.tests/testData/codegen/basics/statements0.kt @@ -3,16 +3,16 @@ * that can be found in the LICENSE file. */ -package runtime.basic.statements0 - import kotlin.test.* +val sb = StringBuilder() + fun simple() { var a = 238 a++ - println(a) + sb.appendLine(a) --a - println(a) + sb.appendLine(a) } class Foo() { @@ -31,12 +31,15 @@ class Foo() { fun fields() { val foo = Foo() foo.more() - println(foo.i) + sb.appendLine(foo.i) foo.less() - println(foo.i) + sb.appendLine(foo.i) } -@Test fun runTest() { +fun box(): String { simple() fields() + + assertEquals("239\n238\n30\n29\n", sb.toString()) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/enum/enum_equals.kt b/native/native.tests/testData/codegen/enum/enum_equals.kt index b5db82a51b9..a8d57f12349 100644 --- a/native/native.tests/testData/codegen/enum/enum_equals.kt +++ b/native/native.tests/testData/codegen/enum/enum_equals.kt @@ -2,8 +2,7 @@ * 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 runtime.basic.enum_equals +// !LANGUAGE: -ProhibitComparisonOfIncompatibleEnums import kotlin.test.* @@ -15,8 +14,13 @@ enum class EnumB { B } -fun main() { - println(EnumA.A == EnumA.A) - println(EnumA.A == EnumA.B) - println(EnumA.A == EnumB.B) -} \ No newline at end of file +fun box(): String { + if (!(EnumA.A == EnumA.A)) + return "FAIL: A must equal A" + if (EnumA.A == EnumA.B) + return "FAIL: A.A must not equal A.B" + if (EnumA.A == EnumB.B) + return "FAIL: A.A must not equal B.B" + + return "OK" +} diff --git a/native/native.tests/testData/codegen/exceptions/catch1.kt b/native/native.tests/testData/codegen/exceptions/catch1.kt index e22562c4ad1..f9c53b3ff2d 100644 --- a/native/native.tests/testData/codegen/exceptions/catch1.kt +++ b/native/native.tests/testData/codegen/exceptions/catch1.kt @@ -3,23 +3,31 @@ * that can be found in the LICENSE file. */ -package runtime.exceptions.catch1 - import kotlin.test.* -@Test fun runTest() { +val sb = StringBuilder() + +fun box(): String { try { - println("Before") + sb.appendLine("Before") foo() - println("After") + sb.appendLine("After") } catch (e: Throwable) { - println("Caught Throwable") + sb.appendLine("Caught Throwable") } - println("Done") + sb.appendLine("Done") + + assertEquals(""" + Before + Caught Throwable + Done + + """.trimIndent(), sb.toString()) + return "OK" } fun foo() { throw Error("Error happens") - println("After in foo()") + sb.appendLine("After in foo()") } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/exceptions/catch2.kt b/native/native.tests/testData/codegen/exceptions/catch2.kt index 5eee69f5301..0801519febf 100644 --- a/native/native.tests/testData/codegen/exceptions/catch2.kt +++ b/native/native.tests/testData/codegen/exceptions/catch2.kt @@ -3,27 +3,35 @@ * that can be found in the LICENSE file. */ -package runtime.exceptions.catch2 - import kotlin.test.* -@Test fun runTest() { +val sb = StringBuilder() + +fun box(): String { try { - println("Before") + sb.appendLine("Before") foo() - println("After") + sb.appendLine("After") } catch (e: Exception) { - println("Caught Exception") + sb.appendLine("Caught Exception") } catch (e: Error) { - println("Caught Error") + sb.appendLine("Caught Error") } catch (e: Throwable) { - println("Caught Throwable") + sb.appendLine("Caught Throwable") } - println("Done") + sb.appendLine("Done") + + assertEquals(""" + Before + Caught Error + Done + + """.trimIndent(), sb.toString()) + return "OK" } fun foo() { throw Error("Error happens") - println("After in foo()") + sb.appendLine("After in foo()") } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/exceptions/catch7.kt b/native/native.tests/testData/codegen/exceptions/catch7.kt index 91ae88cd742..a97d50ffd98 100644 --- a/native/native.tests/testData/codegen/exceptions/catch7.kt +++ b/native/native.tests/testData/codegen/exceptions/catch7.kt @@ -3,21 +3,23 @@ * that can be found in the LICENSE file. */ -package runtime.exceptions.catch7 - import kotlin.test.* -@Test fun runTest() { +val sb = StringBuilder() + +fun box(): String { try { foo() } catch (e: Throwable) { val message = e.message if (message != null) { - println(message) + sb.append(message) } } + + return sb.toString() } fun foo() { - throw Error("Error happens") + throw Error("OK") } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/exceptions/extend0.kt b/native/native.tests/testData/codegen/exceptions/extend0.kt index 298bc0e3781..29583b7a18a 100644 --- a/native/native.tests/testData/codegen/exceptions/extend0.kt +++ b/native/native.tests/testData/codegen/exceptions/extend0.kt @@ -3,16 +3,15 @@ * that can be found in the LICENSE file. */ -package runtime.exceptions.extend0 - import kotlin.test.* class C : Exception("OK") -@Test fun runTest() { +fun box(): String { try { throw C() } catch (e: Throwable) { - println(e.message!!) + return e.message!! } + return "FAIL" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/exceptions/rethrow.kt b/native/native.tests/testData/codegen/exceptions/rethrow.kt index 5de33887ae6..8acff5b6a07 100644 --- a/native/native.tests/testData/codegen/exceptions/rethrow.kt +++ b/native/native.tests/testData/codegen/exceptions/rethrow.kt @@ -3,12 +3,9 @@ * that can be found in the LICENSE file. */ -package runtime.exceptions.rethtow - import kotlin.test.* -@Test -fun runTest() { +fun box(): String { assertFailsWith("My error") { try { error("My error") @@ -16,4 +13,5 @@ fun runTest() { throw e } } + return "OK" } diff --git a/native/native.tests/testData/codegen/exceptions/throw0.kt b/native/native.tests/testData/codegen/exceptions/throw0.kt index 1970a638fe7..d179f88e30a 100644 --- a/native/native.tests/testData/codegen/exceptions/throw0.kt +++ b/native/native.tests/testData/codegen/exceptions/throw0.kt @@ -3,15 +3,13 @@ * that can be found in the LICENSE file. */ -package runtime.basic.throw0 - import kotlin.test.* -@Test fun runTest() { +fun box(): String { val cond = 1 if (cond == 2) throw RuntimeException() if (cond == 3) throw NoSuchElementException("no such element") if (cond == 4) throw Error("error happens") - println("Done") + return "OK" } diff --git a/native/native.tests/testData/codegen/exceptions/throw_from_catch.kt b/native/native.tests/testData/codegen/exceptions/throw_from_catch.kt index 1522b735d21..668d61c1ce7 100644 --- a/native/native.tests/testData/codegen/exceptions/throw_from_catch.kt +++ b/native/native.tests/testData/codegen/exceptions/throw_from_catch.kt @@ -3,12 +3,9 @@ * that can be found in the LICENSE file. */ -package runtime.exceptions.throw_from_catch - import kotlin.test.* -@Test -fun runTest() { +fun box(): String { assertFailsWith("My another error") { try { error("My error") @@ -16,4 +13,5 @@ fun runTest() { error("My another error") } } + return "OK" } diff --git a/native/native.tests/testData/codegen/initializers/initializers0.kt b/native/native.tests/testData/codegen/initializers/initializers0.kt index 31d7d291b4c..f01c0ffaa96 100644 --- a/native/native.tests/testData/codegen/initializers/initializers0.kt +++ b/native/native.tests/testData/codegen/initializers/initializers0.kt @@ -3,51 +3,66 @@ * that can be found in the LICENSE file. */ -package runtime.basic.initializers0 - import kotlin.test.* +val sb = StringBuilder() + class A { init{ - println ("A::init") + sb.appendLine ("A::init") } val a = 1 companion object :B(1) { init { - println ("A::companion") + sb.appendLine ("A::companion") } fun foo() { - println("A::companion::foo") + sb.appendLine("A::companion::foo") } } object AObj : B(){ init { - println("A::Obj") + sb.appendLine("A::Obj") } fun foo() { - println("A::AObj::foo") + sb.appendLine("A::AObj::foo") } } } -@Test fun runTest() { - println("main") +fun box(): String { + sb.appendLine("main") A.foo() A.foo() A.AObj.foo() A.AObj.foo() + + assertEquals(""" + main + B::constructor(1) + A::companion + A::companion::foo + A::companion::foo + B::constructor(0) + B::constructor() + A::Obj + A::AObj::foo + A::AObj::foo + + """.trimIndent(), sb.toString()) + return "OK" } open class B(val a:Int, val b:Int) { constructor(a:Int):this (a, 0) { - println("B::constructor(" + a.toString()+ ")") + sb.appendLine("B::constructor(" + a.toString()+ ")") } constructor():this(0) { - println("B::constructor()") + sb.appendLine("B::constructor()") } } diff --git a/native/native.tests/testData/codegen/initializers/initializers1.kt b/native/native.tests/testData/codegen/initializers/initializers1.kt index 7b8c7cc2851..7ce581b00a8 100644 --- a/native/native.tests/testData/codegen/initializers/initializers1.kt +++ b/native/native.tests/testData/codegen/initializers/initializers1.kt @@ -2,21 +2,21 @@ * 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 runtime.basic.initializers1 - import kotlin.test.* +val sb = StringBuilder() + class TestClass { companion object { init { - println("Init Test") + sb.append("OK") } } } -@Test fun runTest() { +fun box(): String { val t1 = TestClass() val t2 = TestClass() - println("Done") + + return sb.toString() } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/initializers/initializers2.kt b/native/native.tests/testData/codegen/initializers/initializers2.kt index aa24adce598..84ae042171f 100644 --- a/native/native.tests/testData/codegen/initializers/initializers2.kt +++ b/native/native.tests/testData/codegen/initializers/initializers2.kt @@ -3,9 +3,13 @@ * that can be found in the LICENSE file. */ +import kotlin.test.* + +val sb = StringBuilder() + class A(val msg: String) { init { - println("init $msg") + sb.appendLine("init $msg") } override fun toString(): String = msg } @@ -14,9 +18,19 @@ val globalValue1 = 1 val globalValue2 = A("globalValue2") val globalValue3 = A("globalValue3") -fun main(args: Array) { - println(globalValue1.toString()) - println(globalValue2.toString()) - println(globalValue3.toString()) +fun box(): String { + sb.appendLine(globalValue1.toString()) + sb.appendLine(globalValue2.toString()) + sb.appendLine(globalValue3.toString()) + + assertEquals(""" + init globalValue2 + init globalValue3 + 1 + globalValue2 + globalValue3 + + """.trimIndent(), sb.toString()) + return "OK" } diff --git a/native/native.tests/testData/codegen/initializers/initializers3.kt b/native/native.tests/testData/codegen/initializers/initializers3.kt index 5dfb0c67803..314e8f20f4a 100644 --- a/native/native.tests/testData/codegen/initializers/initializers3.kt +++ b/native/native.tests/testData/codegen/initializers/initializers3.kt @@ -2,15 +2,13 @@ * 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 runtime.basic.initializers3 - import kotlin.test.* class Foo(val bar: Int) var x = Foo(42) -@Test fun runTest() { - println(x.bar) +fun box(): String { + assertEquals(42, x.bar) + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/initializers/initializers4.kt b/native/native.tests/testData/codegen/initializers/initializers4.kt index 008b512b138..59c5ee10712 100644 --- a/native/native.tests/testData/codegen/initializers/initializers4.kt +++ b/native/native.tests/testData/codegen/initializers/initializers4.kt @@ -2,15 +2,14 @@ * 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 runtime.basic.initializers4 - import kotlin.test.* const val INT_MAX_POWER_OF_TWO: Int = Int.MAX_VALUE / 2 + 1 val DOUBLE = Double.MAX_VALUE - 1.0 -@Test fun runTest() { - println(INT_MAX_POWER_OF_TWO) - println(DOUBLE > 0.0) +fun box(): String { + assertEquals(1073741824, INT_MAX_POWER_OF_TWO) + assertTrue(DOUBLE > 0.0) + + return "OK" } diff --git a/native/native.tests/testData/codegen/initializers/initializers5.kt b/native/native.tests/testData/codegen/initializers/initializers5.kt index 0c67dcb38b0..919d78a3c54 100644 --- a/native/native.tests/testData/codegen/initializers/initializers5.kt +++ b/native/native.tests/testData/codegen/initializers/initializers5.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 runtime.basic.initializers5 - import kotlin.test.* object A { @@ -12,6 +9,8 @@ object A { val b = A.a } -@Test fun runTest() { - println(A.b) +fun box(): String { + assertEquals(42, A.b) + + return "OK" } \ No newline at end of file diff --git a/native/native.tests/testData/codegen/initializers/initializers7.kt b/native/native.tests/testData/codegen/initializers/initializers7.kt index 7327675675f..57ac9b99ed3 100644 --- a/native/native.tests/testData/codegen/initializers/initializers7.kt +++ b/native/native.tests/testData/codegen/initializers/initializers7.kt @@ -2,9 +2,6 @@ * Copyright 2010-2020 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 runtime.basic.initializers7 - import kotlin.test.* object A { @@ -53,8 +50,10 @@ fun assertCUninitialized() { assertEquals(0, C.c4) } -@Test fun runTest() { +fun box(): String { assertEquals(A.a1, C.c2) assertEquals(A.a2, C.c3) assertEquals(C.c1, C.c4) + + return "OK" } diff --git a/native/native.tests/testData/codegen/initializers/initializers8.kt b/native/native.tests/testData/codegen/initializers/initializers8.kt index d6d77a681b0..d3206081873 100644 --- a/native/native.tests/testData/codegen/initializers/initializers8.kt +++ b/native/native.tests/testData/codegen/initializers/initializers8.kt @@ -2,13 +2,10 @@ * 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 runtime.basic.initializers8 - import kotlin.test.* -var globalString = "abc" +var globalString = "OK" -@Test fun runTest() { - assertEquals("abc", globalString) +fun box(): String { + return globalString } diff --git a/native/native.tests/testData/codegen/interfaceCallsNCasts/interface0.kt b/native/native.tests/testData/codegen/interfaceCallsNCasts/interface0.kt index 347e562c5b6..3f2e3b3865b 100644 --- a/native/native.tests/testData/codegen/interfaceCallsNCasts/interface0.kt +++ b/native/native.tests/testData/codegen/interfaceCallsNCasts/interface0.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 runtime.basic.interface0 - import kotlin.test.* interface A { @@ -12,14 +9,17 @@ interface A { fun c() } +val sb = StringBuilder() + class B(): A { override fun c() { - println("PASSED") + sb.append("OK") } } -@Test fun runTest() { +fun box(): String { val a:A = B() a.b() -} + return sb.toString() +} diff --git a/native/native.tests/testData/datagen/literals/listof1.kt b/native/native.tests/testData/datagen/literals/listof1.kt index 8c01cb18a0e..8afaa02b35c 100644 --- a/native/native.tests/testData/datagen/literals/listof1.kt +++ b/native/native.tests/testData/datagen/literals/listof1.kt @@ -2,17 +2,23 @@ * 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 datagen.literals.listof1 +// WITH_STDLIB +// This test verifies absence of buggy optimzation removed in https://github.com/JetBrains/kotlin/commit/d222e9587 import kotlin.test.* -@Test fun runTest() { +fun box(): String { val list = foo() - println(list === foo()) - println(list.toString()) + if (!(list == foo())) + return "FAIL ==" + if (list === foo()) + return "FAIL ===: two listOf() having same contents are not optimized to be referentially equal in all backends, but are now unexpectedly referentially equal" + if (list.toString() != "[a, b, c]") + return "FAIL toString(): ${list.toString()}" + + return "OK" } fun foo(): List { return listOf("a", "b", "c") -} \ No newline at end of file +} diff --git a/native/native.tests/testData/datagen/literals/strdedup1.kt b/native/native.tests/testData/datagen/literals/strdedup1.kt index 1e1cc37c5a9..977acd4fdc7 100644 --- a/native/native.tests/testData/datagen/literals/strdedup1.kt +++ b/native/native.tests/testData/datagen/literals/strdedup1.kt @@ -3,13 +3,15 @@ * that can be found in the LICENSE file. */ -package datagen.literals.strdedup1 - import kotlin.test.* -@Test fun runTest() { +fun box(): String { val str1 = "Hello" val str2 = "Hello" - println(str1 == str2) - println(str1 === str2) + if (!(str1 == str2)) + return "FAIL ==" + if (!(str1 === str2)) + return "FAIL ===" + + return "OK" } diff --git a/native/native.tests/testData/datagen/literals/strdedup2.kt b/native/native.tests/testData/datagen/literals/strdedup2.kt index 763062dfb50..01ad80b7b18 100644 --- a/native/native.tests/testData/datagen/literals/strdedup2.kt +++ b/native/native.tests/testData/datagen/literals/strdedup2.kt @@ -2,14 +2,20 @@ * 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 datagen.literals.strdedup2 +// TODO: string deduplication across several components seems to require +// linking them as bitcode modules before translating to machine code. +// IGNORE_BACKEND: NATIVE, JVM, JVM_IR +// WITH_STDLIB import kotlin.test.* -@Test fun runTest() { +fun box(): String { val str1 = "" val str2 = "hello".subSequence(2, 2) - println(str1 == str2) - println(str1 === str2) + if(!(str1 == str2)) + return "FAIL ==" + if(!(str1 === str2)) + return "FAIL ===" + + return "OK" } diff --git a/native/native.tests/testData/runtime/basic/collectReferenceFieldValues.kt b/native/native.tests/testData/runtime/basic/collectReferenceFieldValues.kt index 66d3fd1960b..ec966e3c02c 100644 --- a/native/native.tests/testData/runtime/basic/collectReferenceFieldValues.kt +++ b/native/native.tests/testData/runtime/basic/collectReferenceFieldValues.kt @@ -7,6 +7,11 @@ // As soon the issue would be fixed, please remove `&& cacheMode=NO` from next line. // IGNORE_NATIVE: gcType=NOOP && cacheMode=NO +// Ideally, this test must fail with gcType=NOOP with any cache mode. +// KT-63944: unfortunately, GC flavours are silently not switched in presence of caches. +// As soon the issue would be fixed, please remove `&& cacheMode=NO` from next line. +// IGNORE_NATIVE: gcType=NOOP && cacheMode=NO + import kotlin.native.internal.* import kotlin.test.* diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt index 3c6635afa65..4bf0637f73f 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt @@ -927,6 +927,7 @@ private fun Settings.isIgnoredWithIGNORE_BACKEND(directives: Directives): Boolea private val CACHE_MODE_NAMES = CacheMode.Alias.entries.map { it.name } private val TEST_MODE_NAMES = TestMode.entries.map { it.name } private val OPTIMIZATION_MODE_NAMES = OptimizationMode.entries.map { it.name } +private val GC_TYPE_NAMES = GCType.entries.map { it.name } private fun Settings.isIgnoredWithIGNORE_NATIVE( directives: Directives, @@ -951,6 +952,7 @@ private fun Settings.isIgnoredWithIGNORE_NATIVE( ClassLevelProperty.TEST_MODE.shortName -> get().name to TEST_MODE_NAMES ClassLevelProperty.OPTIMIZATION_MODE.shortName -> get().name to OPTIMIZATION_MODE_NAMES ClassLevelProperty.TEST_TARGET.shortName -> get().testTarget.name to null + ClassLevelProperty.GC_TYPE.shortName -> get().name to GC_TYPE_NAMES else -> throw AssertionError("ClassLevelProperty name: $propName is not yet supported in IGNORE_NATIVE* test directives.") } val valueFromTestDirective = matchResult.groups[2]?.value!!