[K/N][tests] Add global TEST_KIND override ^KT-61259

This commit is contained in:
Alexander Shabalin
2023-11-07 14:56:12 +01:00
committed by Space Team
parent e75b29032f
commit 97a86e0ee3
7 changed files with 17 additions and 28 deletions
@@ -59,7 +59,7 @@ internal enum class ClassLevelProperty(val shortName: String) {
TEST_MODE("mode"),
COMPILER_PLUGINS("compilerPlugins"),
CUSTOM_KLIBS("customKlibs"),
FORCE_STANDALONE("forceStandalone"),
TEST_KIND("testKind"),
COMPILE_ONLY("compileOnly"),
OPTIMIZATION_MODE("optimizationMode"),
USE_THREAD_STATE_CHECKER("useThreadStateChecker"),
@@ -201,7 +201,7 @@ internal object NativeTestSupport {
output += computeTestMode(enforcedProperties)
output += computeCompilerPlugins(enforcedProperties)
output += computeCustomKlibs(enforcedProperties)
output += computeForcedStandaloneTestKind(enforcedProperties)
output += computeTestKind(enforcedProperties)
output += computeForcedNoopTestRunner(enforcedProperties)
output += computeTimeouts(enforcedProperties)
// Parse annotations of current class, since there's no way to put annotations to upper-level enclosing class
@@ -309,13 +309,11 @@ internal object NativeTestSupport {
)
)
private fun computeForcedStandaloneTestKind(enforcedProperties: EnforcedProperties): ForcedStandaloneTestKind =
ForcedStandaloneTestKind(
ClassLevelProperty.FORCE_STANDALONE.readValue(
enforcedProperties,
String::toBooleanStrictOrNull,
default = false
)
private fun computeTestKind(enforcedProperties: EnforcedProperties): TestKind =
ClassLevelProperty.TEST_KIND.readValue(
enforcedProperties,
TestKind.values(),
default = TestKind.REGULAR
)
private fun computeForcedNoopTestRunner(enforcedProperties: EnforcedProperties): ForcedNoopTestRunner =
@@ -247,9 +247,9 @@ internal class TestCompilerArgs(val compilerArgs: List<String>) {
}
}
internal fun parseTestKind(registeredDirectives: RegisteredDirectives, location: Location): TestKind {
internal fun parseTestKind(registeredDirectives: RegisteredDirectives, location: Location): TestKind? {
if (KIND !in registeredDirectives)
return TestKind.REGULAR // The default one.
return null // The default is determined by TEST_KIND global property
val values = registeredDirectives[KIND]
return values.singleOrNull() ?: fail { "$location: Exactly one test kind expected in $KIND directive: $values" }
@@ -174,7 +174,7 @@ private class ExtTestDataFile(
fun createTestCase(settings: Settings, sharedModules: ThreadSafeCache<String, TestModule.Shared?>): TestCase {
assertTrue(isRelevant)
val definitelyStandaloneTest = settings.get<ForcedStandaloneTestKind>().value
val definitelyStandaloneTest = settings.get<TestKind>() != TestKind.REGULAR
val isStandaloneTest = definitelyStandaloneTest || determineIfStandaloneTest()
patchPackageNames(isStandaloneTest)
patchFileLevelAnnotations()
@@ -197,12 +197,7 @@ internal class StandardTestCaseGroupProvider : TestCaseGroupProvider {
val freeCompilerArgs = parseFreeCompilerArgs(registeredDirectives, location)
val expectedTimeoutFailure = parseExpectedTimeoutFailure(registeredDirectives)
val testKind = parseTestKind(registeredDirectives, location).let { testKind ->
if (testKind == TestKind.REGULAR && settings.get<ForcedStandaloneTestKind>().value)
TestKind.STANDALONE
else
testKind
}
val testKind = parseTestKind(registeredDirectives, location) ?: settings.get<TestKind>()
if (testKind == TestKind.REGULAR) {
// Fix package declarations to avoid unintended conflicts between symbols with the same name in different test cases.
@@ -103,14 +103,6 @@ internal value class CustomKlibs(val klibs: Set<File>) {
}
}
/**
* Whether to force [TestKind.STANDALONE] for all tests where [TestKind] is assumed to be [TestKind.REGULAR] otherwise:
* - either explicitly specified in the test data file: // KIND: REGULAR
* - or // KIND: is not specified in the test data file and thus automatically considered as [TestKind.REGULAR]
*/
@JvmInline
internal value class ForcedStandaloneTestKind(val value: Boolean)
/**
* Whether tests should be compiled only (true) or compiled and executed (false, the default).
*
@@ -16,7 +16,8 @@ private enum class TestProperty(shortName: String) {
CUSTOM_KLIBS("customKlibs"),
TEST_TARGET("target"),
TEST_MODE("mode"),
FORCE_STANDALONE("forceStandalone"),
TEST_KIND("testKind"),
FORCE_STANDALONE("forceStandalone"), // This is not passed directly into the test infra but transformed into TEST_KIND.
COMPILE_ONLY("compileOnly"),
OPTIMIZATION_MODE("optimizationMode"),
USE_THREAD_STATE_CHECKER("useThreadStateChecker"),
@@ -178,10 +179,13 @@ fun Project.nativeTest(
lazyClassPath { customTestDependencies.flatMapTo(this) { it.files } }
}
compute(TEST_KIND) {
readFromGradle(FORCE_STANDALONE)?.let { "STANDALONE" }
}
// Pass Gradle properties as JVM properties so test process can read them.
compute(TEST_TARGET)
compute(TEST_MODE)
compute(FORCE_STANDALONE)
compute(COMPILE_ONLY)
compute(OPTIMIZATION_MODE)
compute(USE_THREAD_STATE_CHECKER)