From 30f20cb835f0894140752ee66bd811a7f0ac9163 Mon Sep 17 00:00:00 2001 From: Roman Golyshev Date: Tue, 8 Jun 2021 18:38:17 +0300 Subject: [PATCH] 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 --- .../test/builders/TestConfigurationBuilder.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestConfigurationBuilder.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestConfigurationBuilder.kt index 34a10f083ad..85a111dcdec 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestConfigurationBuilder.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestConfigurationBuilder.kt @@ -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() } }