From 3ea4a6a9377860cb47e939f999374fd70b2ff1e8 Mon Sep 17 00:00:00 2001 From: Vladimir Sukharev Date: Fri, 3 Nov 2023 19:55:00 +0100 Subject: [PATCH] [K/N] Add test for KT-63048, K1greenK2red ^KT-63048 --- .../testData/CInterop/KT-63048/library.def | 11 ++++ .../testData/CInterop/KT-63048/usage.kt | 15 +++++ .../test/blackbox/CInteropCheckersTest.kt | 57 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 native/native.tests/testData/CInterop/KT-63048/library.def create mode 100644 native/native.tests/testData/CInterop/KT-63048/usage.kt create mode 100644 native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/CInteropCheckersTest.kt diff --git a/native/native.tests/testData/CInterop/KT-63048/library.def b/native/native.tests/testData/CInterop/KT-63048/library.def new file mode 100644 index 00000000000..95736ce3bd7 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-63048/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-63048/usage.kt b/native/native.tests/testData/CInterop/KT-63048/usage.kt new file mode 100644 index 00000000000..7e40eb3559b --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-63048/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 00000000000..60ea30ba09b --- /dev/null +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/CInteropCheckersTest.kt @@ -0,0 +1,57 @@ +/* + * 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().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-63048" + 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