[K/N][Tests] Use GTest patterns for ignored tests
^KT-61259
This commit is contained in:
committed by
Space Team
parent
1ca79e645a
commit
2276abfb85
@@ -90,8 +90,12 @@ internal class TestProcessor(val suites: List<TestSuite>, val args: Array<String
|
|||||||
|
|
||||||
private fun String.substringEscaped(range: IntRange) = this.substring(range).let { if (it.isNotEmpty()) Regex.escape(it) else "" }
|
private fun String.substringEscaped(range: IntRange) = this.substring(range).let { if (it.isNotEmpty()) Regex.escape(it) else "" }
|
||||||
|
|
||||||
private fun String.toGTestPatterns() = splitToSequence(':').map { pattern ->
|
private fun String.fromGTestPatterns(): List<Regex> = splitToSequence(':').map(::fromGTestPattern).toList()
|
||||||
|
|
||||||
|
// must be in sync with `fromGTestPattern(String)` in native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/runner/TestRun.kt
|
||||||
|
private fun fromGTestPattern(pattern: String): Regex {
|
||||||
val result = StringBuilder()
|
val result = StringBuilder()
|
||||||
|
result.append("^")
|
||||||
var prevIndex = 0
|
var prevIndex = 0
|
||||||
pattern.forEachIndexed { index, c ->
|
pattern.forEachIndexed { index, c ->
|
||||||
if (c == '*' || c == '?') {
|
if (c == '*' || c == '?') {
|
||||||
@@ -101,8 +105,9 @@ internal class TestProcessor(val suites: List<TestSuite>, val args: Array<String
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.append(pattern.substringEscaped(prevIndex until pattern.length))
|
result.append(pattern.substringEscaped(prevIndex until pattern.length))
|
||||||
return@map result.toString().toRegex()
|
result.append("$")
|
||||||
}.toList()
|
return result.toString().toRegex()
|
||||||
|
}
|
||||||
|
|
||||||
// region filters
|
// region filters
|
||||||
|
|
||||||
@@ -115,8 +120,8 @@ internal class TestProcessor(val suites: List<TestSuite>, val args: Array<String
|
|||||||
throw IllegalArgumentException("Wrong pattern syntax: $filter.")
|
throw IllegalArgumentException("Wrong pattern syntax: $filter.")
|
||||||
}
|
}
|
||||||
|
|
||||||
val positivePatterns = filters[0].toGTestPatterns()
|
val positivePatterns = filters[0].fromGTestPatterns()
|
||||||
val negativePatterns = filters.getOrNull(1)?.toGTestPatterns() ?: emptyList()
|
val negativePatterns = filters.getOrNull(1)?.fromGTestPatterns() ?: emptyList()
|
||||||
|
|
||||||
return { testCase ->
|
return { testCase ->
|
||||||
positivePatterns.any { testCase.prettyName.matches(it) } &&
|
positivePatterns.any { testCase.prettyName.matches(it) } &&
|
||||||
|
|||||||
+2
-2
@@ -116,7 +116,7 @@ abstract class ComplexCInteropTestBase : AbstractNativeSimpleTest() {
|
|||||||
).assertSuccess().resultingArtifact
|
).assertSuccess().resultingArtifact
|
||||||
println(cinteropKlib)
|
println(cinteropKlib)
|
||||||
|
|
||||||
val ignoredTests = if (testRunSettings.get<GCType>() != GCType.NOOP) emptySet() else setOf(
|
val ignoredTestGTestPatterns = if (testRunSettings.get<GCType>() != GCType.NOOP) emptySet() else setOf(
|
||||||
"Kt41811Kt.*",
|
"Kt41811Kt.*",
|
||||||
"CustomStringKt.testCustomString",
|
"CustomStringKt.testCustomString",
|
||||||
"Kt42482Kt.testKT42482",
|
"Kt42482Kt.testKT42482",
|
||||||
@@ -131,7 +131,7 @@ abstract class ComplexCInteropTestBase : AbstractNativeSimpleTest() {
|
|||||||
"-XXLanguage:+ImplicitSignedToUnsignedIntegerConversion",
|
"-XXLanguage:+ImplicitSignedToUnsignedIntegerConversion",
|
||||||
"-tr", "-e", "main", "-linker-option", "-L${buildDir.absolutePath}"
|
"-tr", "-e", "main", "-linker-option", "-L${buildDir.absolutePath}"
|
||||||
),
|
),
|
||||||
extras = TestCase.WithTestRunnerExtras(TestRunnerType.DEFAULT, ignoredTests),
|
extras = TestCase.WithTestRunnerExtras(TestRunnerType.DEFAULT, ignoredTestGTestPatterns),
|
||||||
)
|
)
|
||||||
val success = compileToExecutable(testCase, cinteropKlib.asLibraryDependency()).assertSuccess()
|
val success = compileToExecutable(testCase, cinteropKlib.asLibraryDependency()).assertSuccess()
|
||||||
println(success)
|
println(success)
|
||||||
|
|||||||
+1
-1
@@ -48,7 +48,7 @@ internal open class BaseTestRunProvider {
|
|||||||
else {
|
else {
|
||||||
val ignoredTests = (testCase.extras as TestCase.WithTestRunnerExtras).ignoredTests
|
val ignoredTests = (testCase.extras as TestCase.WithTestRunnerExtras).ignoredTests
|
||||||
if (ignoredTests.isNotEmpty()) {
|
if (ignoredTests.isNotEmpty()) {
|
||||||
add(TestRunParameter.WithRegexFilter("(${ignoredTests.joinToString("|")})", positive = false))
|
add(TestRunParameter.WithGTestPatterns(negativePatterns = ignoredTests))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-6
@@ -86,15 +86,19 @@ internal sealed interface TestRunParameter {
|
|||||||
override fun testMatches(testName: TestName) = this.testName == testName
|
override fun testMatches(testName: TestName) = this.testName == testName
|
||||||
}
|
}
|
||||||
|
|
||||||
class WithRegexFilter(val pattern: String, val positive: Boolean) : WithFilter() {
|
class WithGTestPatterns(val positivePatterns: Set<String> = setOf("*"), val negativePatterns: Set<String>) : WithFilter() {
|
||||||
|
val positiveRegexes = positivePatterns.map(::fromGTestPattern)
|
||||||
|
val negativeRegexes = negativePatterns.map(::fromGTestPattern)
|
||||||
|
|
||||||
override fun applyTo(programArgs: MutableList<String>) {
|
override fun applyTo(programArgs: MutableList<String>) {
|
||||||
programArgs += if (positive)
|
"--ktest_filter=${positivePatterns.joinToString(":")}-${negativePatterns.joinToString(":")}"
|
||||||
"--ktest_regex_filter=$pattern"
|
|
||||||
else
|
|
||||||
"--ktest_negative_regex_filter=$pattern"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun testMatches(testName: TestName) = Regex(pattern).matches(testName.toString()) == positive
|
override fun testMatches(testName: TestName): Boolean {
|
||||||
|
val testNameStr = testName.toString()
|
||||||
|
return positiveRegexes.any { it.matches(testNameStr) } &&
|
||||||
|
!negativeRegexes.any { it.matches(testNameStr) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object WithTCTestLogger : TestRunParameter {
|
object WithTCTestLogger : TestRunParameter {
|
||||||
@@ -133,3 +137,23 @@ internal inline fun <reified T : TestRunParameter> List<TestRunParameter>.has():
|
|||||||
internal inline fun <reified T : TestRunParameter> List<TestRunParameter>.get(onFound: T.() -> Unit) {
|
internal inline fun <reified T : TestRunParameter> List<TestRunParameter>.get(onFound: T.() -> Unit) {
|
||||||
firstIsInstanceOrNull<T>()?.let(onFound)
|
firstIsInstanceOrNull<T>()?.let(onFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// must be in sync with `fromGTestPattern(String)` in kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt
|
||||||
|
internal fun fromGTestPattern(pattern: String): Regex {
|
||||||
|
val result = StringBuilder()
|
||||||
|
result.append("^")
|
||||||
|
var prevIndex = 0
|
||||||
|
pattern.forEachIndexed { index, c ->
|
||||||
|
if (c == '*' || c == '?') {
|
||||||
|
result.append(pattern.substringEscaped(prevIndex until index))
|
||||||
|
prevIndex = index + 1
|
||||||
|
result.append(if (c == '*') ".*" else ".")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.append(pattern.substringEscaped(prevIndex until pattern.length))
|
||||||
|
result.append("$")
|
||||||
|
return result.toString().toRegex()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun String.substringEscaped(range: IntRange) = this.substring(range).let { if (it.isNotEmpty()) Regex.escape(it) else "" }
|
||||||
|
|||||||
+3
-1
@@ -166,7 +166,9 @@ internal class TestRunProvider(
|
|||||||
if (testCase.kind == TestKind.REGULAR)
|
if (testCase.kind == TestKind.REGULAR)
|
||||||
filter { testName -> testName.packageName.startsWith(testCase.nominalPackageName) }
|
filter { testName -> testName.packageName.startsWith(testCase.nominalPackageName) }
|
||||||
else if (testCase.extras is WithTestRunnerExtras)
|
else if (testCase.extras is WithTestRunnerExtras)
|
||||||
filterNot { testName -> testCase.extras<WithTestRunnerExtras>().ignoredTests.contains(testName.toString()) }
|
filterNot { testName -> testCase.extras<WithTestRunnerExtras>().ignoredTests.any {
|
||||||
|
fromGTestPattern(it).matches(testName.toString())
|
||||||
|
}}
|
||||||
else
|
else
|
||||||
this
|
this
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user