Add test with long execution command

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2019-06-08 19:59:26 -04:00
parent 7a2991acc1
commit ba61efaa4a
2 changed files with 23 additions and 1 deletions

View File

@ -101,7 +101,7 @@ public class ExecSystemCommand extends Command {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os))) {
while (th.isAlive()) {
final String user = in.prompt();
// Avoid interruption being sent to process.
// Forward to process if not empty.
if (!user.isEmpty()) {
writer.write(user + EOL);
}

View File

@ -79,4 +79,26 @@ public class ExecSystemCommandTest {
}
}
/** Test the execution of the command.
*
* @throws CommandRunException if the command fails */
@Test
public void testLongExecute() throws CommandRunException {
final ConsoleOutput out = SinkOutput.INSTANCE;
final ConsoleInput in = EmptyInput.INSTANCE;
final ExecSystemCommand cmd = new ExecSystemCommand();
if (System.getProperty("os.name").contains("indows")) {
cmd.execute(out, in, "cmd", "/C", "dir", "/s");
} else if (System.getProperty("os.name").contains("inux")) {
cmd.execute(out, in, "ls", "-R");
}
try {
cmd.execute(out, in, "inexistent");
fail("Able to execute inexistent command in system");
} catch (final CommandRunException e) {
// ok
}
}
}