Use more reliable paths matching in TestConfigurationBuilder
Without it, even the slightest difference between the pattern and testDataPath would cause the path to be excluded, for example: testDataPath = /some/absolute/path.txt pattern = absolute/* The example above didn't match, and it resulted in different configurations when tests were launched with different testDataPaths Now, the example above will look like this: testDataPath = /some/absolute/path.txt patter = */absolute/* Now it matches correctly
This commit is contained in:
committed by
TeamCityServer
parent
d42a6771b0
commit
30f20cb835
+10
-3
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.impl.TestConfigurationImpl
|
||||
import org.jetbrains.kotlin.test.model.*
|
||||
import org.jetbrains.kotlin.test.services.*
|
||||
import kotlin.io.path.Path
|
||||
|
||||
@DefaultsDsl
|
||||
@OptIn(TestInfrastructureInternals::class)
|
||||
@@ -69,7 +70,10 @@ class TestConfigurationBuilder {
|
||||
return """$this|$other"""
|
||||
}
|
||||
|
||||
private fun String.toMatchingRegexString(): String = """^${replace("*", ".*")}$"""
|
||||
private fun String.toMatchingRegexString(): String = when (this) {
|
||||
"*" -> ".*"
|
||||
else -> """^.*/${replace("*", ".*")}$"""
|
||||
}
|
||||
|
||||
fun forTestsMatching(pattern: Regex, configuration: TestConfigurationBuilder.() -> Unit) {
|
||||
configurationsByPositiveTestDataCondition += pattern to configuration
|
||||
@@ -162,13 +166,16 @@ class TestConfigurationBuilder {
|
||||
}
|
||||
|
||||
fun build(testDataPath: String): TestConfiguration {
|
||||
// We use URI here because we use '/' in our codebase, and URI also uses it (unlike OS-dependent `toString()`)
|
||||
val absoluteTestDataPath = Path(testDataPath).normalize().toUri().toString()
|
||||
|
||||
for ((regex, configuration) in configurationsByPositiveTestDataCondition) {
|
||||
if (regex.matches(testDataPath)) {
|
||||
if (regex.matches(absoluteTestDataPath)) {
|
||||
this.configuration()
|
||||
}
|
||||
}
|
||||
for ((regex, configuration) in configurationsByNegativeTestDataCondition) {
|
||||
if (!regex.matches(testDataPath)) {
|
||||
if (!regex.matches(absoluteTestDataPath)) {
|
||||
this.configuration()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user