diff --git a/kotlin-native/backend.native/tests/interop/objc/kt55938/lib.kt b/kotlin-native/backend.native/tests/interop/objc/kt55938/lib.kt index 7cf158ec6c0..56025b3bf2d 100644 --- a/kotlin-native/backend.native/tests/interop/objc/kt55938/lib.kt +++ b/kotlin-native/backend.native/tests/interop/objc/kt55938/lib.kt @@ -2,6 +2,7 @@ * 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. */ +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) package kt55938lib diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropKT39120Test.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropKT39120Test.kt index a2b43515ea7..3a1d37a95d9 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropKT39120Test.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropKT39120Test.kt @@ -79,7 +79,7 @@ abstract class AbstractNativeCInteropKT39120Test : AbstractNativeCInteropBaseTes private fun filterContentsOutput(contents: String, pattern: String) = contents.split("\n").filter { it.contains(Regex(pattern)) - }.joinToString(separator = "\n") + }.joinToString(separator = "\n").replace("@ExperimentalForeignApi ", "") private fun createTestCaseNoTestRun(module: TestModule.Exclusive, compilerArgs: TestCompilerArgs) = TestCase( id = TestCaseId.Named(module.name), diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropTest.kt index 43d0f45790d..cec192dd4a2 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropTest.kt @@ -49,6 +49,12 @@ abstract class AbstractNativeCInteropTest : AbstractNativeCInteropBaseTest() { abstract val defFileName: String + // All declarations generated by cinterop now have ExperimentalForeignApi annotations. + // There is no sense in cluttering every test expected data with it, so we simply ignore it + // in the actual data by default: + open val ignoreExperimentalForeignApi: Boolean + get() = true + @Synchronized protected fun runTest(@TestDataFile testPath: String) { // FIXME: check the following failures under Android with -fmodules @@ -88,6 +94,13 @@ abstract class AbstractNativeCInteropTest : AbstractNativeCInteropBaseTest() { } } else { val klibContents = testCompilationResult.assertSuccess().resultingArtifact.getContents(kotlinNativeClassLoader.classLoader) + .let { + if (ignoreExperimentalForeignApi) { + it.replace("@ExperimentalForeignApi ", "") + } else { + it + } + } val expectedContents = goldenFile.readText() assertEquals(StringUtilRt.convertLineSeparators(expectedContents), StringUtilRt.convertLineSeparators(klibContents)) { "Test failed. CInterop compilation result was: $testCompilationResult" diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/LinkerOutputTestKT55578.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/LinkerOutputTestKT55578.kt index adab8f547bf..09abaf6d286 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/LinkerOutputTestKT55578.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/LinkerOutputTestKT55578.kt @@ -20,6 +20,8 @@ import kotlin.test.assertTrue @TestDataPath("\$PROJECT_ROOT") @EnforcedProperty(ClassLevelProperty.COMPILER_OUTPUT_INTERCEPTOR, "NONE") class LinkerOutputTestKT55578 : AbstractNativeLinkerOutputTest() { + private val defaultCompilerArguments = listOf("-opt-in=kotlinx.cinterop.ExperimentalForeignApi") + private val testDir = File("native/native.tests/testData/CInterop/KT-55578/") private val hint1 = "<>" @@ -166,7 +168,11 @@ class LinkerOutputTestKT55578 : AbstractNativeLinkerOutputTest() { files += TestFile.createCommitted(file, this) } - return compileToExecutable(module, libraries.asList().map { it.asLibraryDependency() }, extraArgs) + return compileToExecutable( + module, + libraries.asList().map { it.asLibraryDependency() }, + defaultCompilerArguments + extraArgs + ) } private fun compileKlib(defFile: File, sourceFile: File? = null, extraArgs: List = emptyList()): KLIB {