Skip to content

Commit a889835

Browse files
committed
fix: use local clang-format instead of globally installed one
1 parent c791663 commit a889835

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

Diff for: testlib/src/main/java/com/diffplug/spotless/cli/ForeignExeMock.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,22 @@ public ForeignExeMockWriter writeReadFromStdin() {
450450
// ─────────────── file → stdout (pad lines) ──────────────
451451
@Override
452452
public ForeignExeMockWriter writeWriteToStdout() {
453-
output.println("for /f \"usebackq delims=\" %%L in (\"!stdin_file!\") do (");
454-
output.println(" set \"line=%%L\"");
455-
output.println(" echo(!line!| findstr /r \" $\" >nul");
456-
output.println(" if errorlevel 1 (");
457-
output.println(" echo(!line! ");
453+
/*
454+
- findstr /n /R ".*" prefixes every line (even empty ones) with N:
455+
- we read each raw line (trailing blanks intact) into %%L
456+
- strip everything up to the first colon: set "line=%%L" & set "line=!line:*:=!"
457+
- preserve / append four blanks with <nul set /p (echo would cut them)
458+
*/
459+
460+
output.println("for /f \"usebackq delims=\" %%L in (`findstr /n /R \".*\" \"!stdin_file!\"`) do (");
461+
output.println(" set \"raw=%%L\"");
462+
output.println(" set \"line=!raw:*:=!\""); // throw away leading N:
463+
output.println(" if \"!line:~-4!\"==\" \" (");
464+
output.println(" <nul set /p \"=!line!\""); // already padded
458465
output.println(" ) else (");
459-
output.println(" echo(!line!");
466+
output.println(" <nul set /p \"=!line! \""); // add 4 blanks
460467
output.println(" )");
468+
output.println(" echo("); // newline
461469
output.println(")");
462470
output.println("del \"!stdin_file!\" >nul 2>&1");
463471
output.println();

Diff for: testlib/src/test/java/com/diffplug/spotless/cli/ForeignExeMockTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ void itWritesAExecutableForeignExeMockThatWritesVersion() throws IOException, In
5656
File mock = createClangFormatForeignExeMock();
5757

5858
try (ProcessRunner runner = new ProcessRunner()) {
59-
ProcessRunner.Result result = runner.exec(rootFolder(), null, null, List.of(mock.getName(), "--version"));
59+
ProcessRunner.Result result =
60+
runner.exec(rootFolder(), null, null, List.of(mock.getAbsolutePath(), "--version"));
6061
String output = result.assertExitZero(StandardCharsets.UTF_8);
6162
assertThat(output).contains("11.0.1");
6263
}
@@ -67,8 +68,8 @@ void itWritesAExecutableForeignExeMockThatChecksValidOptions() throws IOExceptio
6768
File mock = createClangFormatForeignExeMock();
6869

6970
try (ProcessRunner runner = new ProcessRunner()) {
70-
ProcessRunner.Result result =
71-
runner.exec(rootFolder(), null, null, List.of(mock.getName(), "--style", "invalid_style_value"));
71+
ProcessRunner.Result result = runner.exec(
72+
rootFolder(), null, null, List.of(mock.getAbsolutePath(), "--style", "invalid_style_value"));
7273
assertThat(result.exitCode()).isNotEqualTo(0);
7374
assertThat(result.stdOutUtf8()).contains("invalid_style_value");
7475
}
@@ -80,7 +81,7 @@ void itWritesAExecutableForeignExeMockThatConsumesValidOption() throws IOExcepti
8081

8182
try (ProcessRunner runner = new ProcessRunner()) {
8283
ProcessRunner.Result result =
83-
runner.exec(rootFolder(), null, null, List.of(mock.getName(), "--style", "LLVM"));
84+
runner.exec(rootFolder(), null, null, List.of(mock.getAbsolutePath(), "--style", "LLVM"));
8485
String output = result.assertExitZero(StandardCharsets.UTF_8);
8586
}
8687
}
@@ -102,13 +103,12 @@ int main(){
102103
rootFolder(),
103104
null,
104105
input.getBytes(StandardCharsets.UTF_8),
105-
List.of(mock.getName(), "--style", "LLVM"));
106+
List.of(mock.getAbsolutePath(), "--style", "LLVM"));
106107
String output = result.assertExitZero(StandardCharsets.UTF_8);
107108
Selfie.expectSelfie(output).toBe("""
108109
int main(){ \s
109110
return 0; \s
110111
} \s
111-
\s
112112
""");
113113
}
114114
}

0 commit comments

Comments
 (0)