Search in sources :

Example 36 with FakeProcessExecutor

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

the class AppleSimulatorControllerTest method launchingInstalledBundleWithArgsPassesArgsThroughToSimCtl.

@Test
public void launchingInstalledBundleWithArgsPassesArgsThroughToSimCtl() throws IOException, InterruptedException {
    FakeProcess fakeSimctlLaunchProcess = new FakeProcess(0, "com.facebook.MyNeatApp: 42", "");
    ProcessExecutorParams fakeSimctlLaunchParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("path/to/simctl", "launch", "70200ED8-EEF1-4BDB-BCCF-3595B137D67D", "com.facebook.MyNeatApp", "arg1", "arg2")).build();
    FakeProcessExecutor fakeProcessExecutor = new FakeProcessExecutor(ImmutableMap.of(fakeSimctlLaunchParams, fakeSimctlLaunchProcess));
    AppleSimulatorController appleSimulatorController = new AppleSimulatorController(fakeProcessExecutor, SIMCTL_PATH, IOS_SIMULATOR_PATH);
    Optional<Long> launchedPID = appleSimulatorController.launchInstalledBundleInSimulator("70200ED8-EEF1-4BDB-BCCF-3595B137D67D", "com.facebook.MyNeatApp", AppleSimulatorController.LaunchBehavior.DO_NOT_WAIT_FOR_DEBUGGER, ImmutableList.of("arg1", "arg2"));
    assertThat(launchedPID, is(equalTo(Optional.of(42L))));
}
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 37 with FakeProcessExecutor

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

the class AppleSimulatorControllerTest method launchingInstalledBundleWaitingForDebuggerWorks.

@Test
public void launchingInstalledBundleWaitingForDebuggerWorks() throws IOException, InterruptedException {
    FakeProcess fakeSimctlLaunchProcess = new FakeProcess(0, "com.facebook.MyNeatApp: 42", "");
    ProcessExecutorParams fakeSimctlLaunchParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("path/to/simctl", "launch", "-w", "70200ED8-EEF1-4BDB-BCCF-3595B137D67D", "com.facebook.MyNeatApp")).build();
    FakeProcessExecutor fakeProcessExecutor = new FakeProcessExecutor(ImmutableMap.of(fakeSimctlLaunchParams, fakeSimctlLaunchProcess));
    AppleSimulatorController appleSimulatorController = new AppleSimulatorController(fakeProcessExecutor, SIMCTL_PATH, IOS_SIMULATOR_PATH);
    Optional<Long> launchedPID = appleSimulatorController.launchInstalledBundleInSimulator("70200ED8-EEF1-4BDB-BCCF-3595B137D67D", "com.facebook.MyNeatApp", AppleSimulatorController.LaunchBehavior.WAIT_FOR_DEBUGGER, ImmutableList.of());
    assertThat(launchedPID, is(equalTo(Optional.of(42L))));
}
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 38 with FakeProcessExecutor

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

the class AppleSimulatorControllerTest method startingSimulatorWorksWhenSimulatorAlreadyBooted.

@Test
public void startingSimulatorWorksWhenSimulatorAlreadyBooted() 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) (Shutdown)\n" + "    iPhone 5s (70200ED8-EEF1-4BDB-BCCF-3595B137D67D) (Booted)\n", "")));
    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 39 with FakeProcessExecutor

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

the class AppleSimulatorDiscoveryTest method appleSimulatorsDiscoveredFromSimctlList.

@Test
public void appleSimulatorsDiscoveredFromSimctlList() throws IOException, InterruptedException {
    ImmutableSet<AppleSimulator> simulators;
    try (OutputStream stdin = new ByteArrayOutputStream();
        InputStream stdout = getClass().getResourceAsStream("testdata/simctl-list.txt");
        InputStream stderr = new ByteArrayInputStream(new byte[0])) {
        FakeProcess fakeXcrunSimctlList = new FakeProcess(0, stdin, stdout, stderr);
        ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("path/to/simctl", "list")).build();
        FakeProcessExecutor fakeProcessExecutor = new FakeProcessExecutor(ImmutableMap.of(processExecutorParams, fakeXcrunSimctlList));
        simulators = AppleSimulatorDiscovery.discoverAppleSimulators(fakeProcessExecutor, Paths.get("path/to/simctl"));
    }
    ImmutableSet<AppleSimulator> expected = ImmutableSet.<AppleSimulator>builder().add(AppleSimulator.builder().setName("iPhone 4s").setUdid("F7C1CC9A-945E-4258-BA84-DEEBE683798B").setSimulatorState(AppleSimulatorState.SHUTDOWN).build()).add(AppleSimulator.builder().setName("iPhone 5").setUdid("45BD7164-686C-474F-8C68-3730432BC5F2").setSimulatorState(AppleSimulatorState.SHUTDOWN).build()).add(AppleSimulator.builder().setName("iPhone 5s").setUdid("70200ED8-EEF1-4BDB-BCCF-3595B137D67D").setSimulatorState(AppleSimulatorState.BOOTED).build()).add(AppleSimulator.builder().setName("iPhone 6 Plus").setUdid("92340ACF-2C44-455F-BACD-573B133FB20E").setSimulatorState(AppleSimulatorState.SHUTDOWN).build()).add(AppleSimulator.builder().setName("iPhone 6").setUdid("A75FF972-FE12-4656-A8CC-99572879D4A3").setSimulatorState(AppleSimulatorState.SHUTDOWN).build()).add(AppleSimulator.builder().setName("iPad 2").setUdid("CC1B0BAD-BAE6-4A53-92CF-F79850654057").setSimulatorState(AppleSimulatorState.SHUTTING_DOWN).build()).add(AppleSimulator.builder().setName("iPad Retina").setUdid("137AAA25-54A1-42E8-8202-84DEADD668E1").setSimulatorState(AppleSimulatorState.SHUTDOWN).build()).add(AppleSimulator.builder().setName("iPad Air").setUdid("554B2E0F-63F3-4400-8319-5C5062CF4C95").setSimulatorState(AppleSimulatorState.SHUTDOWN).build()).add(AppleSimulator.builder().setName("Resizable iPhone").setUdid("58E3748F-F7E6-4A45-B52C-A136B59F7A42").setSimulatorState(AppleSimulatorState.CREATING).build()).add(AppleSimulator.builder().setName("Resizable iPad").setUdid("56FE1CBC-61FF-443D-8E23-19D05864C6DB").setSimulatorState(AppleSimulatorState.SHUTDOWN).build()).build();
    assertThat(simulators, is(equalTo(expected)));
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ByteArrayInputStream(java.io.ByteArrayInputStream) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FakeProcess(com.facebook.buck.util.FakeProcess) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 40 with FakeProcessExecutor

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

the class JavacStepTest method failedCompileSendsStdoutAndStderrToConsole.

@Test
public void failedCompileSendsStdoutAndStderrToConsole() throws Exception {
    FakeJavac fakeJavac = new FakeJavac();
    BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    ProjectFilesystem fakeFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    JavacOptions javacOptions = JavacOptions.builder().setSourceLevel("8.0").setTargetLevel("8.0").build();
    ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> false, file -> false, (path, glob) -> ImmutableSet.of());
    JavacStep step = new JavacStep(Paths.get("output"), NoOpClassUsageFileWriter.instance(), Optional.empty(), ImmutableSortedSet.of(), Paths.get("pathToSrcsList"), ImmutableSortedSet.of(), fakeJavac, javacOptions, BuildTargetFactory.newInstance("//foo:bar"), Optional.empty(), sourcePathResolver, ruleFinder, fakeFilesystem, classpathChecker, Optional.empty());
    FakeProcess fakeJavacProcess = new FakeProcess(1, "javac stdout\n", "javac stderr\n");
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor(Functions.constant(fakeJavacProcess), new TestConsole())).build();
    BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
    executionContext.getBuckEventBus().register(listener);
    StepExecutionResult result = step.execute(executionContext);
    // JavacStep itself writes stdout to the console on error; we expect the Build class to write
    // the stderr stream returned in the StepExecutionResult
    assertThat(result, equalTo(StepExecutionResult.of(1, Optional.of("javac stderr\n"))));
    assertThat(listener.getLogMessages(), equalTo(ImmutableList.of("javac stdout\n")));
}
Also used : BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) FakeProcess(com.facebook.buck.util.FakeProcess) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Paths(java.nio.file.Paths) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Aggregations

FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)47 Test (org.junit.Test)42 FakeProcess (com.facebook.buck.util.FakeProcess)35 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)21 ExecutionContext (com.facebook.buck.step.ExecutionContext)19 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)19 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)17 ImmutableList (com.google.common.collect.ImmutableList)9 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)9 TestConsole (com.facebook.buck.testutil.TestConsole)8 Path (java.nio.file.Path)6 BuckConfig (com.facebook.buck.cli.BuckConfig)5 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)5 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)5 BuckEventBusFactory (com.facebook.buck.event.BuckEventBusFactory)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