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


##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/lastfailed/LastFailedTestsResolver.java:
##########
@@ -176,14 +181,33 @@ public LastFailedTests resolve(Collection<String> 
scannedClasses, TestListResolv
         for (String className : wholeClasses) {
             tests.addAll(wholeClassPatterns(className, userFilter));
         }
+        List<String> failedMethodPatterns = new ArrayList<>();
         int failedMethodCount = 0;
+        boolean allInWholeClasses = true;
         for (Map.Entry<String, Set<String>> entry : failedMethods.entrySet()) {
+            String className = entry.getKey();
             // no need to list the failed methods of a class we run whole
-            if (!wholeClasses.contains(entry.getKey())) {
-                tests.add(entry.getKey() + "#" + String.join("+", 
entry.getValue()));
+            if (!wholeClasses.contains(className)) {
+                failedMethodPatterns.add(className + "#" + String.join("+", 
entry.getValue()));
                 failedMethodCount += entry.getValue().size();
+                allInWholeClasses &= enclosingClasses(className, 
reportClasses.get(className)).stream()
+                        .anyMatch(wholeClasses::contains);
             }
         }
+        // The same goes for the nested classes of a class we run whole, but 
only when no method gets named:
+        // that would turn on the method filter in the fork and leave the 
other nested tests out.
+        if (allInWholeClasses && !userFilter.hasMethodPatterns()) {
+            failedMethodPatterns.clear();
+            failedMethodCount = 0;
+        }
+        // Once we name a method, FooTest$* keeps the nested tests of a class 
we run whole. Not when -Dtest
+        // names methods itself: then they didn't run with their class in the 
first place.
+        if (!failedMethodPatterns.isEmpty() && 
!userFilter.hasMethodPatterns()) {
+            for (String className : wholeClasses) {
+                tests.add(className + "$*");

Review Comment:
   This wildcard also expands the classpath rescan, not just the fork's method 
filter: `AbstractSurefireMojo` rescans after installing 
`lastFailed.getTests()`. For example, with `-Dtest=FooTest,BarTest`, an 
`@AfterAll` failure in FooTest and a failed BarTest#x produce `pkg.FooTest$*`, 
which also selects an independently runnable static class such as 
FooTest$SlowTest—even though it was outside the original selection. Keep the 
wildcard confined to method filtering, rather than using it to discover 
additional standalone classes.



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