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:
@@ -110,6 +110,8 @@ fun Project.projectTest(
|
|||||||
}
|
}
|
||||||
return getOrCreateTask<Test>(taskName) {
|
return getOrCreateTask<Test>(taskName) {
|
||||||
doFirst {
|
doFirst {
|
||||||
|
if (jUnitMode == JUnitMode.JUnit5) return@doFirst
|
||||||
|
|
||||||
val commandLineIncludePatterns = (filter as? DefaultTestFilter)?.commandLineIncludePatterns?.toMutableList() ?: mutableSetOf()
|
val commandLineIncludePatterns = (filter as? DefaultTestFilter)?.commandLineIncludePatterns?.toMutableList() ?: mutableSetOf()
|
||||||
val patterns = filter.includePatterns + commandLineIncludePatterns
|
val patterns = filter.includePatterns + commandLineIncludePatterns
|
||||||
if (patterns.isEmpty() || patterns.any { '*' in it }) return@doFirst
|
if (patterns.isEmpty() || patterns.any { '*' in it }) return@doFirst
|
||||||
@@ -143,7 +145,7 @@ fun Project.projectTest(
|
|||||||
val parentNames = if (jUnitMode != JUnitMode.JUnit4) {
|
val parentNames = if (jUnitMode != JUnitMode.JUnit4) {
|
||||||
/*
|
/*
|
||||||
* If we run test from inner test class with junit 5 we need
|
* 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("$")
|
val nestedNames = classFileNameWithoutExtension.split("$")
|
||||||
mutableListOf(nestedNames.first()).also {
|
mutableListOf(nestedNames.first()).also {
|
||||||
@@ -160,10 +162,10 @@ fun Project.projectTest(
|
|||||||
} else {
|
} else {
|
||||||
if (path == classFileName) return@include true
|
if (path == classFileName) return@include true
|
||||||
if (!path.endsWith(".class")) return@include false
|
if (!path.endsWith(".class")) return@include false
|
||||||
when(jUnitMode) {
|
when (jUnitMode) {
|
||||||
JUnitMode.JUnit5 -> parentNames.any { path.startsWith(it) }
|
|
||||||
JUnitMode.JUnit4 -> path.startsWith("$classFileNameWithoutExtension$")
|
JUnitMode.JUnit4 -> path.startsWith("$classFileNameWithoutExtension$")
|
||||||
JUnitMode.Mix -> parentNames.any { path.startsWith(it) } || path.startsWith("$classFileNameWithoutExtension$")
|
JUnitMode.Mix -> parentNames.any { path.startsWith(it) } || path.startsWith("$classFileNameWithoutExtension$")
|
||||||
|
else -> error("JUnit5 should not be reachable because of early exit")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user