Fix running nested classes with JUnit 5 causes outer class tests execution

Note: there might be a performance issue with running tests,
the reason why custom filtering was added to the tests running.
It's not tested and should be addressed separately

Try run IrBlackBoxCodegenTestGenerated.Annotations. Everything in the
outer class IrBlackBoxCodegenTestGenerated is run instead.
This is not an IDEA problem, since it reproduces from
the command line too.

^KTI-712 Fixed
This commit is contained in:
Nikolay Krasko
2021-12-01 18:48:21 +03:00
committed by teamcity
parent 20408dc176
commit 1efd583e14
+5 -3
View File
@@ -110,6 +110,8 @@ fun Project.projectTest(
}
return getOrCreateTask<Test>(taskName) {
doFirst {
if (jUnitMode == JUnitMode.JUnit5) return@doFirst
val commandLineIncludePatterns = (filter as? DefaultTestFilter)?.commandLineIncludePatterns?.toMutableList() ?: mutableSetOf()
val patterns = filter.includePatterns + commandLineIncludePatterns
if (patterns.isEmpty() || patterns.any { '*' in it }) return@doFirst
@@ -143,7 +145,7 @@ fun Project.projectTest(
val parentNames = if (jUnitMode != JUnitMode.JUnit4) {
/*
* If we run test from inner test class with junit 5 we need
* to include all containing classes of our class
* to include all containing classes of our class
*/
val nestedNames = classFileNameWithoutExtension.split("$")
mutableListOf(nestedNames.first()).also {
@@ -160,10 +162,10 @@ fun Project.projectTest(
} else {
if (path == classFileName) return@include true
if (!path.endsWith(".class")) return@include false
when(jUnitMode) {
JUnitMode.JUnit5 -> parentNames.any { path.startsWith(it) }
when (jUnitMode) {
JUnitMode.JUnit4 -> path.startsWith("$classFileNameWithoutExtension$")
JUnitMode.Mix -> parentNames.any { path.startsWith(it) } || path.startsWith("$classFileNameWithoutExtension$")
else -> error("JUnit5 should not be reachable because of early exit")
}
}
}