Copilot commented on code in PR #3647:
URL: https://github.com/apache/maven-surefire/pull/3647#discussion_r4734166979


##########
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:
   This early return bypasses the enclosing-class exclusion check when a 
wildcard include directly matches a descendant, or when the filter contains 
only exclusions. For a failure in `FooTest$Inner$Deep#m` reported under 
`FooTest`, `-Dtest=FooTest*,!FooTest$Inner` selects the failure, whereas 
`-Dtest=FooTest,!FooTest$Inner` correctly omits it. Check ancestor exclusions 
before accepting a direct match when there are no method patterns, and add 
wildcard and exclude-only regression cases.



-- 
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]

Reply via email to