[Test] Read default target version from sys property in new test infra
This commit is contained in:
+22
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
@@ -41,6 +42,8 @@ import java.io.File
|
||||
class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigurator(testServices) {
|
||||
companion object {
|
||||
val TEST_CONFIGURATION_KIND_KEY = CompilerConfigurationKey.create<ConfigurationKind>("ConfigurationKind")
|
||||
|
||||
private val DEFAULT_JVM_TARGET_FROM_PROPERTY: String? = System.getProperty("kotlin.test.default.jvm.target")
|
||||
}
|
||||
|
||||
override val directivesContainers: List<DirectivesContainer>
|
||||
@@ -66,6 +69,7 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig
|
||||
1 -> configuration.put(JVMConfigurationKeys.JVM_TARGET, targets.single())
|
||||
else -> error("Too many jvm targets passed: ${targets.joinToArrayString()}")
|
||||
}
|
||||
configureDefaultJvmTarget(configuration)
|
||||
|
||||
when (extractJdkKind(registeredDirectives)) {
|
||||
TestJdkKind.MOCK_JDK -> {
|
||||
@@ -145,6 +149,24 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig
|
||||
initBinaryDependencies(module, configuration)
|
||||
}
|
||||
|
||||
private fun configureDefaultJvmTarget(configuration: CompilerConfiguration) {
|
||||
if (DEFAULT_JVM_TARGET_FROM_PROPERTY == null) return
|
||||
val customDefaultTarget = JvmTarget.fromString(DEFAULT_JVM_TARGET_FROM_PROPERTY)
|
||||
?: error("Can't construct JvmTarget for $DEFAULT_JVM_TARGET_FROM_PROPERTY")
|
||||
val originalTarget = configuration[JVMConfigurationKeys.JVM_TARGET]
|
||||
if (originalTarget == null || customDefaultTarget.majorVersion > originalTarget.majorVersion) {
|
||||
// It's not safe to substitute target in general
|
||||
// cause it can affect generated bytecode and original behaviour should be tested somehow.
|
||||
// Original behaviour testing is perfomed by
|
||||
//
|
||||
// codegenTest(target = 6, jvm = "Last", jdk = mostRecentJdk)
|
||||
// codegenTest(target = 8, jvm = "Last", jdk = mostRecentJdk)
|
||||
//
|
||||
// in compiler/tests-different-jdk/build.gradle.kts
|
||||
configuration.put(JVMConfigurationKeys.JVM_TARGET, customDefaultTarget)
|
||||
}
|
||||
}
|
||||
|
||||
private fun extractJdkKind(registeredDirectives: RegisteredDirectives): TestJdkKind {
|
||||
val fullJdkEnabled = JvmEnvironmentConfigurationDirectives.FULL_JDK in registeredDirectives
|
||||
val jdkKinds = registeredDirectives[JvmEnvironmentConfigurationDirectives.JDK_KIND]
|
||||
|
||||
Reference in New Issue
Block a user