olamy commented on code in PR #3647:
URL: https://github.com/apache/maven-surefire/pull/3647#discussion_r4734320233
##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/lastfailed/LastFailedTestsResolver.java:
##########
@@ -220,16 +244,76 @@ private static List<String> wholeClassPatterns(String
className, TestListResolve
return patterns.isEmpty() ? singletonList(className) : patterns;
}
- private List<ReportTestSuite> readReports() {
+ /**
+ * The report of {@code OrderTest} also holds the tests of its {@code
@Nested} class {@code OrderTest$Create}.
+ * {@code -Dtest=OrderTest} runs them too, as long as no method is named:
a method pattern turns on a filter
+ * in the fork that checks each test by its own class. An exclude of the
nested class still counts, the next
+ * run gets it as well, and so does an exclude of a class it sits in.
+ *
+ * @param reportClass the class whose report holds the test
+ */
+ private static boolean shouldRun(
+ TestListResolver userFilter, String className, String reportClass,
String methodName) {
+ String classFile = toClassFileName(className);
+ if (userFilter.shouldRun(classFile, methodName)) {
+ return true;
+ }
+ if (userFilter.hasMethodPatterns()) {
+ return false;
+ }
+ List<String> enclosingClasses = enclosingClasses(className,
reportClass);
+ List<String> classes = new ArrayList<>(enclosingClasses);
+ classes.add(className);
+ // an exclude of FooTest$Inner also leaves out FooTest$Inner$Deep
+ if (classes.stream()
+ .anyMatch(c -> userFilter.getExcludedPatterns().stream()
+ .anyMatch(excluded ->
excluded.matchAsExclusive(toClassFileName(c), methodName)))) {
+ return false;
+ }
+ return enclosingClasses.stream()
+ .anyMatch(enclosing ->
userFilter.shouldRun(toClassFileName(enclosing), methodName));
Review Comment:
Good catch, thanks. When no method is named, the excludes of the class and
of every class it sits in are now checked before any include, so a wildcard
that matches the nested class directly no longer gets around them.
`-Dtest=FooTest*,!FooTest$Inner` and `-Dtest=!FooTest$Inner` both leave out
`FooTest$Inner$Deep#m` now, like `-Dtest=FooTest,!FooTest$Inner`. Both cases
are in `keepsTheExcludesOfNestedClasses` (7e4a000d5).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]