Search in sources :

Example 26 with FakeProcessExecutor

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)));
}
Also used : FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProcess(com.facebook.buck.util.FakeProcess) TestConsole(com.facebook.buck.testutil.TestConsole) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 27 with FakeProcessExecutor

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());
}
Also used : FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor)

Example 28 with FakeProcessExecutor

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;
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) Subscribe(com.google.common.eventbus.Subscribe) IOException(java.io.IOException)

Example 29 with FakeProcessExecutor

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));
}
Also used : Path(java.nio.file.Path) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) IOException(java.io.IOException) Test(org.junit.Test)

Example 30 with FakeProcessExecutor

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));
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) 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