[Gradle, K/N] Rework environment input on test tasks
Provide method `trackEnvironment` to track environment variables. Use only tracked environment variables as task input. #KT-44059 Fixed
This commit is contained in:
+38
-7
@@ -623,11 +623,47 @@ class GeneralNativeIT : BaseGradleIT() {
|
||||
assertFileExists(defaultOutputFile)
|
||||
}
|
||||
|
||||
checkTestsUpToDate(testsToExecute, testsToSkip)
|
||||
|
||||
// Check simulator process leaking.
|
||||
val bootedSimulatorsAfter = getBootedSimulators(projectDir)
|
||||
assertEquals(bootedSimulatorsBefore, bootedSimulatorsAfter)
|
||||
|
||||
// Check the case with failed tests.
|
||||
checkFailedTests(hostTestTask, testsToExecute, testsToSkip)
|
||||
|
||||
build("linkAnotherDebugTestHost") {
|
||||
assertSuccessful()
|
||||
assertFileExists(anotherOutputFile)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Project.checkTestsUpToDate(testsToExecute: List<String>, testsToSkip: List<String>) {
|
||||
// Check that test tasks are up-to-date on second run
|
||||
build("check") {
|
||||
assertSuccessful()
|
||||
|
||||
assertTasksUpToDate(*testsToExecute.toTypedArray())
|
||||
assertTasksSkipped(*testsToSkip.toTypedArray())
|
||||
}
|
||||
|
||||
// Check that setting new value to tracked environment variable triggers tests rerun
|
||||
build("check", options = defaultBuildOptions().copy(androidHome = projectDir)) {
|
||||
assertSuccessful()
|
||||
|
||||
assertTasksExecuted(*testsToExecute.toTypedArray())
|
||||
assertTasksSkipped(*testsToSkip.toTypedArray())
|
||||
}
|
||||
|
||||
build("check", options = defaultBuildOptions().copy(androidHome = projectDir)) {
|
||||
assertSuccessful()
|
||||
|
||||
assertTasksUpToDate(*testsToExecute.toTypedArray())
|
||||
assertTasksSkipped(*testsToSkip.toTypedArray())
|
||||
}
|
||||
}
|
||||
|
||||
private fun Project.checkFailedTests(hostTestTask: String, testsToExecute: List<String>, testsToSkip: List<String>) {
|
||||
projectDir.resolve("src/commonTest/kotlin/test.kt").appendText(
|
||||
"""
|
||||
@Test
|
||||
@@ -698,8 +734,8 @@ class GeneralNativeIT : BaseGradleIT() {
|
||||
assertTestResults(expectedTestResults.first(), hostTestTask)
|
||||
// K/N doesn't report line numbers correctly on Linux (see KT-35408).
|
||||
// TODO: Uncomment when this is fixed.
|
||||
//assertStacktrace(hostTestTask)
|
||||
if (hostIsMac) {
|
||||
//assertStacktrace(hostTestTask, "host")
|
||||
if (HostManager.hostIsMac) {
|
||||
assertTestResultsAnyOf(
|
||||
expectedTestResults[0],
|
||||
expectedTestResults[1],
|
||||
@@ -708,11 +744,6 @@ class GeneralNativeIT : BaseGradleIT() {
|
||||
assertStacktrace("iosTest")
|
||||
}
|
||||
}
|
||||
|
||||
build("linkAnotherDebugTestHost") {
|
||||
assertSuccessful()
|
||||
assertFileExists(anotherOutputFile)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
@@ -42,6 +42,8 @@ kotlin {
|
||||
|
||||
// Check that test events are correctly reported in CLI.
|
||||
configure([hostTest, iosTest]){
|
||||
trackEnvironment("ANDROID_HOME")
|
||||
|
||||
testLogging {
|
||||
events "passed", "skipped", "failed"
|
||||
}
|
||||
|
||||
+22
-3
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.isAtLeast
|
||||
import org.jetbrains.kotlin.gradle.targets.native.internal.parseKotlinNativeStackTraceAsJvm
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTest
|
||||
import org.jetbrains.kotlin.gradle.utils.isConfigurationCacheAvailable
|
||||
import org.jetbrains.kotlin.konan.CompilerVersion
|
||||
import java.io.File
|
||||
import java.util.concurrent.Callable
|
||||
|
||||
@@ -65,13 +64,20 @@ abstract class KotlinNativeTest : KotlinTest() {
|
||||
processOptions.workingDir = File(value)
|
||||
}
|
||||
|
||||
@get:Input
|
||||
@get:Internal
|
||||
var environment: Map<String, Any>
|
||||
get() = processOptions.environment
|
||||
set(value) {
|
||||
processOptions.environment = value
|
||||
}
|
||||
|
||||
private val trackedEnvironmentVariablesKeys = mutableSetOf<String>()
|
||||
|
||||
@Suppress("unused")
|
||||
@get:Input
|
||||
val trackedEnvironment
|
||||
get() = environment.filterKeys(trackedEnvironmentVariablesKeys::contains)
|
||||
|
||||
private fun <T> Property<T>.set(providerLambda: () -> T) = set(project.provider { providerLambda() })
|
||||
|
||||
fun executable(file: File) {
|
||||
@@ -98,8 +104,21 @@ abstract class KotlinNativeTest : KotlinTest() {
|
||||
executableProperty.set(project.provider(provider).map { project.files(it) })
|
||||
}
|
||||
|
||||
fun environment(name: String, value: Any) {
|
||||
@JvmOverloads
|
||||
fun environment(name: String, value: Any, tracked: Boolean = true) {
|
||||
processOptions.environment(name, value)
|
||||
if (tracked) {
|
||||
trackedEnvironmentVariablesKeys.add(name)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun trackEnvironment(name: String, tracked: Boolean = true) {
|
||||
if (tracked) {
|
||||
trackedEnvironmentVariablesKeys.add(name)
|
||||
} else {
|
||||
trackedEnvironmentVariablesKeys.remove(name)
|
||||
}
|
||||
}
|
||||
|
||||
@get:Internal
|
||||
|
||||
Reference in New Issue
Block a user