From 97a86e0ee3c838fa5313dd4288ad6dcd70f339b6 Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Tue, 7 Nov 2023 14:56:12 +0100 Subject: [PATCH] [K/N][tests] Add global TEST_KIND override ^KT-61259 --- .../blackbox/support/ConfigurationProperties.kt | 2 +- .../test/blackbox/support/NativeTestSupport.kt | 14 ++++++-------- .../konan/test/blackbox/support/TestDirectives.kt | 4 ++-- .../support/group/ExtTestCaseGroupProvider.kt | 2 +- .../support/group/StandardTestCaseGroupProvider.kt | 7 +------ .../support/settings/TestProcessSettings.kt | 8 -------- .../buildsrc-compat/src/main/kotlin/nativeTest.kt | 8 ++++++-- 7 files changed, 17 insertions(+), 28 deletions(-) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/ConfigurationProperties.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/ConfigurationProperties.kt index c1d55da8d97..7977621fd15 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/ConfigurationProperties.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/ConfigurationProperties.kt @@ -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"), diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/NativeTestSupport.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/NativeTestSupport.kt index 938a93aa855..418f8daab7a 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/NativeTestSupport.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/NativeTestSupport.kt @@ -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 = diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/TestDirectives.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/TestDirectives.kt index 2e915ab2d25..4b69f2632be 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/TestDirectives.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/TestDirectives.kt @@ -247,9 +247,9 @@ internal class TestCompilerArgs(val compilerArgs: List) { } } -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" } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt index 7057922f724..7ae81579c88 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt @@ -174,7 +174,7 @@ private class ExtTestDataFile( fun createTestCase(settings: Settings, sharedModules: ThreadSafeCache): TestCase { assertTrue(isRelevant) - val definitelyStandaloneTest = settings.get().value + val definitelyStandaloneTest = settings.get() != TestKind.REGULAR val isStandaloneTest = definitelyStandaloneTest || determineIfStandaloneTest() patchPackageNames(isStandaloneTest) patchFileLevelAnnotations() diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/StandardTestCaseGroupProvider.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/StandardTestCaseGroupProvider.kt index 5f5059fb8ce..0deff8b790b 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/StandardTestCaseGroupProvider.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/StandardTestCaseGroupProvider.kt @@ -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().value) - TestKind.STANDALONE - else - testKind - } + val testKind = parseTestKind(registeredDirectives, location) ?: settings.get() if (testKind == TestKind.REGULAR) { // Fix package declarations to avoid unintended conflicts between symbols with the same name in different test cases. diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/settings/TestProcessSettings.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/settings/TestProcessSettings.kt index 0f207d5f5c1..25c59fefd35 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/settings/TestProcessSettings.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/settings/TestProcessSettings.kt @@ -103,14 +103,6 @@ internal value class CustomKlibs(val klibs: Set) { } } -/** - * 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). * diff --git a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/nativeTest.kt b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/nativeTest.kt index fc24ac7dae0..412b602ac0a 100644 --- a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/nativeTest.kt +++ b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/nativeTest.kt @@ -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)