From 06a89a0061108200c9df4e3eb11c8efa06e75eed Mon Sep 17 00:00:00 2001 From: Vladimir Sukharev Date: Tue, 13 Feb 2024 10:07:59 +0100 Subject: [PATCH] [K/N][Tests] Migrate test withSpaces.kt ^KT-61259 --- .../backend.native/tests/build.gradle | 36 ------------- .../withSpaces}/custom headers/custom.h | 0 .../interop/withSpaces}/withSpaces.kt | 1 - .../test/blackbox/ComplexCInteropTest.kt | 52 +++++++++++++++++++ 4 files changed, 52 insertions(+), 37 deletions(-) rename {kotlin-native/backend.native/tests/interop/basics => native/native.tests/testData/interop/withSpaces}/custom headers/custom.h (100%) rename {kotlin-native/backend.native/tests/interop/basics => native/native.tests/testData/interop/withSpaces}/withSpaces.kt (99%) diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index a1eaed78061..a49817d4d85 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -929,29 +929,6 @@ tasks.register("driver_opt", KonanDriverTest) { 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 void createInterop(String name, Closure conf) { konanArtifacts { @@ -1102,10 +1079,6 @@ if (PlatformInfo.isAppleTarget(project)) { } } -createInterop("withSpaces") { - it.defFile generateWithSpaceDefFile() -} - createInterop("exceptions_throwThroughBridge") { it.defFile "interop/exceptions/throwThroughBridge.def" it.extraOpts "-Xcompile-source", "$projectDir/interop/exceptions/throwThroughBridgeInterop.cpp" @@ -1182,15 +1155,6 @@ interopTest("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") { interop = "kt43502" source = "interop/kt43502/main.kt" diff --git a/kotlin-native/backend.native/tests/interop/basics/custom headers/custom.h b/native/native.tests/testData/interop/withSpaces/custom headers/custom.h similarity index 100% rename from kotlin-native/backend.native/tests/interop/basics/custom headers/custom.h rename to native/native.tests/testData/interop/withSpaces/custom headers/custom.h diff --git a/kotlin-native/backend.native/tests/interop/basics/withSpaces.kt b/native/native.tests/testData/interop/withSpaces/withSpaces.kt similarity index 99% rename from kotlin-native/backend.native/tests/interop/basics/withSpaces.kt rename to native/native.tests/testData/interop/withSpaces/withSpaces.kt index 8a06281757f..15835bb0d15 100644 --- a/kotlin-native/backend.native/tests/interop/basics/withSpaces.kt +++ b/native/native.tests/testData/interop/withSpaces/withSpaces.kt @@ -2,7 +2,6 @@ * 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.* diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/ComplexCInteropTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/ComplexCInteropTest.kt index 59cb42c8a16..18e94b97b59 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/ComplexCInteropTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/ComplexCInteropTest.kt @@ -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): TestCompilationResult.Success { val clangResult = compileWithClang( clangDistribution = ClangDistribution.Llvm,