@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 public void create_command() { Command command = Command.create("java"); command.addArgument("-Xmx512m"); command.addArguments(Arrays.asList("-a", "-b")); command.addArguments(new String[] {"-x", "-y"}); assertThat(command.getExecutable()).isEqualTo("java"); assertThat(command.getArguments()).hasSize(5); assertThat(command.toCommandLine()).isEqualTo("java -Xmx512m -a -b -x -y"); }
@Test public void toString_is_the_command_line() { Command command = Command.create("java"); command.addArgument("-Xmx512m"); assertThat(command.toString()).isEqualTo(command.toCommandLine()); }
@Test public void create_command_with_masked_arguments() { Command command = Command.create("java"); command.addArgument("-Xmx512m"); command.addMaskedArgument("s3cr3t"); command.addArguments(new String[] {"-x", "-y"}); assertThat(command.getExecutable()).isEqualTo("java"); assertThat(command.getArguments()).hasSize(4); assertThat(command.toCommandLine()).isEqualTo("java -Xmx512m s3cr3t -x -y"); assertThat(command.toString()).isEqualTo("java -Xmx512m ******** -x -y"); }
int baseCommandLength = baseCommand.toCommandLine().length(); int availableForBatching = MAX_COMMAND_LENGTH - baseCommandLength; LOG.debug("Executing TsLint with command: {}", thisCommand.toCommandLine());