[Native][Tests] Extract more common code
* modulemap files are required for Swift export integration tests * we are going to reuse legacy test infrastructure for now
This commit is contained in:
+2
-18
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestExecutable
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestRunCheck
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestRunChecks
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.*
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.support.util.createTestProvider
|
||||
import org.jetbrains.kotlin.native.executors.runProcess
|
||||
import org.jetbrains.kotlin.test.KtAssert.fail
|
||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
|
||||
@@ -453,24 +454,7 @@ abstract class FrameworkTestBase : AbstractNativeSimpleTest() {
|
||||
swiftExtraOpts: List<String>,
|
||||
): TestCompilationResult.Success<out TestCompilationArtifact.Executable> {
|
||||
// create a test provider and get main entry point
|
||||
val provider = buildDir.resolve("provider.swift")
|
||||
FileWriter(provider).use { writer ->
|
||||
val providers = testSources
|
||||
.map { file ->
|
||||
file.name.toString().removeSuffix(".swift").replaceFirstChar { it.uppercase() }
|
||||
}
|
||||
.map { "${it}Tests" }
|
||||
|
||||
writer.write(
|
||||
"""
|
||||
|// THIS IS AUTOGENERATED FILE
|
||||
|// This method is invoked by the main routine to get a list of tests
|
||||
|func registerProviders() {
|
||||
| ${providers.joinToString("\n ") { "$it()" }}
|
||||
|}
|
||||
""".trimMargin()
|
||||
)
|
||||
}
|
||||
val provider = createTestProvider(buildDir, testSources)
|
||||
val frameworkOpts = listOf(
|
||||
"-Xlinker", "-rpath", "-Xlinker", "@executable_path/Frameworks",
|
||||
"-Xlinker", "-rpath", "-Xlinker", buildDir.absolutePath,
|
||||
|
||||
+2
-9
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.konan.target.AppleConfigurables
|
||||
import org.jetbrains.kotlin.konan.target.withOSVersion
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.invokeSwiftC
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.configurables
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.support.util.createModuleMap
|
||||
import org.jetbrains.kotlin.utils.fileUtils.withReplacedExtensionOrNull
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assumptions
|
||||
@@ -53,15 +54,7 @@ abstract class SwiftTypeCheckBaseTest : AbstractNativeSimpleTest() {
|
||||
val configs = testRunSettings.configurables as AppleConfigurables
|
||||
val swiftTarget = configs.targetTriple.withOSVersion(configs.osVersionMin).toString()
|
||||
|
||||
val bridgeModuleFile = buildDir.resolve("module.modulemap").apply {
|
||||
writeText("""
|
||||
module KotlinBridges {
|
||||
umbrella header "${cHeader.absolutePath}"
|
||||
export *
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
val bridgeModuleFile = createModuleMap(buildDir, cHeader)
|
||||
|
||||
val args = listOf(
|
||||
"-typecheck", swiftFile.absolutePath,
|
||||
|
||||
+13
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.konan.target.ClangArgs
|
||||
import org.jetbrains.kotlin.konan.target.Family
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.AbstractNativeSimpleTest
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.buildDir
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.support.LoggedData
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.TestCompilationArtifact
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.TestCompilationResult
|
||||
@@ -116,4 +117,16 @@ internal class ClangParameters(
|
||||
appendLine("- $it")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun createModuleMap(directory: File, umbrellaHeader: File): File {
|
||||
return directory.resolve("module.modulemap").apply {
|
||||
writeText("""
|
||||
module KotlinBridges {
|
||||
umbrella header "${umbrellaHeader.absolutePath}"
|
||||
export *
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2024 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.support.util
|
||||
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.buildDir
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
|
||||
internal fun createTestProvider(parentDirectory: File, testSources: List<File>): File {
|
||||
// create a test provider and get main entry point
|
||||
val provider = parentDirectory.resolve("provider.swift")
|
||||
FileWriter(provider).use { writer ->
|
||||
val providers = testSources
|
||||
.map { file ->
|
||||
file.name.toString().removeSuffix(".swift").replaceFirstChar { it.uppercase() }
|
||||
}
|
||||
.map { "${it}Tests" }
|
||||
|
||||
writer.write(
|
||||
"""
|
||||
|// THIS IS AUTOGENERATED FILE
|
||||
|// This method is invoked by the main routine to get a list of tests
|
||||
|func registerProviders() {
|
||||
| ${providers.joinToString("\n ") { "$it()" }}
|
||||
|}
|
||||
""".trimMargin()
|
||||
)
|
||||
}
|
||||
return provider
|
||||
}
|
||||
Reference in New Issue
Block a user