[K/N][test] Cinterop failures
diff --git a/native/native.tests/testData/CInterop/KT-todo-2/library.def b/native/native.tests/testData/CInterop/KT-todo-2/library.def new file mode 100644 index 0000000..23e4017 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-todo-2/library.def
@@ -0,0 +1,9 @@ +depends = Foundation +language = Objective-C + +--- + +#import "Foundation/NSObject.h" + +@interface WithClassProperty : NSObject +@end
diff --git a/native/native.tests/testData/CInterop/KT-todo-2/usage.kt b/native/native.tests/testData/CInterop/KT-todo-2/usage.kt new file mode 100644 index 0000000..a2851d2 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-todo-2/usage.kt
@@ -0,0 +1,14 @@ +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) + +import library.* +import kotlin.test.assertEquals + +class Impl : WithClassProperty() { + companion object { + fun stringProperty(): String? = "42" + } +} + +fun main() { + assertEquals("42", Impl.stringProperty()) +} \ No newline at end of file
diff --git a/native/native.tests/testData/CInterop/KT-todo-3/library.def b/native/native.tests/testData/CInterop/KT-todo-3/library.def new file mode 100644 index 0000000..7dd2664 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-todo-3/library.def
@@ -0,0 +1,7 @@ +depends = Foundation +language = Objective-C + +--- + +@interface WithClassProperty +@end
diff --git a/native/native.tests/testData/CInterop/KT-todo-3/usage.kt b/native/native.tests/testData/CInterop/KT-todo-3/usage.kt new file mode 100644 index 0000000..816085b --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-todo-3/usage.kt
@@ -0,0 +1,14 @@ +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class, kotlin.experimental.ExperimentalObjCName::class) + +import library.* +import kotlin.test.assertEquals + +class Impl : WithClassProperty() { + companion object : WithClassPropertyMeta() { + fun stringProperty(): String? = "42" + } +} + +fun main() { + assertEquals("42", Impl.stringProperty()) +} \ No newline at end of file
diff --git a/native/native.tests/testData/CInterop/KT-todo/library.def b/native/native.tests/testData/CInterop/KT-todo/library.def new file mode 100644 index 0000000..95736ce --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-todo/library.def
@@ -0,0 +1,11 @@ +depends = Foundation +language = Objective-C + +--- +#import "Foundation/NSString.h" +#import "Foundation/NSObject.h" + +@interface WithClassProperty : NSObject +-(instancetype) init; +@property (class, readonly, copy) NSString * stringProperty; +@end
diff --git a/native/native.tests/testData/CInterop/KT-todo/usage.kt b/native/native.tests/testData/CInterop/KT-todo/usage.kt new file mode 100644 index 0000000..7e40eb3 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-todo/usage.kt
@@ -0,0 +1,15 @@ +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class, kotlin.experimental.ExperimentalObjCName::class) + +import library.* +import kotlin.test.assertEquals + +@ObjCName("KotlinImplWithCompanionPropertyOverride") +class Impl : WithClassProperty() { + companion object : WithClassPropertyMeta() { + override fun stringProperty(): String? = "42" + } +} + +fun main() { + assertEquals("42", Impl.stringProperty()) +} \ No newline at end of file
diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/CInteropCheckersTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/CInteropCheckersTest.kt new file mode 100644 index 0000000..87c88cf --- /dev/null +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/CInteropCheckersTest.kt
@@ -0,0 +1,99 @@ +/* + * 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. + */ + +package org.jetbrains.kotlin.konan.test.blackbox + +import com.intellij.testFramework.TestDataPath +import org.jetbrains.kotlin.konan.test.blackbox.support.ClassLevelProperty +import org.jetbrains.kotlin.konan.test.blackbox.support.EnforcedProperty +import org.jetbrains.kotlin.konan.test.blackbox.support.TestCase +import org.jetbrains.kotlin.konan.test.blackbox.support.TestCompilerArgs +import org.jetbrains.kotlin.konan.test.blackbox.support.TestKind +import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.TestCompilationResult.Companion.assertSuccess +import org.jetbrains.kotlin.konan.test.blackbox.support.group.FirPipeline +import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestExecutable +import org.jetbrains.kotlin.konan.test.blackbox.support.settings.PipelineType +import org.jetbrains.kotlin.test.TestMetadata +import org.junit.jupiter.api.Tag +import org.junit.jupiter.api.Test +import java.io.File + +@TestDataPath("\$PROJECT_ROOT") +@EnforcedProperty(ClassLevelProperty.COMPILER_OUTPUT_INTERCEPTOR, "NONE") +abstract class BaseCInteropCheckersTest : AbstractNativeSimpleTest() { + @Test + @TestMetadata(TEST_DATA_DIR) + fun testBuilding() { + val library = cinteropToLibrary( + targets = targets, + defFile = File(TEST_DATA_DIR, DEF_FILE), + outputDir = buildDir, + freeCompilerArgs = TestCompilerArgs.EMPTY + ).assertSuccess().resultingArtifact + + val testCase = generateTestCaseWithSingleFile( + sourceFile = File(TEST_DATA_DIR, KT_FILE), + freeCompilerArgs = TestCompilerArgs(testRunSettings.get<PipelineType>().compilerFlags), + testKind = TestKind.STANDALONE_NO_TR, + extras = TestCase.NoTestRunnerExtras("main") + ) + val compilationResult = compileToExecutable(testCase, library.asLibraryDependency()).assertSuccess() + } + + @Test + @TestMetadata(TEST_DATA_DIR_2) + fun testRuntimeAssertNoLinkageIssues() { + val library = cinteropToLibrary( + targets = targets, + defFile = File(TEST_DATA_DIR_2, DEF_FILE), + outputDir = buildDir, + freeCompilerArgs = TestCompilerArgs.EMPTY + ).assertSuccess().resultingArtifact + + val testCase = generateTestCaseWithSingleFile( + sourceFile = File(TEST_DATA_DIR_2, KT_FILE), + freeCompilerArgs = TestCompilerArgs(testRunSettings.get<PipelineType>().compilerFlags), + testKind = TestKind.STANDALONE_NO_TR, + extras = TestCase.NoTestRunnerExtras("main") + ) + val compilationResult = compileToExecutable(testCase, library.asLibraryDependency()).assertSuccess() + val testExecutable = TestExecutable.fromCompilationResult(testCase, compilationResult) + // TODO: Why does it fail with `[tid#9372960] runtime assert: Objective-C class 'WithClassProperty' not found. Ensure that the containing framework or library was linked.`? + runExecutableAndVerify(testCase, testExecutable) + } + + @Test + @TestMetadata(TEST_DATA_DIR_3) + fun testNoInitLoweringError() { + val library = cinteropToLibrary( + targets = targets, + defFile = File(TEST_DATA_DIR_3, DEF_FILE), + outputDir = buildDir, + freeCompilerArgs = TestCompilerArgs.EMPTY + ).assertSuccess().resultingArtifact + + val testCase = generateTestCaseWithSingleFile( + sourceFile = File(TEST_DATA_DIR_3, KT_FILE), + freeCompilerArgs = TestCompilerArgs(testRunSettings.get<PipelineType>().compilerFlags), + testKind = TestKind.STANDALONE_NO_TR, + extras = TestCase.NoTestRunnerExtras("main") + ) + val compilationResult = compileToExecutable(testCase, library.asLibraryDependency()).assertSuccess() + } + + companion object { + const val TEST_DATA_DIR = "native/native.tests/testData/CInterop/KT-todo" + const val TEST_DATA_DIR_2 = "native/native.tests/testData/CInterop/KT-todo-2" + const val TEST_DATA_DIR_3 = "native/native.tests/testData/CInterop/KT-todo-3" + const val DEF_FILE = "library.def" + const val KT_FILE = "usage.kt" + } +} + +class CInteropCheckersTest : BaseCInteropCheckersTest() + +@FirPipeline +@Tag("frontend-fir") +class FirCInteropCheckersTest : BaseCInteropCheckersTest() \ No newline at end of file
diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt index 90a9d0b..2e7ddef 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt
@@ -539,5 +539,5 @@ internal fun Settings.getStageDependentPipelineType(): PipelineType = when (get<TestMode>()) { TestMode.ONE_STAGE_MULTI_MODULE -> get<PipelineType>() - TestMode.TWO_STAGE_MULTI_MODULE -> PipelineType.K1 // Don't pass "-language_version 2.0" to the second stage + TestMode.TWO_STAGE_MULTI_MODULE -> PipelineType.DEFAULT // Don't pass "-language_version 2.0" to the second stage }