diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index 07707d34688..6653b70fede 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java @@ -6292,6 +6292,16 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/exceptions"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + } } @Nested diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java index bc0d04e92bb..7fa801b292d 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java @@ -6292,6 +6292,16 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/exceptions"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + } } @Nested diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index 21694596999..bd7fd05c9d2 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java @@ -6292,6 +6292,16 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/exceptions"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + } } @Nested diff --git a/compiler/testData/codegen/box/cinterop/basics/3.kt b/compiler/testData/codegen/box/cinterop/basics/3.kt index 650aff9f5d6..3e2c7d53054 100644 --- a/compiler/testData/codegen/box/cinterop/basics/3.kt +++ b/compiler/testData/codegen/box/cinterop/basics/3.kt @@ -4,14 +4,14 @@ */ // TARGET_BACKEND: NATIVE // MODULE: cinterop -// FILE: cstdlib_3.def +// FILE: cstdlib.def headers = stdlib.h // MODULE: main(cinterop) // FILE: main.kt @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) -import cstdlib_3.* +import cstdlib.* import kotlinx.cinterop.* import kotlin.test.* diff --git a/compiler/testData/codegen/box/cinterop/packages/dotFnameNested1.kt b/compiler/testData/codegen/box/cinterop/packages/dotFnameNested1.kt new file mode 100644 index 00000000000..fe6cd9fcc40 --- /dev/null +++ b/compiler/testData/codegen/box/cinterop/packages/dotFnameNested1.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2010-2024 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. + */ +// TARGET_BACKEND: NATIVE +// MODULE: cinterop +// FILE: part1.part2.def +package package1 +--- +#define OK_STRING "OK" + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) +import package1.* + +fun box(): String = OK_STRING diff --git a/compiler/testData/codegen/box/cinterop/packages/dotFnameNested2.kt b/compiler/testData/codegen/box/cinterop/packages/dotFnameNested2.kt new file mode 100644 index 00000000000..5a5568897d3 --- /dev/null +++ b/compiler/testData/codegen/box/cinterop/packages/dotFnameNested2.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2010-2024 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. + */ +// TARGET_BACKEND: NATIVE +// MODULE: cinterop +// FILE: filename1.filename2.def +package package1.package2 +--- +#define OK_STRING "OK" + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) +import package1.package2.* + +fun box(): String = OK_STRING diff --git a/compiler/testData/codegen/box/cinterop/packages/dotFnameRoot.kt b/compiler/testData/codegen/box/cinterop/packages/dotFnameRoot.kt new file mode 100644 index 00000000000..f156a36e155 --- /dev/null +++ b/compiler/testData/codegen/box/cinterop/packages/dotFnameRoot.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2010-2024 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. + */ +// TARGET_BACKEND: NATIVE +// MODULE: cinterop +// FILE: root1.root2.def +--- +#define OK_STRING "OK" + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) +import root2.root1.* + +fun box(): String = OK_STRING diff --git a/compiler/testData/codegen/box/cinterop/packages/nested1.kt b/compiler/testData/codegen/box/cinterop/packages/nested1.kt new file mode 100644 index 00000000000..17a869fc025 --- /dev/null +++ b/compiler/testData/codegen/box/cinterop/packages/nested1.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2010-2024 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. + */ +// TARGET_BACKEND: NATIVE +// MODULE: cinterop +// FILE: packages.def +package package1 +--- +#define OK_STRING "OK" + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) +import package1.* + +fun box(): String = OK_STRING diff --git a/compiler/testData/codegen/box/cinterop/packages/nested2.kt b/compiler/testData/codegen/box/cinterop/packages/nested2.kt new file mode 100644 index 00000000000..ea5f12163f7 --- /dev/null +++ b/compiler/testData/codegen/box/cinterop/packages/nested2.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2010-2024 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. + */ +// TARGET_BACKEND: NATIVE +// MODULE: cinterop +// FILE: packages.def +package package1.package2 +--- +#define OK_STRING "OK" + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) +import package1.package2.* + +fun box(): String = OK_STRING diff --git a/compiler/testData/codegen/box/cinterop/packages/root.kt b/compiler/testData/codegen/box/cinterop/packages/root.kt new file mode 100644 index 00000000000..00a94c3b74f --- /dev/null +++ b/compiler/testData/codegen/box/cinterop/packages/root.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2010-2024 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. + */ +// TARGET_BACKEND: NATIVE +// MODULE: cinterop +// FILE: root1.def +--- +#define OK_STRING "OK" + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) +import root1.* + +fun box(): String = OK_STRING diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java index 49f1536bb80..df71c9c16a2 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java @@ -6292,6 +6292,16 @@ public class JvmAbiConsistencyTestBoxGenerated extends AbstractJvmAbiConsistency KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/exceptions"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + } } @Nested diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index a7bfb888a76..bb0ba233cf1 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -6058,6 +6058,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/exceptions"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + } } @Nested diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 9cc1aeebb68..effc9708e2d 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -6292,6 +6292,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/exceptions"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + } } @Nested diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index cabaf71b682..7dff2047bd8 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java @@ -6292,6 +6292,16 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/exceptions"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + } } @Nested diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 86ab8fd4f55..3dd17f3b335 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -5509,6 +5509,19 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/exceptions"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } } + + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Packages extends AbstractLightAnalysisModeTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + } } @TestMetadata("compiler/testData/codegen/box/classLiteral") diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java index 9801dcd2b50..06c7e67040a 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java @@ -4630,6 +4630,16 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/exceptions"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); + } + } } @Nested diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6CodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6CodegenBoxTestGenerated.java index 88ad2d45cc1..6c36924fc74 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6CodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6CodegenBoxTestGenerated.java @@ -4630,6 +4630,16 @@ public class FirJsES6CodegenBoxTestGenerated extends AbstractFirJsES6CodegenBoxT KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/exceptions"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true); + } + } } @Nested diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index d51346f9474..71a9198b10e 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -4630,6 +4630,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/exceptions"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); + } + } } @Nested diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java index 3f7e1ca9ca3..2c66eda6f17 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java @@ -4630,6 +4630,16 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/exceptions"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true); + } + } } @Nested diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java index eeb89b236b5..1881d0b0543 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java @@ -4989,6 +4989,55 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe runTest("compiler/testData/codegen/box/cinterop/exceptions/cCallback.kt"); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + @Tag("frontend-fir") + @FirPipeline() + @UseExtTestCaseGroupProvider() + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); + } + + @Test + @TestMetadata("dotFnameNested1.kt") + public void testDotFnameNested1() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/dotFnameNested1.kt"); + } + + @Test + @TestMetadata("dotFnameNested2.kt") + public void testDotFnameNested2() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/dotFnameNested2.kt"); + } + + @Test + @TestMetadata("dotFnameRoot.kt") + public void testDotFnameRoot() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/dotFnameRoot.kt"); + } + + @Test + @TestMetadata("nested1.kt") + public void testNested1() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/nested1.kt"); + } + + @Test + @TestMetadata("nested2.kt") + public void testNested2() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/nested2.kt"); + } + + @Test + @TestMetadata("root.kt") + public void testRoot() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/root.kt"); + } + } } @Nested diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java index e9a78cb9cdb..2ccabb64bb4 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java @@ -5103,6 +5103,57 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB runTest("compiler/testData/codegen/box/cinterop/exceptions/cCallback.kt"); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + @Tag("frontend-fir") + @FirPipeline() + @UseExtTestCaseGroupProvider() + @UsePartialLinkage(mode = Mode.DISABLED) + @Tag("no-partial-linkage-may-be-skipped") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); + } + + @Test + @TestMetadata("dotFnameNested1.kt") + public void testDotFnameNested1() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/dotFnameNested1.kt"); + } + + @Test + @TestMetadata("dotFnameNested2.kt") + public void testDotFnameNested2() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/dotFnameNested2.kt"); + } + + @Test + @TestMetadata("dotFnameRoot.kt") + public void testDotFnameRoot() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/dotFnameRoot.kt"); + } + + @Test + @TestMetadata("nested1.kt") + public void testNested1() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/nested1.kt"); + } + + @Test + @TestMetadata("nested2.kt") + public void testNested2() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/nested2.kt"); + } + + @Test + @TestMetadata("root.kt") + public void testRoot() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/root.kt"); + } + } } @Nested diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java index a2f7fdf0a33..966c9c04790 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java @@ -4875,6 +4875,53 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/cinterop/exceptions/cCallback.kt"); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + @UseExtTestCaseGroupProvider() + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); + } + + @Test + @TestMetadata("dotFnameNested1.kt") + public void testDotFnameNested1() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/dotFnameNested1.kt"); + } + + @Test + @TestMetadata("dotFnameNested2.kt") + public void testDotFnameNested2() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/dotFnameNested2.kt"); + } + + @Test + @TestMetadata("dotFnameRoot.kt") + public void testDotFnameRoot() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/dotFnameRoot.kt"); + } + + @Test + @TestMetadata("nested1.kt") + public void testNested1() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/nested1.kt"); + } + + @Test + @TestMetadata("nested2.kt") + public void testNested2() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/nested2.kt"); + } + + @Test + @TestMetadata("root.kt") + public void testRoot() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/root.kt"); + } + } } @Nested diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java index 72ba20611f5..9168084c4d2 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java @@ -4990,6 +4990,55 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT runTest("compiler/testData/codegen/box/cinterop/exceptions/cCallback.kt"); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + @UseExtTestCaseGroupProvider() + @UsePartialLinkage(mode = Mode.DISABLED) + @Tag("no-partial-linkage-may-be-skipped") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); + } + + @Test + @TestMetadata("dotFnameNested1.kt") + public void testDotFnameNested1() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/dotFnameNested1.kt"); + } + + @Test + @TestMetadata("dotFnameNested2.kt") + public void testDotFnameNested2() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/dotFnameNested2.kt"); + } + + @Test + @TestMetadata("dotFnameRoot.kt") + public void testDotFnameRoot() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/dotFnameRoot.kt"); + } + + @Test + @TestMetadata("nested1.kt") + public void testNested1() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/nested1.kt"); + } + + @Test + @TestMetadata("nested2.kt") + public void testNested2() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/nested2.kt"); + } + + @Test + @TestMetadata("root.kt") + public void testRoot() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/packages/root.kt"); + } + } } @Nested diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/CinteropPackagesTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/CinteropPackagesTest.kt new file mode 100644 index 00000000000..f5cd57c7502 --- /dev/null +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/CinteropPackagesTest.kt @@ -0,0 +1,80 @@ +/* + * Copyright 2010-2023 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. + */ + +package org.jetbrains.kotlin.konan.test.blackbox + +import org.jetbrains.kotlin.konan.test.blackbox.support.TestCase +import org.jetbrains.kotlin.konan.test.blackbox.support.TestCompilerArgs +import org.jetbrains.kotlin.konan.test.blackbox.support.TestDirectives +import org.jetbrains.kotlin.konan.test.blackbox.support.TestKind +import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.TestCompilationResult.Companion.assertSuccess +import org.junit.jupiter.api.Test +import java.io.File +import kotlin.test.assertNotNull +import kotlin.test.assertNull +import kotlin.test.assertTrue + +// Compile .def and .kt files in most straightforward way to check the structure of packages created by `cinterop` tool into interop klib. +// Same test sources are also checked with new native test infra using its package renaming feature. +class CInteropPackagesTest : AbstractNativeSimpleTest() { + @Test + fun testAllTestSourcesInCinteropPackages() { + val testSources = File(TEST_DATA_DIR).listFiles() + assertTrue(testSources.isNotEmpty()) + + testSources.forEach { testSource -> + val lines = testSource.readLines() + val testCaseBuildDir = buildDir.resolve(testSource.name) + testCaseBuildDir.mkdirs() + var output_file: File? = null + val generatedFilesByExtension = mutableMapOf() + lines.forEach { line -> + val prefix = "// ${TestDirectives.FILE}: " + if (line.startsWith(prefix)) { + output_file = testCaseBuildDir.resolve(line.removePrefix(prefix)) + val extension = line.substringAfterLast(".") + assertNull( + generatedFilesByExtension[extension], + "Test source ${testSource.absolutePath} must contain only one directive `// ${TestDirectives.FILE}: `" + ) + generatedFilesByExtension[extension] = output_file!! + } else { + output_file?.appendText("$line\n") + } + } + val defFile = generatedFilesByExtension["def"] + assertNotNull( + defFile, + "Test source ${testSource.absolutePath} must contain directive `// ${TestDirectives.FILE}: `" + ) + val ktFile = generatedFilesByExtension["kt"] + assertNotNull( + ktFile, + "Test source ${testSource.absolutePath} must contain directive `// ${TestDirectives.FILE}: `" + ) + ktFile.appendText("fun main() { box() }") + + val library = cinteropToLibrary( + targets = targets, + defFile = defFile, + outputDir = buildDir, + freeCompilerArgs = TestCompilerArgs.EMPTY + ).assertSuccess().resultingArtifact + + compileToExecutable( + generateTestCaseWithSingleFile( + sourceFile = ktFile, + testKind = TestKind.STANDALONE_NO_TR, + extras = TestCase.NoTestRunnerExtras("main") + ), + library.asLibraryDependency() + ).assertSuccess() + } + } + + companion object { + private const val TEST_DATA_DIR = "compiler/testData/codegen/box/cinterop/packages" + } +} 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 000c7b562e3..14db7c23cc5 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 @@ -258,8 +258,6 @@ private class ExtTestDataFile( basePackageName.child(oldPackageName) } - val packagesOfDefFiles = defFiles.map { Name.identifier(it.name.removeSuffix(".def")) } - filesToTransform.forEach { handler -> handler.accept(object : KtVisitor>() { override fun visitKtElement(element: KtElement, parentAccessibleDeclarationNames: Set) { @@ -273,24 +271,26 @@ private class ExtTestDataFile( val oldPackageDirective = file.packageDirective val oldPackageName = oldPackageDirective?.fqName ?: FqName.ROOT - val newPackageName = oldToNewPackageNameMapping.getValue(oldPackageName) + val newPackageName = oldToNewPackageNameMapping.getValue(file.packageFqNameForKLib) val newPackageDirective = handler.psiFactory.createPackageDirective(newPackageName) if (oldPackageDirective != null) { // Replace old package directive by the new one. - oldPackageDirective.replace(newPackageDirective).ensureSurroundedByWhiteSpace() + oldPackageDirective.replace(newPackageDirective).ensureSurroundedByNewLines() } else { // Insert the package directive immediately after file-level annotations. - file.addAfter(newPackageDirective, file.fileAnnotationList).ensureSurroundedByWhiteSpace() + file.addAfter(newPackageDirective, file.fileAnnotationList).ensureSurroundedByNewLines() } - // Add @ReflectionPackageName annotation to make the compiler use original package name in the reflective information. - val annotationText = - "kotlin.native.internal.ReflectionPackageName(${oldPackageName.asString().quoteAsKotlinStringLiteral()})" - val fileAnnotationList = handler.psiFactory.createFileAnnotationListWithAnnotation(annotationText) - file.addAnnotations(fileAnnotationList) + if (!file.name.endsWith(".def")) { // don't process .def file contents after package directive + // Add @ReflectionPackageName annotation to make the compiler use original package name in the reflective information. + val annotationText = + "kotlin.native.internal.ReflectionPackageName(${oldPackageName.asString().quoteAsKotlinStringLiteral()})" + val fileAnnotationList = handler.psiFactory.createFileAnnotationListWithAnnotation(annotationText) + file.addAnnotations(fileAnnotationList) - visitKtElement(file, file.collectAccessibleDeclarationNames()) + visitKtElement(file, file.collectAccessibleDeclarationNames()) + } } override fun visitPackageDirective(directive: KtPackageDirective, unused: Set) = Unit @@ -303,7 +303,6 @@ private class ExtTestDataFile( || importedFqName.startsWith(KOTLINX_PACKAGE_NAME) || importedFqName.startsWith(HELPERS_PACKAGE_NAME) || importedFqName.startsWith(CNAMES_PACKAGE_NAME) - || packagesOfDefFiles.any { importedFqName.startsWith(it) } ) { return } @@ -457,11 +456,11 @@ private class ExtTestDataFile( if (oldFileAnnotationList != null) { // Add new annotations to the old ones. fileAnnotationList.annotationEntries.forEach { - oldFileAnnotationList.add(it).ensureSurroundedByWhiteSpace() + oldFileAnnotationList.add(it).ensureSurroundedByNewLines() } } else { // Insert the annotations list immediately before package directive. - this.addBefore(fileAnnotationList, packageDirective).ensureSurroundedByWhiteSpace() + this.addBefore(fileAnnotationList, packageDirective).ensureSurroundedByNewLines() } } @@ -626,12 +625,11 @@ private class ExtTestDataFileStructureFactory(parentDisposable: Disposable) : Te val directives: Directives get() = filesAndModules.directives - val defFiles: List = filesAndModules.parsedFiles.filter { it.key.name.endsWith(".def") }.map { it.value } val filesToTransform: Iterable - get() = filesAndModules.parsedFiles.filter { it.key.name.endsWith(".kt") } + get() = filesAndModules.parsedFiles.filter { it.key.name.endsWith(".kt") || it.key.name.endsWith(".def") } .map { (extTestFile, psiFile) -> object : CurrentFileHandler { - override val packageFqName get() = psiFile.packageFqName + override val packageFqName get() = psiFile.packageFqNameForKLib override val module = object : CurrentFileHandler.ModuleHandler { override fun markAsMain() { extTestFile.module.isMain = true @@ -974,3 +972,15 @@ private fun Settings.isIgnoredWithIGNORE_NATIVE( } return false } + +private val KtFile.packageFqNameForKLib: FqName + get() = when (name.substringAfterLast(".")) { + "kt" -> packageFqName + "def" -> { + // Without package directive, CInterop tool puts declarations to a package with kinda odd name, as such: + // name of .def file without extension, splitted by dot-separated parts, and reversed. + if (packageFqName != FqName.ROOT) packageFqName + else FqName.fromSegments(name.removeSuffix(".def").split(".").reversed()) + } + else -> TODO("File extension is not yet supported: $name") + } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/util/PsiTransformation.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/util/PsiTransformation.kt index b2053afbc13..e408194b773 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/util/PsiTransformation.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/util/PsiTransformation.kt @@ -11,21 +11,21 @@ import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.psiUtil.nextLeaf import org.jetbrains.kotlin.psi.psiUtil.prevLeaf -internal fun PsiElement.ensureSurroundedByWhiteSpace(): PsiElement = - ensureHasWhiteSpaceBefore().ensureHasWhiteSpaceAfter() +internal fun PsiElement.ensureSurroundedByNewLines(): PsiElement = + ensureHasNewLineBefore().ensureHasNewLineAfter() -private fun PsiElement.ensureHasWhiteSpaceBefore(): PsiElement { +private fun PsiElement.ensureHasNewLineBefore(): PsiElement { val (fileBoundaryReached, whiteSpaceBefore) = whiteSpaceBefore() - if (!fileBoundaryReached and !whiteSpaceBefore.endsWith(" ")) { - parent.addBefore(KtPsiFactory(project).createWhiteSpace(" "), this) + if (!fileBoundaryReached and !whiteSpaceBefore.endsWith("\n")) { + parent.addBefore(KtPsiFactory(project).createWhiteSpace("\n"), this) } return this } -private fun PsiElement.ensureHasWhiteSpaceAfter(): PsiElement { +private fun PsiElement.ensureHasNewLineAfter(): PsiElement { val (fileBoundaryReached, whiteSpaceAfter) = whiteSpaceAfter() - if (!fileBoundaryReached and !whiteSpaceAfter.startsWith(" ")) { - parent.addAfter(KtPsiFactory(project).createWhiteSpace(" "), this) + if (!fileBoundaryReached and !whiteSpaceAfter.startsWith("\n")) { + parent.addAfter(KtPsiFactory(project).createWhiteSpace("\n"), this) } return this } diff --git a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmCodegenBoxTestGenerated.java b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmCodegenBoxTestGenerated.java index 0a17ef0775d..cfa1ac1408c 100644 --- a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmCodegenBoxTestGenerated.java +++ b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmCodegenBoxTestGenerated.java @@ -4612,6 +4612,16 @@ public class FirWasmCodegenBoxTestGenerated extends AbstractFirWasmCodegenBoxTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/exceptions"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); + } + } } @Nested diff --git a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java index 457af149f23..f034abdfb56 100644 --- a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java +++ b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java @@ -4612,6 +4612,16 @@ public class K1WasmCodegenBoxTestGenerated extends AbstractK1WasmCodegenBoxTest KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/exceptions"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); } } + + @Nested + @TestMetadata("compiler/testData/codegen/box/cinterop/packages") + @TestDataPath("$PROJECT_ROOT") + public class Packages { + @Test + public void testAllFilesPresentInPackages() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/packages"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); + } + } } @Nested