Search in sources :

Example 96 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class ShellStepTest method testStdErrPrintedOnErrorIfNotSilentEvenIfNotShouldPrintStdErr.

@Test
public void testStdErrPrintedOnErrorIfNotSilentEvenIfNotShouldPrintStdErr() throws Exception {
    ShellStep command = createCommand(/*shouldPrintStdErr*/
    false, /*shouldPrintStdOut*/
    false);
    ProcessExecutorParams params = createParams();
    FakeProcess process = new FakeProcess(EXIT_FAILURE, OUTPUT_MSG, ERROR_MSG);
    TestConsole console = new TestConsole(Verbosity.STANDARD_INFORMATION);
    ExecutionContext context = createContext(ImmutableMap.of(params, process), console);
    command.launchAndInteractWithProcess(context, params);
    assertEquals(ERROR_MSG, console.getTextWrittenToStdErr());
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcess(com.facebook.buck.util.FakeProcess) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 97 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class ShellStepTest method testStdErrPrintedOnSuccessIfShouldPrintStdErrEvenIfSilent.

@Test
public void testStdErrPrintedOnSuccessIfShouldPrintStdErrEvenIfSilent() throws Exception {
    ShellStep command = createCommand(/*shouldPrintStdErr*/
    true, /*shouldPrintStdOut*/
    false);
    ProcessExecutorParams params = createParams();
    FakeProcess process = new FakeProcess(EXIT_SUCCESS, OUTPUT_MSG, ERROR_MSG);
    TestConsole console = new TestConsole(Verbosity.SILENT);
    ExecutionContext context = createContext(ImmutableMap.of(params, process), console);
    command.launchAndInteractWithProcess(context, params);
    assertEquals(ERROR_MSG, console.getTextWrittenToStdErr());
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcess(com.facebook.buck.util.FakeProcess) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 98 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class ShellStepTest method testStdinDoesNotGetToProcessWhenAbsent.

@Test
public void testStdinDoesNotGetToProcessWhenAbsent() throws Exception {
    final Optional<String> stdin = Optional.empty();
    ShellStep command = createCommand(ImmutableMap.of(), ImmutableList.of("cat", "-"), null, /*shouldPrintStdErr*/
    true, /*shouldPrintStdOut*/
    true, stdin);
    ProcessExecutorParams params = createParams();
    FakeProcess process = new FakeProcess(EXIT_SUCCESS, OUTPUT_MSG, ERROR_MSG);
    TestConsole console = new TestConsole(Verbosity.ALL);
    ExecutionContext context = createContext(ImmutableMap.of(params, process), console);
    command.launchAndInteractWithProcess(context, params);
    assertEquals("", process.getOutput());
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcess(com.facebook.buck.util.FakeProcess) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 99 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class ShellStepTest method testStdOutNotPrintedIfNotShouldRecordStdoutEvenIfVerbose.

@Test
public void testStdOutNotPrintedIfNotShouldRecordStdoutEvenIfVerbose() throws Exception {
    ShellStep command = createCommand(/*shouldPrintStdErr*/
    false, /*shouldPrintStdOut*/
    false);
    ProcessExecutorParams params = createParams();
    FakeProcess process = new FakeProcess(EXIT_SUCCESS, OUTPUT_MSG, ERROR_MSG);
    TestConsole console = new TestConsole(Verbosity.ALL);
    ExecutionContext context = createContext(ImmutableMap.of(params, process), console);
    command.launchAndInteractWithProcess(context, params);
    assertEquals("", console.getTextWrittenToStdErr());
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcess(com.facebook.buck.util.FakeProcess) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 100 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class ShellStepTest method testStdinGetsToProcessWhenPresent.

@Test
public void testStdinGetsToProcessWhenPresent() throws Exception {
    final Optional<String> stdin = Optional.of("hello world!");
    ShellStep command = createCommand(ImmutableMap.of(), ImmutableList.of("cat", "-"), null, /*shouldPrintStdErr*/
    true, /*shouldPrintStdOut*/
    true, stdin);
    ProcessExecutorParams params = createParams();
    FakeProcess process = new FakeProcess(EXIT_SUCCESS, OUTPUT_MSG, ERROR_MSG);
    TestConsole console = new TestConsole(Verbosity.ALL);
    ExecutionContext context = createContext(ImmutableMap.of(params, process), console);
    command.launchAndInteractWithProcess(context, params);
    assertEquals(stdin.get(), process.getOutput());
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcess(com.facebook.buck.util.FakeProcess) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Aggregations

TestConsole (com.facebook.buck.testutil.TestConsole)100 Test (org.junit.Test)74 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)27 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)27 ExecutionContext (com.facebook.buck.step.ExecutionContext)25 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)25 Path (java.nio.file.Path)21 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)16 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)16 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)16 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)16 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)16 BuckEventBus (com.facebook.buck.event.BuckEventBus)15 FakeProcess (com.facebook.buck.util.FakeProcess)14 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)13 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)12 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)11 Clock (com.facebook.buck.timing.Clock)10 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)9 BuildTarget (com.facebook.buck.model.BuildTarget)8