This is an automated email from the ASF dual-hosted git repository.
olamy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/master by this push:
new 7f99fce4d [SUREFIRE-1599] Stop converting testClassFile's separator
for %regex patterns (#3598)
7f99fce4d is described below
commit 7f99fce4daf4fc2b026ee9e30feeb2c11dea3c9b
Author: Arturo Bernal <[email protected]>
AuthorDate: Mon Nov 23 12:10:54 2026 +0100
[SUREFIRE-1599] Stop converting testClassFile's separator for %regex
patterns (#3598)
matchClassRegexPatter converted testClassFile's separator to the
platform's (replacing '/' with '\' on Windows) but left classPattern -
the user's %regex[...] expression - untouched, so a pattern like
%regex[it/.*] could never match on Windows: the file path had backslashes,
the pattern still had a literal forward slash.
Both sides are documented to always use forward slashes, even on
Windows (inclusion-exclusion.md.vm), and testClassFile is in fact always
built with a literal '/' (FileScanner), never File.separator - so unlike
matchClassPatter, which legitimately converts both sides for its
non-regex Ant-style patterns, there is nothing to convert here at all.
Fixes #2255
---
.../org/apache/maven/surefire/api/testset/ResolvedTest.java | 7 +++++--
.../apache/maven/surefire/api/testset/ResolvedTestTest.java | 11 +++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git
a/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/ResolvedTest.java
b/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/ResolvedTest.java
index 3c6b0244b..50b448d99 100644
---
a/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/ResolvedTest.java
+++
b/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/ResolvedTest.java
@@ -355,8 +355,11 @@ private boolean matchClassPatter(String testClassFile) {
}
private boolean matchClassRegexPatter(String testClassFile) {
- String realFile = separatorChar == '/' ? testClassFile :
testClassFile.replace('/', separatorChar);
- return of(classPattern).matches(realFile, true);
+ // testClassFile is always forward-slash (see
FileScanner/TestListResolver), and so is the user's
+ // %regex[...] pattern by documented contract
(inclusion-exclusion.md.vm: "Slashes here are forward,
+ // even on Windows") - neither side is platform-native, so unlike
matchClassPatter there is nothing
+ // to convert here.
+ return of(classPattern).matches(testClassFile, true);
}
}
diff --git
a/surefire-api/src/test/java/org/apache/maven/surefire/api/testset/ResolvedTestTest.java
b/surefire-api/src/test/java/org/apache/maven/surefire/api/testset/ResolvedTestTest.java
index 03a420e1c..e0946f445 100644
---
a/surefire-api/src/test/java/org/apache/maven/surefire/api/testset/ResolvedTestTest.java
+++
b/surefire-api/src/test/java/org/apache/maven/surefire/api/testset/ResolvedTestTest.java
@@ -73,4 +73,15 @@ public void testFromFullyQualifiedClass() {
classFileName = fromFullyQualifiedClass("my.package.MyTest.*");
assertEquals("my/package/MyTest.*", classFileName);
}
+
+ @Test
+ public void testRegexPatternUsesForwardSlashesLikeTestClassFile() {
+ // Per inclusion-exclusion.md.vm: "Regex matches are done over paths
using slashes ("/") ...
+ // Slashes here are forward, even on Windows." testClassFile (built by
FileScanner) is always
+ // forward-slash too, so neither side of this match should ever be
converted to the platform's
+ // separator - %regex[it/.*] must keep matching
"it/ExampleIntegrationTest.class" everywhere.
+ ResolvedTest test = new ResolvedTest(CLASS, "it/.*", true);
+ assertTrue(test.matchAsInclusive("it/ExampleIntegrationTest.class",
null));
+
assertFalse(test.matchAsInclusive("other/ExampleIntegrationTest.class", null));
+ }
}