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))));
}
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))));
}
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)));
}
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)));
}
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")));
}
Aggregations