From ba61efaa4aa2765ada97ae9784e6f05ed1f4db62 Mon Sep 17 00:00:00 2001 From: Emmanuel Bigeon Date: Sat, 8 Jun 2019 19:59:26 -0400 Subject: [PATCH] Add test with long execution command Signed-off-by: Emmanuel Bigeon --- .../bigeon/gclc/system/ExecSystemCommand.java | 2 +- .../gclc/system/ExecSystemCommandTest.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gclc.system/src/main/java/net/bigeon/gclc/system/ExecSystemCommand.java b/gclc.system/src/main/java/net/bigeon/gclc/system/ExecSystemCommand.java index b29521a..8707664 100644 --- a/gclc.system/src/main/java/net/bigeon/gclc/system/ExecSystemCommand.java +++ b/gclc.system/src/main/java/net/bigeon/gclc/system/ExecSystemCommand.java @@ -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); } diff --git a/gclc.system/src/test/java/net/bigeon/gclc/system/ExecSystemCommandTest.java b/gclc.system/src/test/java/net/bigeon/gclc/system/ExecSystemCommandTest.java index 11538f2..9488d11 100644 --- a/gclc.system/src/test/java/net/bigeon/gclc/system/ExecSystemCommandTest.java +++ b/gclc.system/src/test/java/net/bigeon/gclc/system/ExecSystemCommandTest.java @@ -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 + } + } + }