Native: prepare existing tests for cinterop adding ExperimentalForeignApi
cinterop tool should add ExperimentalForeignApi to all generated declarations by default. This commit prepares existing tests for this. ^KT-58362
This commit is contained in:
committed by
Space Team
parent
93ef98cbec
commit
3280d3ef80
@@ -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
|
||||
|
||||
|
||||
+1
-1
@@ -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),
|
||||
|
||||
+13
@@ -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"
|
||||
|
||||
+7
-1
@@ -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 = "<<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<String> = emptyList()): KLIB {
|
||||
|
||||
Reference in New Issue
Block a user