Search in sources :

Example 21 with FakeProcess

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

the class JavacStepTest method successfulCompileDoesNotSendStdoutAndStderrToConsole.

@Test
public void successfulCompileDoesNotSendStdoutAndStderrToConsole() 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(0, "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);
    // Note that we don't include stderr in the step result on success.
    assertThat(result, equalTo(StepExecutionResult.SUCCESS));
    assertThat(listener.getLogMessages(), empty());
}
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)

Example 22 with FakeProcess

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

the class JavacStepTest method missingBootclasspathDirFailsWithError.

@Test
public void missingBootclasspathDirFailsWithError() 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").setBootclasspath("/no-such-dir").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);
    assertThat(result, equalTo(StepExecutionResult.ERROR));
    assertThat(listener.getLogMessages(), equalTo(ImmutableList.of("Invalid Java compiler options: Bootstrap classpath /no-such-dir " + "contains no valid entries")));
}
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)

Example 23 with FakeProcess

use of com.facebook.buck.util.FakeProcess 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 24 with FakeProcess

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

the class KnownBuildRuleTypesTest method addXcodeSelectProcess.

private static void addXcodeSelectProcess(Map<ProcessExecutorParams, FakeProcess> processMap, String xcodeSelectPath) {
    FakeProcess xcodeSelectOutputProcess = new FakeProcess(0, xcodeSelectPath, "");
    ProcessExecutorParams xcodeSelectParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("xcode-select", "--print-path")).build();
    processMap.put(xcodeSelectParams, xcodeSelectOutputProcess);
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) FakeProcess(com.facebook.buck.util.FakeProcess)

Example 25 with FakeProcess

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

the class ShellStepTest method testStdErrNotPrintedOnSuccessIfNotShouldPrintStdErr.

@Test
public void testStdErrNotPrintedOnSuccessIfNotShouldPrintStdErr() throws Exception {
    ShellStep command = createCommand(/*shouldPrintStdErr*/
    false, /*shouldPrintStdOut*/
    false);
    ProcessExecutorParams params = createParams();
    FakeProcess process = new FakeProcess(EXIT_SUCCESS, OUTPUT_MSG, ERROR_MSG);
    TestConsole console = new TestConsole(Verbosity.STANDARD_INFORMATION);
    ExecutionContext context = createContext(ImmutableMap.of(params, process), console);
    command.launchAndInteractWithProcess(context, params);
    assertEquals("", console.getTextWrittenToStdErr());
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcess(com.facebook.buck.util.FakeProcess) TestConsole(com.facebook.buck.testutil.TestConsole) 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