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


##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java:
##########
@@ -433,6 +449,37 @@ boolean printTestFailures(TestResultType type) {
         return printed;
     }
 
+    /**
+     * Whether a passing test shows that a class whose {@code @BeforeAll} 
failed got through it on a rerun.
+     *
+     * @param failedClass qualified name of the class whose {@code @BeforeAll} 
failed, {@code null} if unknown
+     * @param failedReportClass class name the failure is reported under
+     * @param passedClass qualified name of the class of the passing test, 
{@code null} if unknown
+     * @param passedReportClass class name the passing test is reported under
+     */
+    static boolean passedAfterBeforeAllFailure(
+            String failedClass, String failedReportClass, String passedClass, 
String passedReportClass) {
+        if (failedReportClass == null || 
!failedReportClass.equals(passedReportClass)) {
+            return false;
+        }
+        // A top-level class, or no qualified name: any test reported under 
the same class counts
+        if (failedClass == null || failedClass.equals(failedReportClass)) {
+            return true;
+        }
+        // A nested class is reported under its outer class. Only its own 
tests, or the tests of
+        // classes nested in it, show that its @BeforeAll passed. A passing 
outer test doesn't, nor does
+        // a test with no class, like a dynamic test with a classpath: source.
+        return passedClass != null && (passedClass.equals(failedClass) || 
passedClass.startsWith(failedClass + '$'));

Review Comment:
   When a nested class's fail-once `@BeforeAll` is followed only by passing 
dynamic tests with `classpath:` URI sources, those tests have `passedClass == 
null` and cannot satisfy this check. The retry succeeds, but both XML and 
global statistics retain an error, causing the build to fail. Preserve the 
owning class/container ancestry for recovery matching and add a regression for 
this case; accepting arbitrary source-less siblings would mask genuine failures.



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