[Native][tests] Fix: Provide correct path to K/N stdlib in compiled tests
This commit is contained in:
+2
-1
@@ -8,6 +8,7 @@
|
||||
package org.jetbrains.kotlin.konan.blackboxtest
|
||||
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.TestCaseId
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.group.PredefinedPaths.KOTLIN_NATIVE_DISTRIBUTION
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.group.PredefinedTestCase as TC
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.group.PredefinedTestCases
|
||||
import org.junit.jupiter.api.Tag
|
||||
@@ -44,4 +45,4 @@ class NativeStdlibBlackBoxTest : AbstractNativeBlackBoxTest() {
|
||||
fun nativeStdlib() = dynamicTestCase(TestCaseId.Named("nativeStdlib"))
|
||||
}
|
||||
|
||||
private const val KOTLIN_NATIVE_STDLIB_PATH = "kotlin-native/dist/klib/common/stdlib"
|
||||
private const val KOTLIN_NATIVE_STDLIB_PATH = "$KOTLIN_NATIVE_DISTRIBUTION/klib/common/stdlib"
|
||||
|
||||
+7
-9
@@ -8,11 +8,7 @@ package org.jetbrains.kotlin.konan.blackboxtest.support
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.AbstractNativeBlackBoxTest
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.group.TestCaseGroupProvider
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.*
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.GeneratedSources
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.GlobalSettings
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Settings
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.TestRoots
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.TestSettings
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.*
|
||||
import org.jetbrains.kotlin.test.TestMetadata
|
||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEquals
|
||||
@@ -154,21 +150,23 @@ class NativeBlackBoxTestSupport : BeforeEachCallback {
|
||||
testSettings: TestSettings,
|
||||
testSettingsAnnotation: Annotation?
|
||||
): TestCaseGroupProvider {
|
||||
// Try to find a constructor that accepts the annotation.
|
||||
// Try to find a constructor that accepts the setting and the annotation.
|
||||
if (testSettingsAnnotation != null) {
|
||||
val testSettingsAnnotationClass = testSettingsAnnotation.annotationClass
|
||||
testSettings.providerClass.constructors.asSequence()
|
||||
.forEach { c ->
|
||||
val p = c.parameters.singleOrNull() ?: return@forEach
|
||||
if (p.hasTypeOf(testSettingsAnnotationClass)) return c.call(testSettingsAnnotation).cast()
|
||||
val (p1, p2) = c.parameters.takeIf { it.size == 2 } ?: return@forEach
|
||||
if (p1.hasTypeOf<Settings>() && p2.hasTypeOf(testSettingsAnnotationClass))
|
||||
return c.call(settings, testSettingsAnnotation).cast()
|
||||
}
|
||||
}
|
||||
|
||||
// ... or settings at least.
|
||||
// ... or the settings at least.
|
||||
testSettings.providerClass.constructors.asSequence()
|
||||
.forEach { c ->
|
||||
val p = c.parameters.singleOrNull() ?: return@forEach
|
||||
if (p.hasTypeOf<Settings>()) return c.call(settings).cast()
|
||||
if (p.hasTypeOf<Settings>())
|
||||
return c.call(settings).cast()
|
||||
}
|
||||
|
||||
fail { "No suitable constructor for ${testSettings.providerClass}" }
|
||||
|
||||
+34
-29
@@ -7,10 +7,8 @@ package org.jetbrains.kotlin.konan.blackboxtest.support.group
|
||||
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.*
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.TestCase.WithTestRunnerExtras
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.TestCaseGroup
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.TestCaseGroupId
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.TestFile
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.TestModule
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.GlobalSettings
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Settings
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.ThreadSafeFactory
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.expandGlobTo
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.getAbsoluteFile
|
||||
@@ -19,7 +17,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
import org.junit.jupiter.api.fail
|
||||
import java.io.File
|
||||
|
||||
internal class PredefinedTestCaseGroupProvider(annotation: PredefinedTestCases) : TestCaseGroupProvider {
|
||||
internal class PredefinedTestCaseGroupProvider(private val settings: Settings, annotation: PredefinedTestCases) : TestCaseGroupProvider {
|
||||
private val testCaseIdToPredefinedTestCase: Map<TestCaseId.Named, PredefinedTestCase> = buildMap {
|
||||
annotation.testCases.forEach { predefinedTestCase ->
|
||||
val testCaseId = TestCaseId.Named(predefinedTestCase.name)
|
||||
@@ -76,31 +74,38 @@ internal class PredefinedTestCaseGroupProvider(annotation: PredefinedTestCases)
|
||||
return lazyTestCaseGroups[testCaseGroupId.cast()]
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun Array<String>.expandGlobs(noExpandedFilesErrorMessage: () -> String): Set<File> {
|
||||
val files = buildSet {
|
||||
this@expandGlobs.forEach { pathPattern -> expandGlobTo(getAbsoluteFile(pathPattern), this) }
|
||||
private fun Array<String>.expandGlobs(noExpandedFilesErrorMessage: () -> String): Set<File> {
|
||||
val files = buildSet {
|
||||
this@expandGlobs.forEach { pathPattern ->
|
||||
expandGlobTo(getAbsoluteFile(substituteRealPaths(pathPattern)), this)
|
||||
}
|
||||
assertTrue(files.isNotEmpty(), noExpandedFilesErrorMessage)
|
||||
return files
|
||||
}
|
||||
assertTrue(files.isNotEmpty(), noExpandedFilesErrorMessage)
|
||||
return files
|
||||
}
|
||||
|
||||
private fun Array<String>.parseCompilerArgs(parsingErrorMessage: () -> String): TestCompilerArgs =
|
||||
if (isEmpty())
|
||||
TestCompilerArgs.EMPTY
|
||||
else {
|
||||
val freeCompilerArgs = map { arg -> substituteRealPaths(arg) }
|
||||
val forbiddenCompilerArgs = TestCompilerArgs.findForbiddenArgs(freeCompilerArgs)
|
||||
assertTrue(forbiddenCompilerArgs.isEmpty()) {
|
||||
"""
|
||||
${parsingErrorMessage()}
|
||||
|
||||
Forbidden compiler arguments found: $forbiddenCompilerArgs
|
||||
All arguments: $this
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
TestCompilerArgs(freeCompilerArgs)
|
||||
}
|
||||
|
||||
private fun Array<String>.parseCompilerArgs(parsingErrorMessage: () -> String): TestCompilerArgs =
|
||||
if (isEmpty())
|
||||
TestCompilerArgs.EMPTY
|
||||
else {
|
||||
val freeCompilerArgs = asList()
|
||||
val forbiddenCompilerArgs = TestCompilerArgs.findForbiddenArgs(freeCompilerArgs)
|
||||
assertTrue(forbiddenCompilerArgs.isEmpty()) {
|
||||
"""
|
||||
${parsingErrorMessage()}
|
||||
|
||||
Forbidden compiler arguments found: $forbiddenCompilerArgs
|
||||
All arguments: $this
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
TestCompilerArgs(freeCompilerArgs)
|
||||
}
|
||||
}
|
||||
private fun substituteRealPaths(value: String): String =
|
||||
if ('$' in value) {
|
||||
// N.B. Here, more substitutions can be supported in the future if it would be necessary.
|
||||
value.replace(PredefinedPaths.KOTLIN_NATIVE_DISTRIBUTION, settings.get<GlobalSettings>().kotlinNativeHome.path)
|
||||
} else
|
||||
value
|
||||
}
|
||||
|
||||
+6
-2
@@ -9,7 +9,11 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.settings.TestSettings
|
||||
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@TestSettings(providerClass = PredefinedTestCaseGroupProvider::class)
|
||||
annotation class PredefinedTestCases(vararg val testCases: PredefinedTestCase)
|
||||
internal annotation class PredefinedTestCases(vararg val testCases: PredefinedTestCase)
|
||||
|
||||
@Target()
|
||||
annotation class PredefinedTestCase(val name: String, val freeCompilerArgs: Array<String>, val sourceLocations: Array<String>)
|
||||
internal annotation class PredefinedTestCase(val name: String, val freeCompilerArgs: Array<String>, val sourceLocations: Array<String>)
|
||||
|
||||
internal object PredefinedPaths {
|
||||
const val KOTLIN_NATIVE_DISTRIBUTION = "\$KOTLIN_NATIVE_DISTRIBUTION\$"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user