|
16 | 16 | import org.junit.Assert; |
17 | 17 | import org.junit.jupiter.api.Test; |
18 | 18 | import org.junit.jupiter.api.Timeout; |
| 19 | +import org.junit.jupiter.api.condition.EnabledOnOs; |
| 20 | +import org.junit.jupiter.api.condition.OS; |
19 | 21 | import org.junit.jupiter.api.io.TempDir; |
20 | 22 |
|
21 | 23 | import dev.jbang.BaseTest; |
@@ -60,6 +62,55 @@ void testHasJBangSetup(@TempDir Path tempDir) throws IOException { |
60 | 62 | assertThat(App.AppSetup.hasJBangSetup(rcFile), is(true)); |
61 | 63 | } |
62 | 64 |
|
| 65 | + @Test |
| 66 | + @EnabledOnOs(OS.WINDOWS) |
| 67 | + void testUpdateStagesWindowsCmdLauncher(@TempDir Path tempDir) throws IOException, InterruptedException { |
| 68 | + Path source = Files.createDirectory(tempDir.resolve("source")); |
| 69 | + Path target = Settings.getConfigBinDir(); |
| 70 | + Files.createDirectories(target); |
| 71 | + Files.writeString(source.resolve("jbang"), "new sh"); |
| 72 | + Files.writeString(source.resolve("jbang.cmd"), "new cmd"); |
| 73 | + Files.writeString(source.resolve("jbang.ps1"), "new ps1"); |
| 74 | + Files.writeString(source.resolve("jbang.jar"), "new jar"); |
| 75 | + Files.writeString(target.resolve("jbang.cmd"), "running cmd"); |
| 76 | + Files.writeString(target.resolve("jbang.jar"), "running jar"); |
| 77 | + environmentVariables.set(Util.JBANG_RUNTIME_SHELL, "cmd"); |
| 78 | + |
| 79 | + App.AppInstall.copyJBangFiles(source, target); |
| 80 | + |
| 81 | + assertThat(Files.readString(target.resolve("jbang.cmd")), is("running cmd")); |
| 82 | + assertThat(Files.readString(target.resolve("jbang.cmd.new")), is("new cmd")); |
| 83 | + assertThat(Files.readString(target.resolve("jbang")), is("new sh")); |
| 84 | + assertThat(Files.readString(target.resolve("jbang.ps1")), is("new ps1")); |
| 85 | + assertThat(Files.readString(target.resolve("jbang.jar")), is("running jar")); |
| 86 | + assertThat(Files.readString(target.resolve("jbang.jar.new")), is("new jar")); |
| 87 | + |
| 88 | + String updateCommand = App.AppInstall.cmdLauncherUpdateCommand(); |
| 89 | + assertThat(updateCommand, notNullValue()); |
| 90 | + Process process = new ProcessBuilder("cmd", "/d", "/c", updateCommand).start(); |
| 91 | + assertThat(process.waitFor(), is(0)); |
| 92 | + assertThat(Files.readString(target.resolve("jbang.cmd")), is("new cmd")); |
| 93 | + assertThat(target.resolve("jbang.cmd.new").toFile(), not(anExistingFile())); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + @EnabledOnOs(OS.WINDOWS) |
| 98 | + void testUpdateReplacesStagedCmdLauncherOutsideCmd(@TempDir Path tempDir) throws IOException { |
| 99 | + Path source = Files.createDirectory(tempDir.resolve("source")); |
| 100 | + Path target = Files.createDirectory(tempDir.resolve("target")); |
| 101 | + Files.writeString(source.resolve("jbang"), "new sh"); |
| 102 | + Files.writeString(source.resolve("jbang.cmd"), "new cmd"); |
| 103 | + Files.writeString(source.resolve("jbang.ps1"), "new ps1"); |
| 104 | + Files.writeString(source.resolve("jbang.jar"), "new jar"); |
| 105 | + Files.writeString(target.resolve("jbang.cmd"), "old cmd"); |
| 106 | + environmentVariables.set(Util.JBANG_RUNTIME_SHELL, "powershell"); |
| 107 | + |
| 108 | + App.AppInstall.copyJBangFiles(source, target); |
| 109 | + |
| 110 | + assertThat(Files.readString(target.resolve("jbang.cmd")), is("new cmd")); |
| 111 | + assertThat(target.resolve("jbang.cmd.new").toFile(), not(anExistingFile())); |
| 112 | + } |
| 113 | + |
63 | 114 | @Test |
64 | 115 | void testAppInstallFile() throws Exception { |
65 | 116 | String src = examplesTestFolder.resolve("with space/helloworld.java").toString(); |
|
0 commit comments