Skip to content

Commit 90f1f1d

Browse files
committed
Fix spotlessFiles parameter tests
- `(`,`|` and `)` should not be escaped with `\`, otherwise they get interpreted as literals and no file matches - On Windows paths use backslashes, so `\\\\` has to be used. 2 for java strings and 2 since this parameter is treated as a regex.
1 parent 5d965e7 commit 90f1f1d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

plugin-maven/src/test/java/com/diffplug/spotless/maven/SpecificFilesTest.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,29 @@
1616
package com.diffplug.spotless.maven;
1717

1818
import java.io.IOException;
19+
import java.nio.file.Path;
1920

2021
import org.junit.Test;
2122

2223
public class SpecificFilesTest extends MavenIntegrationHarness {
2324
private String testFile(int number, boolean absolute) throws IOException {
2425
String rel = "src/main/java/test" + number + ".java";
26+
Path path;
2527
if (absolute) {
26-
return rootFolder() + "/" + rel;
28+
path = Path.of(rootFolder().getAbsolutePath(), rel);
2729
} else {
28-
return rel;
30+
path = Path.of(rel);
2931
}
32+
String result = path.toString();
33+
if (!isOnWindows()) {
34+
return result;
35+
} else {
36+
return result.replace("\\", "\\\\");
37+
}
38+
}
39+
40+
private boolean isOnWindows() {
41+
return System.getProperty("os.name").startsWith("Windows");
3042
}
3143

3244
private String testFile(int number) throws IOException {
@@ -73,6 +85,11 @@ public void multiFile() throws IOException, InterruptedException {
7385

7486
@Test
7587
public void regexp() throws IOException, InterruptedException {
76-
integration(".*/src/main/java/test\\(1\\|3\\).java", true, false, true);
88+
String pattern;
89+
if (isOnWindows())
90+
pattern = "\".*\\\\src\\\\main\\\\java\\\\test(1|3).java\"";
91+
else
92+
pattern = ".*/src/main/java/test(1|3).java";
93+
integration(pattern, true, false, true);
7794
}
7895
}

0 commit comments

Comments
 (0)