@Test public void should_use_cmd_for_new_shell_on_windows() { System2 system = mock(System2.class); when(system.isOsWindows()).thenReturn(true); Command command = new Command("foo.bat", system); command.setNewShell(true); assertThat(command.toCommandLine()).isEqualTo("cmd /C call foo.bat"); assertThat(command.isNewShell()).isTrue(); }
@Test public void should_use_sh_for_new_shell_on_unix() { System2 system = mock(System2.class); when(system.isOsWindows()).thenReturn(false); Command command = new Command("foo.sh", system); command.setNewShell(true); assertThat(command.toCommandLine()).isEqualTo("sh foo.sh"); assertThat(command.isNewShell()).isTrue(); }
@Test(timeout = 6000L) public void should_stop_after_timeout_and_new_shell() throws IOException { try { String executable = getScript("forever"); CommandExecutor.create().execute(Command.create(executable).setNewShell(true).setDirectory(workDir), 1000L); fail(); } catch (TimeoutException e) { // ok } }
command.setNewShell(false);