Compare commits

...

2 Commits

Author SHA1 Message Date
Roman Golyshev
1b836872d9 Fix converting string GLOB to regexp in TestConfigurationBuilder
This is required when `p1|p2|p3|...|pN` concatenation is used (see `or`
extension function above `toMatchingRegexString`)

This is a follow-up to the 6f4b6c1b5b7bc05557306179e25a79fa234aa77f
commit
2021-06-11 18:10:01 +03:00
Roman Golyshev
d9a3f2665b 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
2021-06-11 18:10:00 +03:00

View File

@@ -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()
}
}