Skip to content

Commit

Permalink
Fix CommandRunner test for Windows platform
Browse files Browse the repository at this point in the history
  • Loading branch information
besidev committed Sep 25, 2024
1 parent da6ad59 commit b694da8
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,27 @@ public void runAsync() throws IOException {
} else {
commandRunner.addArgs("ls", "build.gradle");
}
Process process = commandRunner.runAsync("ls");
Process process = commandRunner.runAsync("async-ls");
assertThat(process.getClass()).isAssignableTo(Process.class);
}

@Test
public void runAsyncWithMockDirectoryThrowsException() {
if (PlatformUtils.isWindows()) {
commandRunner.addArgs("cmd", "/c", "dir", "/b", "build.gradle");
assertThatThrownBy(() -> commandRunner.runAsync("async-cmd-dir", mockFile))
.hasMessageContaining("Cannot run program \"cmd\"")
.hasMessageContaining("CreateProcess error=267, The directory name is invalid")
.hasRootCauseMessage("CreateProcess error=267, The directory name is invalid")
.hasCauseInstanceOf(IOException.class);
} else {
commandRunner.addArgs("ls", "build.gradle");
assertThatThrownBy(() -> commandRunner.runAsync("async-ls", mockFile))
.hasMessageContaining("Cannot run program \"ls\"")
.hasMessageContaining("error=2, No such file or directory")
.hasRootCauseMessage("error=2, No such file or directory")
.hasCauseInstanceOf(IOException.class);
}
assertThatThrownBy(() -> commandRunner.runAsync("ls", mockFile))
.hasMessageContaining("Cannot run program \"ls\"")
.hasMessageContaining("error=2, No such file or directory")
.hasRootCauseMessage("error=2, No such file or directory")
.hasCauseInstanceOf(IOException.class);
}

@Test
Expand All @@ -102,7 +107,7 @@ public void runAsyncWithDirectoryAndOutput() throws IOException, InterruptedExce
} else {
commandRunner.addArgs("mkdir", "runner");
}
Process process = commandRunner.runAsync("dir", tempDir.toFile());
Process process = commandRunner.runAsync("async-dir-list", tempDir.toFile());
int result = process.waitFor();
assertThat(result).isEqualTo(0); // Successful execution
assertThat(commandRunner.getLastResponse()).isEqualTo("");
Expand Down

0 comments on commit b694da8

Please sign in to comment.