[ObjCExport] Fe10: Implement test with exported and non exported klib dependencies
KT-65670
This commit is contained in:
committed by
Space Team
parent
b26f9cb274
commit
e377a98815
+16
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.backend.konan.testUtils
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCHeader
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
|
||||
interface HeaderGenerator {
|
||||
|
||||
@@ -18,7 +19,22 @@ interface HeaderGenerator {
|
||||
* We do not generate them by default to keep test data easier to read.
|
||||
*/
|
||||
val generateBaseDeclarationStubs: Boolean = false,
|
||||
|
||||
/**
|
||||
* List of paths pointing to .klib files that can be used as dependency for the compiler when generating
|
||||
* the header for the given source files.
|
||||
*
|
||||
* Some of those dependencies can also be exported, see [exportedDependencyModuleNames]
|
||||
*/
|
||||
val dependencies: List<Path> = listOf(),
|
||||
|
||||
/**
|
||||
* Any dependency listed in [dependencies] which module name is present in this set is considered 'exported' and
|
||||
* will result in the entire public API surface of the said library to be translated in the header
|
||||
*/
|
||||
val exportedDependencyModuleNames: Set<String> = emptySet(),
|
||||
)
|
||||
|
||||
|
||||
fun generateHeaders(root: File, configuration: Configuration = Configuration()): ObjCHeader
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2024 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.backend.konan.testUtils
|
||||
|
||||
import java.io.File
|
||||
import kotlin.io.path.Path
|
||||
|
||||
val testDependencyKlibs = System.getProperty("testDependencyKlibs").orEmpty()
|
||||
.split(File.pathSeparator)
|
||||
.map(::Path)
|
||||
|
||||
val testLibraryAKlibFile
|
||||
get() = testDependencyKlibs.firstOrNull { it.contains(Path("testLibraryA")) }
|
||||
?: error("Missing 'testLibraryA' in 'testDependencyKlibs' System Property")
|
||||
|
||||
val testLibraryBKlibFile
|
||||
get() = testDependencyKlibs.firstOrNull { it.contains(Path("testLibraryB")) }
|
||||
?: error("Missing 'testLibraryB' in 'testDependencyKlibs' System Property")
|
||||
+16
-6
@@ -5,9 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.tests
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.testUtils.HeaderGenerator
|
||||
import org.jetbrains.kotlin.backend.konan.testUtils.TodoAnalysisApi
|
||||
import org.jetbrains.kotlin.backend.konan.testUtils.dependenciesDir
|
||||
import org.jetbrains.kotlin.backend.konan.testUtils.*
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.File
|
||||
@@ -21,7 +19,7 @@ import kotlin.test.fail
|
||||
* - stubs orders
|
||||
* - depth of traversing (some types must be skipped
|
||||
*/
|
||||
class ObjCDependenciesTypesTest(
|
||||
class ObjCExportDependenciesHeaderGeneratorTest(
|
||||
private val generator: HeaderGenerator,
|
||||
) {
|
||||
|
||||
@@ -54,9 +52,21 @@ class ObjCDependenciesTypesTest(
|
||||
doTest(dependenciesDir.resolve("implementIterator"))
|
||||
}
|
||||
|
||||
private fun doTest(root: File) {
|
||||
@Test
|
||||
fun `test - exportedAndNotExportedDependency`() {
|
||||
doTest(
|
||||
dependenciesDir.resolve("exportedAndNotExportedDependency"), configuration = HeaderGenerator.Configuration(
|
||||
frameworkName = "MyApp",
|
||||
generateBaseDeclarationStubs = true,
|
||||
dependencies = listOf(testLibraryAKlibFile, testLibraryBKlibFile),
|
||||
exportedDependencyModuleNames = setOf("org.jetbrains.kotlin:testLibraryA")
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun doTest(root: File, configuration: HeaderGenerator.Configuration = HeaderGenerator.Configuration()) {
|
||||
if (!root.isDirectory) fail("Expected ${root.absolutePath} to be directory")
|
||||
val generatedHeaders = generator.generateHeaders(root, HeaderGenerator.Configuration()).toString()
|
||||
val generatedHeaders = generator.generateHeaders(root, configuration).toString()
|
||||
KotlinTestUtils.assertEqualsToFile(root.resolve("!${root.nameWithoutExtension}.h"), generatedHeaders)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user