diff --git a/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues.kt b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues.kt deleted file mode 100644 index ec966e3c02c..00000000000 --- a/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues.kt +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ -// 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 - -// 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.* - -value class BoxInt(val x: Int) -value class BoxBoxInt(val x: BoxInt) -data class A(val x: Int) -value class BoxA(val x: A) -value class BoxBoxA(val x: BoxA) - - -class X( - val a: Int, - val b: List, - val c: IntArray, - val d: Array, - val e: Array, - val f: BoxInt, - val g: BoxBoxInt, - val h: A, - val i: BoxA, - val j: BoxBoxA, - val k: Any?, - val l: Any?, - val m: Any?, - val n: Any?, - val o: IntArray? -) { - val p by lazy { 1 } - lateinit var q: IntArray - lateinit var r: IntArray -} - -fun `big class with mixed values`() { - val lst = listOf(1, 2, 3) - val ia = intArrayOf(1, 2, 3) - val ia2 = intArrayOf(3, 4, 5) - val ai = arrayOf(1, 2, 3) - val astr: Array = arrayOf("123", "456", 1, 2, 3) - val bi = BoxInt(2) - val bbi = BoxBoxInt(BoxInt(3)) - val a1 = A(1) - val a2 = A(2) - val a3 = A(3) - val a6 = A(3) - val x = X( - 1, lst, ia, ai, astr, bi, bbi, - a1, BoxA(a2), BoxBoxA(BoxA(a3)), - 4, BoxInt(5), BoxA(a6), null, null - ) - x.r = ia2 - val fields = x.collectReferenceFieldValues() - assertEquals(12, fields.size) - // not using assertContains because of === - assertTrue(fields.any { it === lst }, "Should contain list $lst") - assertTrue(fields.any { it === ia }, "Should contain int array $ia") - assertTrue(fields.any { it === ia2 }, "Should contain int array $ia2") - assertTrue(fields.any { it === ai }, "Should contain array of int $ai") - assertTrue(fields.any { it === astr }, "Should contain array of string $astr") - assertTrue(fields.any { it === a1 }, "Should contain A(1)") - assertTrue(fields.any { it === a2 }, "Should contain A(2)") - assertTrue(fields.any { it === a3 }, "Should contain A(3)") - assertTrue(fields.any { it.toString().startsWith("Lazy value not initialized yet") }, "Should contain lazy delegate") - assertContains(fields, 4) - assertContains(fields, BoxInt(5)) - assertContains(fields, BoxA(a6))} - -fun `call on primitive`() { - assertEquals(1.collectReferenceFieldValues(), emptyList()) - assertEquals(123456.collectReferenceFieldValues(), emptyList()) -} - -fun `call on value over primitive class`() { - assertEquals(BoxInt(1).collectReferenceFieldValues(), emptyList()) - assertEquals(BoxBoxInt(BoxInt(1)).collectReferenceFieldValues(), emptyList()) -} - -fun `call on value class`() { - val a1 = A(1) - assertEquals(BoxA(a1).collectReferenceFieldValues(), listOf(a1)) - assertEquals(BoxBoxA(BoxA(a1)).collectReferenceFieldValues(), listOf(a1)) -} - -fun `call on String`() { - assertEquals("1234".collectReferenceFieldValues(), emptyList()) - assertEquals("".collectReferenceFieldValues(), emptyList()) -} - -fun `call on primitive array`() { - assertEquals(intArrayOf(1, 2, 3).collectReferenceFieldValues(), emptyList()) - assertEquals(intArrayOf().collectReferenceFieldValues(), emptyList()) -} - -fun `call on array`() { - assertEquals(arrayOf(1, 2, 3).collectReferenceFieldValues(), listOf(1, 2, 3)) - assertEquals(arrayOf(null, "10", null, 3).collectReferenceFieldValues(), listOf("10", 3)) - assertEquals(arrayOf().collectReferenceFieldValues(), emptyList()) - assertEquals(emptyArray().collectReferenceFieldValues(), emptyList()) - assertEquals(emptyArray().collectReferenceFieldValues(), emptyList()) -} - -fun box(): String { - `big class with mixed values`() - `call on value over primitive class`() - `call on primitive`() - `call on array`() - `call on String`() - `call on value class`() - `call on primitive array`() - - return "OK" -} diff --git a/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/bigClassWithMixedValues.kt b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/bigClassWithMixedValues.kt new file mode 100644 index 00000000000..618ec89b3e1 --- /dev/null +++ b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/bigClassWithMixedValues.kt @@ -0,0 +1,73 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +import kotlin.native.internal.* +import kotlin.test.* + +value class BoxInt(val x: Int) +value class BoxBoxInt(val x: BoxInt) +data class A(val x: Int) +value class BoxA(val x: A) +value class BoxBoxA(val x: BoxA) + + +class X( + val a: Int, + val b: List, + val c: IntArray, + val d: Array, + val e: Array, + val f: BoxInt, + val g: BoxBoxInt, + val h: A, + val i: BoxA, + val j: BoxBoxA, + val k: Any?, + val l: Any?, + val m: Any?, + val n: Any?, + val o: IntArray? +) { + val p by lazy { 1 } + lateinit var q: IntArray + lateinit var r: IntArray +} + +fun box(): String { + val lst = listOf(1, 2, 3) + val ia = intArrayOf(1, 2, 3) + val ia2 = intArrayOf(3, 4, 5) + val ai = arrayOf(1, 2, 3) + val astr: Array = arrayOf("123", "456", 1, 2, 3) + val bi = BoxInt(2) + val bbi = BoxBoxInt(BoxInt(3)) + val a1 = A(1) + val a2 = A(2) + val a3 = A(3) + val a6 = A(3) + val x = X( + 1, lst, ia, ai, astr, bi, bbi, + a1, BoxA(a2), BoxBoxA(BoxA(a3)), + 4, BoxInt(5), BoxA(a6), null, null + ) + x.r = ia2 + val fields = x.collectReferenceFieldValues() + assertEquals(12, fields.size) + // not using assertContains because of === + assertTrue(fields.any { it === lst }, "Should contain list $lst") + assertTrue(fields.any { it === ia }, "Should contain int array $ia") + assertTrue(fields.any { it === ia2 }, "Should contain int array $ia2") + assertTrue(fields.any { it === ai }, "Should contain array of int $ai") + assertTrue(fields.any { it === astr }, "Should contain array of string $astr") + assertTrue(fields.any { it === a1 }, "Should contain A(1)") + assertTrue(fields.any { it === a2 }, "Should contain A(2)") + assertTrue(fields.any { it === a3 }, "Should contain A(3)") + assertTrue(fields.any { it.toString().startsWith("Lazy value not initialized yet") }, "Should contain lazy delegate") + assertContains(fields, 4) + assertContains(fields, BoxInt(5)) + assertContains(fields, BoxA(a6)) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnArray.kt b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnArray.kt new file mode 100644 index 00000000000..4d1107df376 --- /dev/null +++ b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnArray.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +import kotlin.native.internal.* +import kotlin.test.* + +fun box(): String { + assertEquals(arrayOf(1, 2, 3).collectReferenceFieldValues(), listOf(1, 2, 3)) + assertEquals(arrayOf(null, "10", null, 3).collectReferenceFieldValues(), listOf("10", 3)) + assertEquals(arrayOf().collectReferenceFieldValues(), emptyList()) + assertEquals(emptyArray().collectReferenceFieldValues(), emptyList()) + assertEquals(emptyArray().collectReferenceFieldValues(), emptyList()) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnPrimitive.kt b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnPrimitive.kt new file mode 100644 index 00000000000..986a1b0bd5d --- /dev/null +++ b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnPrimitive.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +import kotlin.native.internal.* +import kotlin.test.* + +fun box(): String { + assertEquals(1.collectReferenceFieldValues(), emptyList()) + assertEquals(123456.collectReferenceFieldValues(), emptyList()) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnPrimitiveArray.kt b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnPrimitiveArray.kt new file mode 100644 index 00000000000..ece8e5ef2e1 --- /dev/null +++ b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnPrimitiveArray.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +import kotlin.native.internal.* +import kotlin.test.* + +fun box(): String { + assertEquals(intArrayOf(1, 2, 3).collectReferenceFieldValues(), emptyList()) + assertEquals(intArrayOf().collectReferenceFieldValues(), emptyList()) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnString.kt b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnString.kt new file mode 100644 index 00000000000..5fc0f506980 --- /dev/null +++ b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnString.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +import kotlin.native.internal.* +import kotlin.test.* + +fun box(): String { + assertEquals("1234".collectReferenceFieldValues(), emptyList()) + assertEquals("".collectReferenceFieldValues(), emptyList()) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnValueClass.kt b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnValueClass.kt new file mode 100644 index 00000000000..a210873fe8b --- /dev/null +++ b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnValueClass.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +import kotlin.native.internal.* +import kotlin.test.* + +data class A(val x: Int) +value class BoxA(val x: A) +value class BoxBoxA(val x: BoxA) + +fun box(): String { + val a1 = A(1) + assertEquals(BoxA(a1).collectReferenceFieldValues(), listOf(a1)) + assertEquals(BoxBoxA(BoxA(a1)).collectReferenceFieldValues(), listOf(a1)) + + return "OK" +} diff --git a/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnValueOverPrimitiveClass.kt b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnValueOverPrimitiveClass.kt new file mode 100644 index 00000000000..39061b247f4 --- /dev/null +++ b/native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnValueOverPrimitiveClass.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +import kotlin.native.internal.* +import kotlin.test.* + +value class BoxInt(val x: Int) +value class BoxBoxInt(val x: BoxInt) + +fun box(): String { + assertEquals(BoxInt(1).collectReferenceFieldValues(), emptyList()) + assertEquals(BoxBoxInt(BoxInt(1)).collectReferenceFieldValues(), emptyList()) + + return "OK" +} 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 f39e4a4ff83..d35fb5de1fb 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 @@ -3639,10 +3639,59 @@ public class FirNativeCodegenLocalTestGenerated extends AbstractNativeCodegenBox KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/codegen/reflection"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); } - @Test - @TestMetadata("collectReferenceFieldValues.kt") - public void testCollectReferenceFieldValues() throws Exception { - runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues.kt"); + @Nested + @TestMetadata("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues") + @TestDataPath("$PROJECT_ROOT") + @Tag("frontend-fir") + @FirPipeline() + @UseExtTestCaseGroupProvider() + public class CollectReferenceFieldValues { + @Test + public void testAllFilesPresentInCollectReferenceFieldValues() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); + } + + @Test + @TestMetadata("bigClassWithMixedValues.kt") + public void testBigClassWithMixedValues() throws Exception { + runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/bigClassWithMixedValues.kt"); + } + + @Test + @TestMetadata("callOnArray.kt") + public void testCallOnArray() throws Exception { + runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnArray.kt"); + } + + @Test + @TestMetadata("callOnPrimitive.kt") + public void testCallOnPrimitive() throws Exception { + runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnPrimitive.kt"); + } + + @Test + @TestMetadata("callOnPrimitiveArray.kt") + public void testCallOnPrimitiveArray() throws Exception { + runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnPrimitiveArray.kt"); + } + + @Test + @TestMetadata("callOnString.kt") + public void testCallOnString() throws Exception { + runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnString.kt"); + } + + @Test + @TestMetadata("callOnValueClass.kt") + public void testCallOnValueClass() throws Exception { + runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnValueClass.kt"); + } + + @Test + @TestMetadata("callOnValueOverPrimitiveClass.kt") + public void testCallOnValueOverPrimitiveClass() throws Exception { + runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnValueOverPrimitiveClass.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 50208d64308..38eb0eaa0bf 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 @@ -3545,10 +3545,57 @@ public class NativeCodegenLocalTestGenerated extends AbstractNativeCodegenBoxTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/codegen/reflection"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); } - @Test - @TestMetadata("collectReferenceFieldValues.kt") - public void testCollectReferenceFieldValues() throws Exception { - runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues.kt"); + @Nested + @TestMetadata("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues") + @TestDataPath("$PROJECT_ROOT") + @UseExtTestCaseGroupProvider() + public class CollectReferenceFieldValues { + @Test + public void testAllFilesPresentInCollectReferenceFieldValues() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); + } + + @Test + @TestMetadata("bigClassWithMixedValues.kt") + public void testBigClassWithMixedValues() throws Exception { + runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/bigClassWithMixedValues.kt"); + } + + @Test + @TestMetadata("callOnArray.kt") + public void testCallOnArray() throws Exception { + runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnArray.kt"); + } + + @Test + @TestMetadata("callOnPrimitive.kt") + public void testCallOnPrimitive() throws Exception { + runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnPrimitive.kt"); + } + + @Test + @TestMetadata("callOnPrimitiveArray.kt") + public void testCallOnPrimitiveArray() throws Exception { + runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnPrimitiveArray.kt"); + } + + @Test + @TestMetadata("callOnString.kt") + public void testCallOnString() throws Exception { + runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnString.kt"); + } + + @Test + @TestMetadata("callOnValueClass.kt") + public void testCallOnValueClass() throws Exception { + runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnValueClass.kt"); + } + + @Test + @TestMetadata("callOnValueOverPrimitiveClass.kt") + public void testCallOnValueOverPrimitiveClass() throws Exception { + runTest("native/native.tests/testData/codegen/reflection/collectReferenceFieldValues/callOnValueOverPrimitiveClass.kt"); + } } }