[K/N][Tests] Migrate test withSpaces.kt
^KT-61259
This commit is contained in:
committed by
Space Team
parent
2bb9b936ac
commit
06a89a0061
@@ -929,29 +929,6 @@ tasks.register("driver_opt", KonanDriverTest) {
|
|||||||
flags = ["-opt"]
|
flags = ["-opt"]
|
||||||
}
|
}
|
||||||
|
|
||||||
def generateWithSpaceDefFile() {
|
|
||||||
def buildDirectory = project.layout.buildDirectory.get().asFile
|
|
||||||
def mapOption = "--Map \"$buildDirectory/cutom map.map\""
|
|
||||||
if (PlatformInfo.isAppleTarget(project)) {
|
|
||||||
mapOption = "-map \"$buildDirectory/cutom map.map\""
|
|
||||||
} else if (PlatformInfo.isWindowsTarget(project)) {
|
|
||||||
mapOption = "\"-Wl,--Map,$buildDirectory/cutom map.map\""
|
|
||||||
}
|
|
||||||
|
|
||||||
buildDirectory.mkdirs()
|
|
||||||
def file = new File("${buildDirectory}/withSpaces.def")
|
|
||||||
file.write """
|
|
||||||
headers = stdio.h "${projectDir}/interop/basics/custom headers/custom.h"
|
|
||||||
linkerOpts = $mapOption
|
|
||||||
---
|
|
||||||
|
|
||||||
int customCompare(const char* str1, const char* str2) {
|
|
||||||
return custom_strcmp(str1, str2);
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
return file.absolutePath
|
|
||||||
}
|
|
||||||
|
|
||||||
// A helper method to create interop artifacts
|
// A helper method to create interop artifacts
|
||||||
void createInterop(String name, Closure conf) {
|
void createInterop(String name, Closure conf) {
|
||||||
konanArtifacts {
|
konanArtifacts {
|
||||||
@@ -1102,10 +1079,6 @@ if (PlatformInfo.isAppleTarget(project)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createInterop("withSpaces") {
|
|
||||||
it.defFile generateWithSpaceDefFile()
|
|
||||||
}
|
|
||||||
|
|
||||||
createInterop("exceptions_throwThroughBridge") {
|
createInterop("exceptions_throwThroughBridge") {
|
||||||
it.defFile "interop/exceptions/throwThroughBridge.def"
|
it.defFile "interop/exceptions/throwThroughBridge.def"
|
||||||
it.extraOpts "-Xcompile-source", "$projectDir/interop/exceptions/throwThroughBridgeInterop.cpp"
|
it.extraOpts "-Xcompile-source", "$projectDir/interop/exceptions/throwThroughBridgeInterop.cpp"
|
||||||
@@ -1182,15 +1155,6 @@ interopTest("interop_embedStaticLibraries") {
|
|||||||
interop = 'embedStaticLibraries'
|
interop = 'embedStaticLibraries'
|
||||||
}
|
}
|
||||||
|
|
||||||
interopTest("interop_withSpaces") {
|
|
||||||
interop ='withSpaces'
|
|
||||||
source = "interop/basics/withSpaces.kt"
|
|
||||||
|
|
||||||
doLast {
|
|
||||||
assert project.layout.buildDirectory.file("cutom map.map").get().asFile.exists()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dynamicTest("interop_kt43502") {
|
dynamicTest("interop_kt43502") {
|
||||||
interop = "kt43502"
|
interop = "kt43502"
|
||||||
source = "interop/kt43502/main.kt"
|
source = "interop/kt43502/main.kt"
|
||||||
|
|||||||
-1
@@ -2,7 +2,6 @@
|
|||||||
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import withSpaces.*
|
import withSpaces.*
|
||||||
+52
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.konan.test.blackbox
|
package org.jetbrains.kotlin.konan.test.blackbox
|
||||||
|
|
||||||
import com.intellij.testFramework.TestDataPath
|
import com.intellij.testFramework.TestDataPath
|
||||||
|
import org.jetbrains.kotlin.konan.target.Family
|
||||||
import org.jetbrains.kotlin.konan.target.isSimulator
|
import org.jetbrains.kotlin.konan.target.isSimulator
|
||||||
import org.jetbrains.kotlin.konan.test.blackbox.support.*
|
import org.jetbrains.kotlin.konan.test.blackbox.support.*
|
||||||
import org.jetbrains.kotlin.konan.test.blackbox.support.TestCase
|
import org.jetbrains.kotlin.konan.test.blackbox.support.TestCase
|
||||||
@@ -25,6 +26,7 @@ import org.junit.jupiter.api.Assumptions
|
|||||||
import org.junit.jupiter.api.Tag
|
import org.junit.jupiter.api.Tag
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@TestDataPath("\$PROJECT_ROOT")
|
@TestDataPath("\$PROJECT_ROOT")
|
||||||
class ClassicComplexCInteropTest : ComplexCInteropTestBase()
|
class ClassicComplexCInteropTest : ComplexCInteropTestBase()
|
||||||
@@ -138,6 +140,56 @@ abstract class ComplexCInteropTestBase : AbstractNativeSimpleTest() {
|
|||||||
runExecutableAndVerify(testCase, testExecutable)
|
runExecutableAndVerify(testCase, testExecutable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("withSpaces.kt")
|
||||||
|
fun testWithSpaces() {
|
||||||
|
val srcDir = interopDir.resolve("withSpaces")
|
||||||
|
val mapfile = buildDir.resolve("cutom map.map").also { it.delete() }
|
||||||
|
val mapOption = when {
|
||||||
|
targets.testTarget.family.isAppleFamily -> "-map \"${buildDir.absolutePath}/cutom map.map\""
|
||||||
|
targets.testTarget.family == Family.MINGW -> "\"-Wl,--Map,${buildDir.absolutePath}/cutom map.map\""
|
||||||
|
else -> "--Map \"${buildDir.absolutePath}/cutom map.map\""
|
||||||
|
}
|
||||||
|
val withSpacesDef = buildDir.resolve("withSpaces.def").also {
|
||||||
|
it.printWriter().use {
|
||||||
|
it.println(
|
||||||
|
"""
|
||||||
|
headers = stdio.h "${srcDir.absolutePath}/custom headers/custom.h"
|
||||||
|
linkerOpts = $mapOption
|
||||||
|
---
|
||||||
|
|
||||||
|
int customCompare(const char* str1, const char* str2) {
|
||||||
|
return custom_strcmp(str1, str2);
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val cinteropKlib = cinteropToLibrary(
|
||||||
|
targets = targets,
|
||||||
|
defFile = withSpacesDef,
|
||||||
|
outputDir = buildDir,
|
||||||
|
freeCompilerArgs = TestCompilerArgs.EMPTY
|
||||||
|
).assertSuccess().resultingArtifact
|
||||||
|
|
||||||
|
val testCase = generateTestCaseWithSingleFile(
|
||||||
|
sourceFile = srcDir.resolve("withSpaces.kt"),
|
||||||
|
freeCompilerArgs = TestCompilerArgs(
|
||||||
|
"-opt-in=kotlinx.cinterop.ExperimentalForeignApi",
|
||||||
|
),
|
||||||
|
testKind = TestKind.STANDALONE_NO_TR,
|
||||||
|
extras = TestCase.NoTestRunnerExtras("main"),
|
||||||
|
)
|
||||||
|
val success = compileToExecutable(testCase, cinteropKlib.asLibraryDependency()).assertSuccess()
|
||||||
|
val testExecutable = TestExecutable(
|
||||||
|
success.resultingArtifact,
|
||||||
|
success.loggedData,
|
||||||
|
listOf(TestName("interop_objc_tests"))
|
||||||
|
)
|
||||||
|
runExecutableAndVerify(testCase, testExecutable)
|
||||||
|
assertTrue(mapfile.exists())
|
||||||
|
}
|
||||||
|
|
||||||
private fun compileDylib(name: String, mSources: List<File>): TestCompilationResult.Success<out TestCompilationArtifact.Executable> {
|
private fun compileDylib(name: String, mSources: List<File>): TestCompilationResult.Success<out TestCompilationArtifact.Executable> {
|
||||||
val clangResult = compileWithClang(
|
val clangResult = compileWithClang(
|
||||||
clangDistribution = ClangDistribution.Llvm,
|
clangDistribution = ClangDistribution.Llvm,
|
||||||
|
|||||||
Reference in New Issue
Block a user