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


##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/lastfailed/LastFailedTestsResolver.java:
##########
@@ -207,9 +206,10 @@ public LastFailedTests resolve(Collection<String> 
scannedClasses, TestListResolv
      */
     private static List<String> wholeClassPatterns(String className, 
TestListResolver userFilter) {
         String classFile = toClassFileName(className);
+        String topLevelClassFile = toClassFileName(topLevelClass(className));
         List<String> patterns = new ArrayList<>();
         for (ResolvedTest included : userFilter.getIncludedPatterns()) {
-            if (included.matchAsInclusive(classFile, null)) {
+            if (included.matchAsInclusive(classFile, null) || 
included.matchAsInclusive(topLevelClassFile, null)) {

Review Comment:
   For a nested initialization error with `-Dtest=FooTest,FooTest$Inner#a`, 
accepting the outer `FooTest` include here returns the whole nested class, 
although normal execution permits only its method `a`. This also projects 
outer-only method includes onto eligible nested classes, such as adding `b` for 
`FooTest*#a,FooTest#b`, even if the eligibility helper is fixed. Only inherit 
outer-class includes when the filter has no method patterns, and add 
mixed-filter regression coverage.



##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/lastfailed/LastFailedTestsResolver.java:
##########
@@ -220,6 +220,15 @@ private static List<String> wholeClassPatterns(String 
className, TestListResolve
         return patterns.isEmpty() ? singletonList(className) : patterns;
     }
 
+    /**
+     * The reports name a nested class {@code OrderTest$Create}, while {@code 
-Dtest=OrderTest} only matches
+     * {@code OrderTest}. Its nested classes run with it, so we check the 
top-level class too.
+     */
+    private static boolean shouldRun(TestListResolver userFilter, String 
className, String methodName) {
+        return userFilter.shouldRun(toClassFileName(className), methodName)
+                || 
userFilter.shouldRun(toClassFileName(topLevelClass(className)), methodName);

Review Comment:
   With a previous `FooTest$Inner#m` failure, `-Dtest=FooTest#m` now selects 
the nested method even though `TestMethodFilter` matches method-qualified 
filters against the actual nested class and excludes it. Gate this fallback on 
`!userFilter.hasMethodPatterns()` so reruns stay within the requested 
selection. Update the initialization-error expectation in 
`LastFailedTestsResolverTest:165–171` and add a matching-method regression case 
(`FooTest#m` rather than only `FooTest#other`).



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