Search in sources :

Example 16 with CommandOutputWithStatus

use of com.google.copybara.util.CommandOutputWithStatus in project copybara by google.

the class CommandRunnerTest method testCommand.

@Test
public void testCommand() throws Exception {
    Command command = new Command(new String[] { "echo", "hello", "world" });
    CommandOutputWithStatus result = runCommand(new CommandRunner(command));
    assertThat(result.getTerminationStatus().success()).isTrue();
    assertThat(result.getStdout()).isEqualTo("hello world\n");
    assertWithMessage("Not empty: %s", new String(outContent.toByteArray(), UTF_8)).that(outContent.toByteArray()).isEmpty();
    assertWithMessage("Not empty: %s", new String(errContent.toByteArray(), UTF_8)).that(errContent.toByteArray()).isEmpty();
    assertLogContains("Executing [echo hello world]", "'echo' STDOUT: hello world", "Command 'echo' finished");
}
Also used : Command(com.google.copybara.shell.Command) CommandOutputWithStatus(com.google.copybara.util.CommandOutputWithStatus) CommandRunner(com.google.copybara.util.CommandRunner) Test(org.junit.Test)

Example 17 with CommandOutputWithStatus

use of com.google.copybara.util.CommandOutputWithStatus in project copybara by google.

the class CommandRunnerTest method testMaxCommandLength.

@Test
public void testMaxCommandLength() throws Exception {
    String[] args = new String[10000];
    args[0] = "echo";
    for (int i = 1; i < 10000; i++) {
        args[i] = "hello world!";
    }
    Command command = new Command(args);
    CommandOutputWithStatus result = runCommand(new CommandRunner(command).withVerbose(true));
    assertThat(result.getTerminationStatus().success()).isTrue();
    assertLogContains("...", "'echo' STDOUT: hello world!", "Command 'echo' finished");
}
Also used : Command(com.google.copybara.shell.Command) CommandOutputWithStatus(com.google.copybara.util.CommandOutputWithStatus) CommandRunner(com.google.copybara.util.CommandRunner) Test(org.junit.Test)

Aggregations

CommandOutputWithStatus (com.google.copybara.util.CommandOutputWithStatus)17 Command (com.google.copybara.shell.Command)10 CommandException (com.google.copybara.shell.CommandException)7 BadExitStatusWithOutputException (com.google.copybara.util.BadExitStatusWithOutputException)7 CommandRunner (com.google.copybara.util.CommandRunner)7 RepoException (com.google.copybara.exception.RepoException)6 ImmutableList (com.google.common.collect.ImmutableList)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ValidationException (com.google.copybara.exception.ValidationException)2 Matcher (com.google.re2j.Matcher)2 IOException (java.io.IOException)2 AccessValidationException (com.google.copybara.exception.AccessValidationException)1 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)1 BufferedWriter (java.io.BufferedWriter)1 Path (java.nio.file.Path)1 PathMatcher (java.nio.file.PathMatcher)1 LinkedHashSet (java.util.LinkedHashSet)1 Matcher (java.util.regex.Matcher)1