Search in sources :

Example 21 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.

the class XctoolRunTestsStepTest method xctoolCommandWhichReturnsExitCode400FailsStep.

@Test
public void xctoolCommandWhichReturnsExitCode400FailsStep() throws Exception {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    XctoolRunTestsStep step = new XctoolRunTestsStep(projectFilesystem, Paths.get("/path/to/xctool"), ImmutableMap.of(), Optional.empty(), "iphonesimulator", Optional.empty(), ImmutableSet.of(Paths.get("/path/to/Foo.xctest")), ImmutableMap.of(), Paths.get("/path/to/output.json"), Optional.empty(), Suppliers.ofInstance(Optional.of(Paths.get("/path/to/developer/dir"))), TestSelectorList.EMPTY, false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    ProcessExecutorParams xctoolParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("/path/to/xctool", "-reporter", "json-stream", "-sdk", "iphonesimulator", "run-tests", "-logicTest", "/path/to/Foo.xctest")).setEnvironment(ImmutableMap.of("DEVELOPER_DIR", "/path/to/developer/dir")).setDirectory(projectFilesystem.getRootPath().toAbsolutePath()).setRedirectOutput(ProcessBuilder.Redirect.PIPE).build();
    FakeProcess fakeXctoolFailure = new FakeProcess(400, "", "");
    FakeProcessExecutor processExecutor = new FakeProcessExecutor(ImmutableMap.of(xctoolParams, fakeXctoolFailure));
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(processExecutor).setEnvironment(ImmutableMap.of()).build();
    assertThat(step.execute(executionContext).getExitCode(), not(equalTo(0)));
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProcess(com.facebook.buck.util.FakeProcess) Test(org.junit.Test)

Example 22 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.

the class XctoolRunTestsStepTest method xctoolCommandWithTestSelectorFailsIfListTestsOnlyFails.

@Test
public void xctoolCommandWithTestSelectorFailsIfListTestsOnlyFails() throws Exception {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    XctoolRunTestsStep step = new XctoolRunTestsStep(projectFilesystem, Paths.get("/path/to/xctool"), ImmutableMap.of(), Optional.empty(), "iphonesimulator", Optional.empty(), ImmutableSet.of(Paths.get("/path/to/FooTest.xctest"), Paths.get("/path/to/BarTest.xctest")), ImmutableMap.of(), Paths.get("/path/to/output.json"), Optional.empty(), Suppliers.ofInstance(Optional.of(Paths.get("/path/to/developer/dir"))), TestSelectorList.builder().addRawSelectors("#.*Magic.*").build(), false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    ProcessExecutorParams xctoolListOnlyParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("/path/to/xctool", "-reporter", "json-stream", "-sdk", "iphonesimulator", "run-tests", "-logicTest", "/path/to/FooTest.xctest", "-logicTest", "/path/to/BarTest.xctest", "-listTestsOnly")).setEnvironment(ImmutableMap.of("DEVELOPER_DIR", "/path/to/developer/dir")).setDirectory(projectFilesystem.getRootPath().toAbsolutePath()).setRedirectOutput(ProcessBuilder.Redirect.PIPE).build();
    FakeProcess fakeXctoolListTestsFailureProcess = new FakeProcess(42, "", "Chopper Dave, we have Uh-Oh");
    FakeProcessExecutor processExecutor = new FakeProcessExecutor(ImmutableMap.of(xctoolListOnlyParams, fakeXctoolListTestsFailureProcess));
    TestConsole testConsole = new TestConsole();
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(processExecutor).setEnvironment(ImmutableMap.of()).setConsole(testConsole).build();
    assertThat(step.execute(executionContext).getExitCode(), equalTo(42));
    assertThat(testConsole.getTextWrittenToStdErr(), allOf(containsString("xctool failed with exit code 42: Chopper Dave, we have Uh-Oh"), containsString("Failed to query tests with xctool")));
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProcess(com.facebook.buck.util.FakeProcess) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 23 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.

the class XctoolRunTestsStepTest method xctoolCommandWhichReturnsExitCode1DoesNotFailStep.

@Test
public void xctoolCommandWhichReturnsExitCode1DoesNotFailStep() throws Exception {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    XctoolRunTestsStep step = new XctoolRunTestsStep(projectFilesystem, Paths.get("/path/to/xctool"), ImmutableMap.of(), Optional.empty(), "iphonesimulator", Optional.empty(), ImmutableSet.of(Paths.get("/path/to/Foo.xctest")), ImmutableMap.of(), Paths.get("/path/to/output.json"), Optional.empty(), Suppliers.ofInstance(Optional.of(Paths.get("/path/to/developer/dir"))), TestSelectorList.EMPTY, false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    ProcessExecutorParams xctoolParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("/path/to/xctool", "-reporter", "json-stream", "-sdk", "iphonesimulator", "run-tests", "-logicTest", "/path/to/Foo.xctest")).setEnvironment(ImmutableMap.of("DEVELOPER_DIR", "/path/to/developer/dir")).setDirectory(projectFilesystem.getRootPath().toAbsolutePath()).setRedirectOutput(ProcessBuilder.Redirect.PIPE).build();
    // Test failure is indicated by xctool exiting with exit code 1, so it shouldn't
    // fail the step.
    FakeProcess fakeXctoolTestFailure = new FakeProcess(1, "", "");
    FakeProcessExecutor processExecutor = new FakeProcessExecutor(ImmutableMap.of(xctoolParams, fakeXctoolTestFailure));
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(processExecutor).setEnvironment(ImmutableMap.of()).build();
    assertThat(step.execute(executionContext).getExitCode(), equalTo(0));
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProcess(com.facebook.buck.util.FakeProcess) Test(org.junit.Test)

Example 24 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.

the class XctoolRunTestsStepTest method xctoolCommandWithAppAndLogicTests.

@Test
public void xctoolCommandWithAppAndLogicTests() throws Exception {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    XctoolRunTestsStep step = new XctoolRunTestsStep(projectFilesystem, Paths.get("/path/to/xctool"), ImmutableMap.of(), Optional.empty(), "iphonesimulator", Optional.of("name=iPhone 5s,OS=8.2"), ImmutableSet.of(Paths.get("/path/to/FooLogicTest.xctest")), ImmutableMap.of(Paths.get("/path/to/FooAppTest.xctest"), Paths.get("/path/to/Foo.app")), Paths.get("/path/to/output.json"), Optional.empty(), Suppliers.ofInstance(Optional.of(Paths.get("/path/to/developer/dir"))), TestSelectorList.EMPTY, false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    ProcessExecutorParams xctoolParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("/path/to/xctool", "-reporter", "json-stream", "-sdk", "iphonesimulator", "-destination", "name=iPhone 5s,OS=8.2", "run-tests", "-logicTest", "/path/to/FooLogicTest.xctest", "-appTest", "/path/to/FooAppTest.xctest:/path/to/Foo.app")).setEnvironment(ImmutableMap.of("DEVELOPER_DIR", "/path/to/developer/dir")).setDirectory(projectFilesystem.getRootPath().toAbsolutePath()).setRedirectOutput(ProcessBuilder.Redirect.PIPE).build();
    FakeProcess fakeXctoolSuccess = new FakeProcess(0, "", "");
    FakeProcessExecutor processExecutor = new FakeProcessExecutor(ImmutableMap.of(xctoolParams, fakeXctoolSuccess));
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(processExecutor).setEnvironment(ImmutableMap.of()).build();
    assertThat(step.execute(executionContext).getExitCode(), equalTo(0));
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProcess(com.facebook.buck.util.FakeProcess) Test(org.junit.Test)

Example 25 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.

the class XctoolRunTestsStepTest method xctoolCommandWithOnlyAppTests.

@Test
public void xctoolCommandWithOnlyAppTests() throws Exception {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    XctoolRunTestsStep step = new XctoolRunTestsStep(projectFilesystem, Paths.get("/path/to/xctool"), ImmutableMap.of(), Optional.empty(), "iphonesimulator", Optional.of("name=iPhone 5s"), ImmutableSet.of(), ImmutableMap.of(Paths.get("/path/to/FooAppTest.xctest"), Paths.get("/path/to/Foo.app")), Paths.get("/path/to/output.json"), Optional.empty(), Suppliers.ofInstance(Optional.of(Paths.get("/path/to/developer/dir"))), TestSelectorList.EMPTY, false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    ProcessExecutorParams xctoolParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("/path/to/xctool", "-reporter", "json-stream", "-sdk", "iphonesimulator", "-destination", "name=iPhone 5s", "run-tests", "-appTest", "/path/to/FooAppTest.xctest:/path/to/Foo.app")).setEnvironment(ImmutableMap.of("DEVELOPER_DIR", "/path/to/developer/dir")).setDirectory(projectFilesystem.getRootPath().toAbsolutePath()).setRedirectOutput(ProcessBuilder.Redirect.PIPE).build();
    FakeProcess fakeXctoolSuccess = new FakeProcess(0, "", "");
    FakeProcessExecutor processExecutor = new FakeProcessExecutor(ImmutableMap.of(xctoolParams, fakeXctoolSuccess));
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(processExecutor).setEnvironment(ImmutableMap.of()).build();
    assertThat(step.execute(executionContext).getExitCode(), equalTo(0));
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProcess(com.facebook.buck.util.FakeProcess) Test(org.junit.Test)

Aggregations

ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)72 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)32 FakeProcess (com.facebook.buck.util.FakeProcess)30 Test (org.junit.Test)30 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)21 ExecutionContext (com.facebook.buck.step.ExecutionContext)19 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)19 IOException (java.io.IOException)18 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)12 TestConsole (com.facebook.buck.testutil.TestConsole)12 Path (java.nio.file.Path)11 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)8 ListeningProcessExecutor (com.facebook.buck.util.ListeningProcessExecutor)6 HumanReadableException (com.facebook.buck.util.HumanReadableException)5 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableSet (com.google.common.collect.ImmutableSet)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4 Matcher (java.util.regex.Matcher)4