Skip to content

Commit

Permalink
Fix spotlessFiles parameter tests
Browse files Browse the repository at this point in the history
- `(`,`|` 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.
  • Loading branch information
driv committed Nov 15, 2020
1 parent 5d965e7 commit 90f1f1d
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,29 @@
package com.diffplug.spotless.maven;

import java.io.IOException;
import java.nio.file.Path;

import org.junit.Test;

public class SpecificFilesTest extends MavenIntegrationHarness {
private String testFile(int number, boolean absolute) throws IOException {
String rel = "src/main/java/test" + number + ".java";
Path path;
if (absolute) {
return rootFolder() + "/" + rel;
path = Path.of(rootFolder().getAbsolutePath(), rel);
} else {
return rel;
path = Path.of(rel);
}
String result = path.toString();
if (!isOnWindows()) {
return result;
} else {
return result.replace("\\", "\\\\");
}
}

private boolean isOnWindows() {
return System.getProperty("os.name").startsWith("Windows");
}

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

@Test
public void regexp() throws IOException, InterruptedException {
integration(".*/src/main/java/test\\(1\\|3\\).java", true, false, true);
String pattern;
if (isOnWindows())
pattern = "\".*\\\\src\\\\main\\\\java\\\\test(1|3).java\"";
else
pattern = ".*/src/main/java/test(1|3).java";
integration(pattern, true, false, true);
}
}

0 comments on commit 90f1f1d

Please sign in to comment.