New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue/fix gradle filter #3257
Issue/fix gradle filter #3257
Conversation
...rc/jvmMain/kotlin/io/kotest/runner/junit/platform/gradle/GradleClassMethodRegexTestFilter.kt
Show resolved
Hide resolved
@@ -52,6 +59,12 @@ object GradlePostDiscoveryFilterExtractor { | |||
return field.get(obj) as List<Any> | |||
} | |||
|
|||
private fun buildScriptIncludePatterns(obj: Any): List<Any> { | |||
val field = obj::class.java.getDeclaredField("buildScriptIncludePatterns") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added support for filters defined in build script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there build script exclude patterns as well? Not saying we need to fix it now, but could be flagged up as a potential future contribution
val isPackageMatched by lazy { doesNotContainUppercase && packagePath.matches(laxRegexPattern) } // io.kotest | ||
val isPackageWithDotMatched by lazy { doesNotContainUppercase && "$packagePath.".matches(laxRegexPattern) } // io.kotest.* | ||
|
||
return isSimpleClassMatch || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
277826f
to
9ed501f
Compare
@@ -52,6 +59,12 @@ object GradlePostDiscoveryFilterExtractor { | |||
return field.get(obj) as List<Any> | |||
} | |||
|
|||
private fun buildScriptIncludePatterns(obj: Any): List<Any> { | |||
val field = obj::class.java.getDeclaredField("buildScriptIncludePatterns") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there build script exclude patterns as well? Not saying we need to fix it now, but could be flagged up as a potential future contribution
withData( | ||
nameFn = { filters -> "should be INCLUDED when evaluating $filters" }, | ||
listOf("\\QGradleClassMethodRegexTestFilterTest\\E"), | ||
listOf(".*\\QthodRegexTestFilterTest\\E"), | ||
listOf(".*\\QTest\\E"), | ||
listOf("\\Qio.kotest.runner.junit.platform.gradle.GradleClassMethodRegexTestFilterTest\\E"), | ||
listOf(".*\\Q.platform.gradle.GradleClassMethodRegexTestFilterTest\\E"), | ||
listOf(".*\\Qorm.gradle.GradleClassMethodRegexTestFilterTest\\E") | ||
) { filters -> | ||
GradleClassMethodRegexTestFilter(filters).filter(spec) shouldBe TestFilterResult.Include | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :)
In this PR
GradleClassMethodRegexTestFilter
to translate patterns supplied by gradle to the proper test filters (fixes Gradle test regex are incorrectly applied #3250).GradleClassMethodRegexTestFilterTest.kt
tests to reflect the pattern supplied by latest gradle (gradle 7.5.1).filter { }
defined in gradle.build.kts #3247)Patterns that works
tested against gradle 7.5.1, using both filters defined in
build.gradle.kts
and command line:gradle test --tests "SomeTest"
gradle test --tests "*Test"
gradle test --tests "io.package.*"
gradle test --tests "io.package"
gradle test --tests "io.package.SomeTest"
gradle test --tests "io.package.SomeTest.first level context*"
gradle test --tests "io.package.SomeTest.*"
gradle test --tests "io.*.SomeTest"
gradle test --tests "io.*.SomeTest.*"
gradle test --tests "SomeTest.first level context*"
gradle test --tests "*.first level context*"
Pattern that does NOT work
In this PR I decided to omit the support for nested context / test matching. It's arguably quite involved so I'd reserve it for future contribution. Kotest support lazy test registration within nested context. Gradle test filter does not natively work nicely with kotest. In order to make it work we need to think of a way to recursively apply partial context-search as we dive deeper into the contexts. I.e. These patterns DOES NOT work yet:
gradle test --tests "SomeTest.first level context -- should assert this test description"
gradle test --tests "SomeTest.first level context -- nested context -- *"
gradle test --tests "SomeTest.first level context -- nested context -- yet another nested context -- *"
Mechanism
Gradle supplies a pattern string which corresponds to a well-formed regex object. This can be directly usable for kotest.
A*
becomes\QA\E.*
A*Test
becomes\QA\E.*\QTest\E
io.*.A*Test
becomes\Qio.\E.*\Q.A\E.*\QTest\E
io.*.A*Test.AccountDetails*
becomes\Qio.\E.*\Q.A\E.*\QTest.AccountDetails\E.*
io.*.A*Test.some test context*
becomes\Qio.\E.*\Q.A\E.*\QTest.some test context\E.*
Within the code we get this pattern string and directly translate them into a regex object to be used against the path / classname / packagename as appropriate.