[K/N][Tests] Migrate test withSpaces.kt
^KT-61259
This commit is contained in:
committed by
Space Team
parent
2bb9b936ac
commit
06a89a0061
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int custom_strcmp(const char* str1, const char* str2) {
|
||||
return strcmp(str1, str2);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
import kotlin.test.*
|
||||
import kotlinx.cinterop.*
|
||||
import withSpaces.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
customCompare("first", "second")
|
||||
}
|
||||
+52
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.konan.test.blackbox
|
||||
|
||||
import com.intellij.testFramework.TestDataPath
|
||||
import org.jetbrains.kotlin.konan.target.Family
|
||||
import org.jetbrains.kotlin.konan.target.isSimulator
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.support.*
|
||||
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.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@TestDataPath("\$PROJECT_ROOT")
|
||||
class ClassicComplexCInteropTest : ComplexCInteropTestBase()
|
||||
@@ -138,6 +140,56 @@ abstract class ComplexCInteropTestBase : AbstractNativeSimpleTest() {
|
||||
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> {
|
||||
val clangResult = compileWithClang(
|
||||
clangDistribution = ClangDistribution.Llvm,
|
||||
|
||||
Reference in New Issue
Block a user