Skip to content
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

include extraction of regex patterns defined within build gradle #3248

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -15,7 +15,7 @@ import java.util.regex.Pattern
*
* Since ClassMethodNameFilter is private, we can't get access to the underlying patterns, so we resort
* to this reflection bullshit to get the raw strings out, so we can parse and apply the patterns ourselves,
* thus allowing kotest to properly support the --tests options.
* thus allowing kotest to properly support the --tests options as well as filter { } block defined in build.gradle.kts.
*
*/
object GradlePostDiscoveryFilterExtractor {
Expand All @@ -32,10 +32,13 @@ object GradlePostDiscoveryFilterExtractor {
val matcher = testMatcher(filter)
logger.log { Pair(null, "TestMatcher [$matcher]") }

val buildScriptIncludePatterns = buildScriptIncludePatterns(matcher)
logger.log { Pair(null, "buildScriptIncludePatterns [$buildScriptIncludePatterns]") }

val commandLineIncludePatterns = commandLineIncludePatterns(matcher)
logger.log { Pair(null, "commandLineIncludePatterns [$commandLineIncludePatterns]") }

val regexes = commandLineIncludePatterns.map { pattern(it) }
val regexes = (buildScriptIncludePatterns + commandLineIncludePatterns).map { pattern(it) }
logger.log { Pair(null, "ClassMethodNameFilter regexes [$regexes]") }
regexes
}.getOrElse { emptyList() }
Expand All @@ -46,6 +49,12 @@ object GradlePostDiscoveryFilterExtractor {
return field.get(obj)
}

private fun buildScriptIncludePatterns(obj: Any): List<Any> {
val field = obj::class.java.getDeclaredField("buildScriptIncludePatterns")
field.isAccessible = true
return field.get(obj) as List<Any>
}

private fun commandLineIncludePatterns(obj: Any): List<Any> {
val field = obj::class.java.getDeclaredField("commandLineIncludePatterns")
field.isAccessible = true
Expand Down