Copilot commented on code in PR #3647:
URL: https://github.com/apache/maven-surefire/pull/3647#discussion_r4733006442
##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/lastfailed/LastFailedTestsResolver.java:
##########
@@ -176,14 +181,40 @@ 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, we name the nested classes of a class we run
whole too, or the fork leaves their
+ // tests out. Not when -Dtest names methods itself: then they didn't
run with their class in the first place.
+ if (!failedMethodPatterns.isEmpty() &&
!userFilter.hasMethodPatterns()) {
+ Set<String> reportClassNames = new HashSet<>(suites.values());
+ for (String className : wholeClasses) {
+ if (unfinishedClasses.contains(className) &&
!reportClassNames.contains(className)) {
+ // no report, so we don't know its nested classes.
FooTest$* may also pick a static nested
+ // class that has its own report, but that's better than
losing tests.
+ tests.add(className + "$*");
Review Comment:
When `-Dtest=FooTest,BarTest` selects an unfinished `FooTest` with no report
and a failed `BarTest#x`, this produces
`pkg.FooTest,pkg.FooTest$*,pkg.BarTest#x`. `AbstractSurefireMojo` rescans using
those patterns, so an independent static `FooTest$SlowTest` is now selected and
executed even though the original test parameter excluded it. Keep the
descendant allowance out of the scanner's class selection; apply it only to
nested tests discovered through the selected outer class, or determine the
actual nested classes before expanding the selection.
##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/lastfailed/LastFailedTestsResolver.java:
##########
@@ -176,14 +181,40 @@ 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, we name the nested classes of a class we run
whole too, or the fork leaves their
+ // tests out. Not when -Dtest names methods itself: then they didn't
run with their class in the first place.
+ if (!failedMethodPatterns.isEmpty() &&
!userFilter.hasMethodPatterns()) {
+ Set<String> reportClassNames = new HashSet<>(suites.values());
+ for (String className : wholeClasses) {
+ if (unfinishedClasses.contains(className) &&
!reportClassNames.contains(className)) {
+ // no report, so we don't know its nested classes.
FooTest$* may also pick a static nested
+ // class that has its own report, but that's better than
losing tests.
+ tests.add(className + "$*");
+ } else {
+ tests.addAll(nestedClasses(className, suites));
Review Comment:
An existing report may omit nested descendants, for example after an outer
or nested class's `@BeforeAll` failure, or when an unfinished class has an
older, method-filtered report. If another class contributes a failed method
such as `BarTest#x`, the rerun's method filter rejects those unlisted
descendants even though their enclosing class should run whole. Discover the
actual nested hierarchy or preserve whole-subtree selection in the provider,
and add regressions for setup failures and incomplete older reports.
--
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]