[K/N][Tests] Patch package names also for .def files
To separate interop modules to different packages, .def files should be treated similarly to .kt files: 1) package directive should be prepended with test-specific synthetic package, or, if, absent, package directive with synthetic package should be added. 2) in .kt files, import directives and fully-qualified import from interop modules should be prepended with same test-specific synthetic package.
This commit is contained in:
committed by
Space Team
parent
55a78bf499
commit
9f2558f640
+10
@@ -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
|
||||
|
||||
+10
@@ -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
|
||||
|
||||
+10
@@ -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
|
||||
|
||||
+2
-2
@@ -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.*
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
+10
@@ -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
|
||||
|
||||
+10
@@ -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
|
||||
|
||||
+10
@@ -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
|
||||
|
||||
+10
@@ -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
|
||||
|
||||
+13
@@ -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")
|
||||
|
||||
+10
@@ -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
|
||||
|
||||
Generated
+10
@@ -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
|
||||
|
||||
+10
@@ -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
|
||||
|
||||
+10
@@ -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
|
||||
|
||||
+49
@@ -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
|
||||
|
||||
+51
@@ -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
|
||||
|
||||
+47
@@ -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
|
||||
|
||||
+49
@@ -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
|
||||
|
||||
+80
@@ -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<String, File>()
|
||||
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}: <SOMEFILE.$extension>`"
|
||||
)
|
||||
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}: <SOMEFILE.def>`"
|
||||
)
|
||||
val ktFile = generatedFilesByExtension["kt"]
|
||||
assertNotNull(
|
||||
ktFile,
|
||||
"Test source ${testSource.absolutePath} must contain directive `// ${TestDirectives.FILE}: <SOMEFILE.kt>`"
|
||||
)
|
||||
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"
|
||||
}
|
||||
}
|
||||
+27
-17
@@ -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<Unit, Set<Name>>() {
|
||||
override fun visitKtElement(element: KtElement, parentAccessibleDeclarationNames: Set<Name>) {
|
||||
@@ -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<Name>) = 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<KtFile> = filesAndModules.parsedFiles.filter { it.key.name.endsWith(".def") }.map { it.value }
|
||||
val filesToTransform: Iterable<CurrentFileHandler>
|
||||
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")
|
||||
}
|
||||
|
||||
+8
-8
@@ -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
|
||||
}
|
||||
|
||||
Generated
+10
@@ -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
|
||||
|
||||
Generated
+10
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user