use of com.facebook.buck.util.FakeProcessExecutor in project buck by facebook.
the class PythonBuckConfigTest method testDefaultPythonLibrary.
@Test
public void testDefaultPythonLibrary() throws InterruptedException {
BuildTarget library = BuildTargetFactory.newInstance("//:library");
PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("python", ImmutableMap.of("library", library.toString()))).build(), new AlwaysFoundExecutableFinder());
assertThat(config.getDefaultPythonPlatform(new FakeProcessExecutor(Functions.constant(new FakeProcess(0, "CPython 2 7", "")), new TestConsole())).getCxxLibrary(), Matchers.equalTo(Optional.of(library)));
}
use of com.facebook.buck.util.FakeProcessExecutor in project buck by facebook.
the class KnownBuildRuleTypesTestUtil method getDefaultKnownBuildRuleTypes.
public static KnownBuildRuleTypes getDefaultKnownBuildRuleTypes(ProjectFilesystem filesystem, ImmutableMap<String, String> environment) throws InterruptedException, IOException {
BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).build();
List<String> paths = getPaths(environment);
return KnownBuildRuleTypes.createInstance(config, filesystem, new FakeProcessExecutor(ImmutableMap.<ProcessExecutorParams, FakeProcess>builder().put(XCODE_SELECT_PARAMS, XCODE_SELECT_PROCESS).putAll(getPythonProcessMap(paths)).build()), new FakeAndroidDirectoryResolver());
}
use of com.facebook.buck.util.FakeProcessExecutor in project buck by facebook.
the class ShellStepTest method createContext.
private static ExecutionContext createContext(ImmutableMap<ProcessExecutorParams, FakeProcess> processes, final Console console) throws IOException {
ExecutionContext context = TestExecutionContext.newBuilder().setConsole(console).setProcessExecutor(new FakeProcessExecutor(processes, console)).build();
context.getBuckEventBus().register(new Object() {
@Subscribe
public void logEvent(ConsoleEvent event) throws IOException {
if (event.getLevel().equals(Level.WARNING)) {
console.getStdErr().write(event.getMessage().getBytes(Charsets.UTF_8));
}
}
});
return context;
}
use of com.facebook.buck.util.FakeProcessExecutor in project buck by facebook.
the class WorkerProcessTest method testSubmitAndWaitForJob.
@Test
public void testSubmitAndWaitForJob() throws IOException {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
Path tmpPath = Files.createTempDirectory("tmp").toAbsolutePath().normalize();
Path argsPath = Paths.get(tmpPath.toString(), "0.args");
Path stdoutPath = Paths.get(tmpPath.toString(), "0.out");
Path stderrPath = Paths.get(tmpPath.toString(), "0.err");
String jobArgs = "my job args";
int exitCode = 0;
Optional<String> stdout = Optional.of("my stdout");
Optional<String> stderr = Optional.of("my stderr");
WorkerProcess process = new WorkerProcess(new FakeProcessExecutor(), createDummyParams(), filesystem, tmpPath);
process.setProtocol(new FakeWorkerProcessProtocol() {
@Override
public int receiveCommandResponse(int messageID) throws IOException {
// simulate the external tool and write the stdout and stderr files
filesystem.writeContentsToPath(stdout.get(), stdoutPath);
filesystem.writeContentsToPath(stderr.get(), stderrPath);
return super.receiveCommandResponse(messageID);
}
});
WorkerJobResult expectedResult = WorkerJobResult.of(exitCode, stdout, stderr);
assertThat(process.submitAndWaitForJob(jobArgs), Matchers.equalTo(expectedResult));
assertThat(filesystem.readFileIfItExists(argsPath).get(), Matchers.equalTo(jobArgs));
}
use of com.facebook.buck.util.FakeProcessExecutor in project buck by facebook.
the class ShellStepTest method testDescriptionWithEnvironmentAndPath.
@Test
public void testDescriptionWithEnvironmentAndPath() {
ShellStep command = createCommand(ENV, ARGS, PATH);
ExecutionContext context = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor()).build();
String template = Platform.detect() == Platform.WINDOWS ? "(cd %s && V1=\"two words\" V2=$foo'bar' bash -c \"echo $V1 $V2\")" : "(cd %s && V1='two words' V2='$foo'\\''bar'\\''' bash -c 'echo $V1 $V2')";
assertEquals(String.format(template, Escaper.escapeAsBashString(PATH)), command.getDescription(context));
}
Aggregations