Search in sources :

Example 16 with FakeProcess

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

the class AppleSimulatorControllerTest method installingBundleInSimulatorWorks.

@Test
public void installingBundleInSimulatorWorks() throws IOException, InterruptedException {
    FakeProcess fakeSimctlInstallProcess = new FakeProcess(0);
    ProcessExecutorParams fakeSimctlInstallParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("path/to/simctl", "install", "70200ED8-EEF1-4BDB-BCCF-3595B137D67D", "Path/To/MyNeatApp.app")).build();
    FakeProcessExecutor fakeProcessExecutor = new FakeProcessExecutor(ImmutableMap.of(fakeSimctlInstallParams, fakeSimctlInstallProcess));
    AppleSimulatorController appleSimulatorController = new AppleSimulatorController(fakeProcessExecutor, SIMCTL_PATH, IOS_SIMULATOR_PATH);
    boolean installed = appleSimulatorController.installBundleInSimulator("70200ED8-EEF1-4BDB-BCCF-3595B137D67D", Paths.get("Path/To/MyNeatApp.app"));
    assertThat(installed, is(true));
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProcess(com.facebook.buck.util.FakeProcess) Test(org.junit.Test)

Example 17 with FakeProcess

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

the class AppleSimulatorControllerTest method cannotStartSimulatorWhenSimulatorWithDifferentUdidExists.

@Test
public void cannotStartSimulatorWhenSimulatorWithDifferentUdidExists() throws IOException, InterruptedException {
    ImmutableList.Builder<Map.Entry<ProcessExecutorParams, FakeProcess>> fakeProcessesBuilder = ImmutableList.builder();
    fakeProcessesBuilder.add(new SimpleImmutableEntry<>(SIMCTL_LIST_PARAMS, new FakeProcess(0, "    iPhone 5 (45BD7164-686C-474F-8C68-3730432BC5F2) (Booted)\n" + "    iPhone 5s (70200ED8-EEF1-4BDB-BCCF-3595B137D67D) (Shutdown)\n", "")));
    FakeProcessExecutor fakeProcessExecutor = new FakeProcessExecutor(fakeProcessesBuilder.build());
    AppleSimulatorController appleSimulatorController = new AppleSimulatorController(fakeProcessExecutor, SIMCTL_PATH, IOS_SIMULATOR_PATH);
    assertThat(appleSimulatorController.canStartSimulator("70200ED8-EEF1-4BDB-BCCF-3595B137D67D"), is(false));
}
Also used : SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) ImmutableList(com.google.common.collect.ImmutableList) FakeProcess(com.facebook.buck.util.FakeProcess) Test(org.junit.Test)

Example 18 with FakeProcess

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

the class AppleSimulatorControllerTest method startingSimulatorWorksWhenSimulatorNotRunning.

@Test
public void startingSimulatorWorksWhenSimulatorNotRunning() throws IOException, InterruptedException {
    ImmutableList.Builder<Map.Entry<ProcessExecutorParams, FakeProcess>> fakeProcessesBuilder = ImmutableList.builder();
    fakeProcessesBuilder.add(new SimpleImmutableEntry<>(SIMCTL_LIST_PARAMS, new FakeProcess(0)));
    fakeProcessesBuilder.add(new SimpleImmutableEntry<>(ProcessExecutorParams.builder().setCommand(ImmutableList.of("open", "-a", IOS_SIMULATOR_PATH.toString(), "--args", "-CurrentDeviceUDID", "70200ED8-EEF1-4BDB-BCCF-3595B137D67D")).build(), new FakeProcess(0)));
    fakeProcessesBuilder.add(new SimpleImmutableEntry<>(SIMCTL_LIST_PARAMS, new FakeProcess(0, "    iPhone 5 (45BD7164-686C-474F-8C68-3730432BC5F2) (Shutdown)\n" + "    iPhone 5s (70200ED8-EEF1-4BDB-BCCF-3595B137D67D) (Booted)\n", "")));
    FakeProcessExecutor fakeProcessExecutor = new FakeProcessExecutor(fakeProcessesBuilder.build());
    AppleSimulatorController appleSimulatorController = new AppleSimulatorController(fakeProcessExecutor, SIMCTL_PATH, IOS_SIMULATOR_PATH);
    Optional<Long> result = appleSimulatorController.startSimulator("70200ED8-EEF1-4BDB-BCCF-3595B137D67D", 1000);
    assertThat(result, is(Optional.of(0L)));
}
Also used : SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) ImmutableList(com.google.common.collect.ImmutableList) FakeProcess(com.facebook.buck.util.FakeProcess) Test(org.junit.Test)

Example 19 with FakeProcess

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

the class ExternalJavacTest method externalJavacWillHashTheExternalIfNoVersionInformationIsReturned.

@Test
public void externalJavacWillHashTheExternalIfNoVersionInformationIsReturned() throws IOException {
    Path javac = Files.createTempFile("fake", "javac");
    javac.toFile().deleteOnExit();
    ProcessExecutorParams javacExe = ProcessExecutorParams.builder().addCommand(javac.toAbsolutePath().toString(), "-version").build();
    FakeProcess javacProc = new FakeProcess(0, "", "");
    final FakeProcessExecutor executor = new FakeProcessExecutor(ImmutableMap.of(javacExe, javacProc));
    ExternalJavac compiler = new ExternalJavac(Either.ofLeft(javac)) {

        @Override
        ProcessExecutor createProcessExecutor() {
            return executor;
        }
    };
    RuleKeyObjectSink sink = createMock(RuleKeyObjectSink.class);
    expect(sink.setReflectively("javac", javac.toString())).andReturn(sink);
    replay(sink);
    compiler.appendToRuleKey(sink);
}
Also used : Path(java.nio.file.Path) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProcess(com.facebook.buck.util.FakeProcess) RuleKeyObjectSink(com.facebook.buck.rules.RuleKeyObjectSink) Test(org.junit.Test)

Example 20 with FakeProcess

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

the class ExternalJavacTest method externalJavacWillHashTheJavacVersionIfPresent.

@Test
public void externalJavacWillHashTheJavacVersionIfPresent() throws IOException {
    Path javac = Files.createTempFile("fake", "javac");
    javac.toFile().deleteOnExit();
    String reportedJavacVersion = "mozzarella";
    JavacVersion javacVersion = JavacVersion.of(reportedJavacVersion);
    ProcessExecutorParams javacExe = ProcessExecutorParams.builder().addCommand(javac.toAbsolutePath().toString(), "-version").build();
    FakeProcess javacProc = new FakeProcess(0, "", reportedJavacVersion);
    final FakeProcessExecutor executor = new FakeProcessExecutor(ImmutableMap.of(javacExe, javacProc));
    ExternalJavac compiler = new ExternalJavac(Either.ofLeft(javac)) {

        @Override
        ProcessExecutor createProcessExecutor() {
            return executor;
        }
    };
    RuleKeyObjectSink sink = createMock(RuleKeyObjectSink.class);
    expect(sink.setReflectively("javac.version", javacVersion.toString())).andReturn(sink);
    replay(sink);
    compiler.appendToRuleKey(sink);
}
Also used : Path(java.nio.file.Path) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProcess(com.facebook.buck.util.FakeProcess) RuleKeyObjectSink(com.facebook.buck.rules.RuleKeyObjectSink) Test(org.junit.Test)

Aggregations

FakeProcess (com.facebook.buck.util.FakeProcess)46 Test (org.junit.Test)41 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)35 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)30 ExecutionContext (com.facebook.buck.step.ExecutionContext)21 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)21 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)14 TestConsole (com.facebook.buck.testutil.TestConsole)14 ImmutableList (com.google.common.collect.ImmutableList)9 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)9 BuckEventBusFactory (com.facebook.buck.event.BuckEventBusFactory)4 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)4 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)4 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)4 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)4 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)4 StepExecutionResult (com.facebook.buck.step.StepExecutionResult)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Paths (java.nio.file.Paths)4 InputStream (java.io.InputStream)3