Search in sources :

Example 41 with FakeProcessExecutor

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

the class JavacStepTest method existingBootclasspathDirSucceeds.

@Test
public void existingBootclasspathDirSucceeds() 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("/this-totally-exists").build();
    ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> true, 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);
    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 42 with FakeProcessExecutor

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

the class AppleConfigTest method getSpecifiedAppleDeveloperDirectorySupplierForTests.

@Test
public void getSpecifiedAppleDeveloperDirectorySupplierForTests() {
    BuckConfig buckConfig = FakeBuckConfig.builder().setSections(ImmutableMap.of("apple", ImmutableMap.of("xcode_developer_dir", "/path/to/somewhere", "xcode_developer_dir_for_tests", "/path/to/somewhere2"))).build();
    AppleConfig config = new AppleConfig(buckConfig);
    Supplier<Optional<Path>> supplier = config.getAppleDeveloperDirectorySupplier(new FakeProcessExecutor());
    assertNotNull(supplier);
    assertEquals(Optional.of(Paths.get("/path/to/somewhere")), supplier.get());
    Supplier<Optional<Path>> supplierForTests = config.getAppleDeveloperDirectorySupplierForTests(new FakeProcessExecutor());
    assertNotNull(supplierForTests);
    assertEquals(Optional.of(Paths.get("/path/to/somewhere2")), supplierForTests.get());
}
Also used : FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) Optional(java.util.Optional) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) Test(org.junit.Test)

Example 43 with FakeProcessExecutor

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

the class ShellStepTest method testDescriptionWithPath.

@Test
public void testDescriptionWithPath() {
    ShellStep command = createCommand(ImmutableMap.of(), ARGS, PATH);
    ExecutionContext context = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor()).build();
    String template = Platform.detect() == Platform.WINDOWS ? "(cd %s && bash -c \"echo $V1 $V2\")" : "(cd %s && 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)

Example 44 with FakeProcessExecutor

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

the class ShellStepTest method testDescriptionWithEnvironment.

@Test
public void testDescriptionWithEnvironment() {
    Path workingDirectory = Paths.get(".").toAbsolutePath().normalize();
    ShellStep command = createCommand(ENV, ARGS, null);
    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(workingDirectory)), command.getDescription(context));
}
Also used : Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) Test(org.junit.Test)

Example 45 with FakeProcessExecutor

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

the class ShellStepTest method testDescription.

@Test
public void testDescription() {
    Path workingDirectory = Paths.get(".").toAbsolutePath().normalize();
    ShellStep command = createCommand(ImmutableMap.of(), ARGS, null);
    ExecutionContext context = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor()).build();
    String expectedDescription = Platform.detect() == Platform.WINDOWS ? "(cd %s && bash -c \"echo $V1 $V2\")" : "(cd %s && bash -c 'echo $V1 $V2')";
    assertEquals(String.format(expectedDescription, Escaper.escapeAsBashString(workingDirectory)), command.getDescription(context));
}
Also used : Path(java.nio.file.Path) 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