Search in sources :

Example 16 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class InstallCommandIntegrationTest method appleBundleInstallsAndRunsInIphoneSimulatorWithDwarfDebugging.

@Test
public void appleBundleInstallsAndRunsInIphoneSimulatorWithDwarfDebugging() throws IOException, InterruptedException {
    assumeThat(Platform.detect(), is(Platform.MACOS));
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "apple_app_bundle", tmp);
    workspace.setUp();
    workspace.enableDirCache();
    // build locally
    ProcessResult result = workspace.runBuckCommand("install", "--config", "apple.default_debug_info_format_for_binaries=DWARF", "--config", "apple.default_debug_info_format_for_libraries=DWARF", "--config", "apple.default_debug_info_format_for_tests=DWARF", "-r", "//:DemoApp");
    assumeFalse(result.getStderr().contains("no appropriate simulator found"));
    result.assertSuccess();
    // find port to connect lldb to
    // "lldb -p 12345"
    Pattern p = Pattern.compile("lldb -p \\d{1,6}");
    Matcher matcher = p.matcher(result.getStderr());
    assertThat(matcher.find(), equalTo(true));
    String[] lldbCommand = matcher.group().split(" ");
    ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
    // run lldb session
    ProcessExecutor.Result lldbResult = executor.launchAndExecute(ProcessExecutorParams.builder().addCommand(lldbCommand).build(), ImmutableSet.of(), Optional.of("b application:didFinishLaunchingWithOptions:\nb\nexit\nY\n"), Optional.empty(), Optional.empty());
    assertThat(lldbResult.getExitCode(), equalTo(0));
    // check that lldb resolved breakpoint locations
    String lldbOutput = lldbResult.getStdout().orElse("");
    assertThat(lldbOutput, containsString("Current breakpoints:"));
    assertThat(lldbOutput, containsString("name = 'application:didFinishLaunchingWithOptions:', " + "locations = 1, resolved = 1, hit count = 0"));
    // clean buck out
    workspace.runBuckCommand("clean");
    // build again - get everything from cache now
    result = workspace.runBuckCommand("install", "--config", "apple.default_debug_info_format_for_binaries=DWARF", "--config", "apple.default_debug_info_format_for_libraries=DWARF", "--config", "apple.default_debug_info_format_for_tests=DWARF", "-r", "//:DemoApp");
    result.assertSuccess();
    matcher = p.matcher(result.getStderr());
    assertThat(matcher.find(), equalTo(true));
    String[] lldbCommand2 = matcher.group().split(" ");
    // run lldb session again - now on top of files fetched from cache
    lldbResult = executor.launchAndExecute(ProcessExecutorParams.builder().addCommand(lldbCommand2).build(), ImmutableSet.of(), Optional.of("b application:didFinishLaunchingWithOptions:\nb\nexit\nY\n"), Optional.empty(), Optional.empty());
    assertThat(lldbResult.getExitCode(), equalTo(0));
    // check that lldb resolved breakpoint locations with files from cache
    lldbOutput = lldbResult.getStdout().orElse("");
    assertThat(lldbOutput, containsString("Current breakpoints:"));
    assertThat(lldbOutput, containsString("name = 'application:didFinishLaunchingWithOptions:', " + "locations = 1, resolved = 1, hit count = 0"));
}
Also used : Pattern(java.util.regex.Pattern) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) Matcher(java.util.regex.Matcher) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Matchers.containsString(org.hamcrest.Matchers.containsString) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 17 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class TargetsCommandTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException {
    console = new TestConsole();
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "target_command", tmp);
    workspace.setUp();
    filesystem = new ProjectFilesystem(workspace.getDestPath().toRealPath().normalize());
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
    AndroidDirectoryResolver androidDirectoryResolver = new FakeAndroidDirectoryResolver();
    ArtifactCache artifactCache = new NoopArtifactCache();
    BuckEventBus eventBus = BuckEventBusFactory.newInstance();
    objectMapper = ObjectMappers.newDefaultInstance();
    targetsCommand = new TargetsCommand();
    params = CommandRunnerParamsForTesting.createCommandRunnerParamsForTesting(console, cell, androidDirectoryResolver, artifactCache, eventBus, FakeBuckConfig.builder().build(), Platform.detect(), ImmutableMap.copyOf(System.getenv()), new FakeJavaPackageFinder(), objectMapper, Optional.empty());
    executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) AndroidDirectoryResolver(com.facebook.buck.android.AndroidDirectoryResolver) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) FakeJavaPackageFinder(com.facebook.buck.jvm.java.FakeJavaPackageFinder) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) Before(org.junit.Before)

Example 18 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class ServerStatusCommandTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException {
    console = new TestConsole();
    webServer = createStrictMock(WebServer.class);
    params = CommandRunnerParamsForTesting.builder().setWebserver(Optional.of(webServer)).setConsole(console).build();
}
Also used : WebServer(com.facebook.buck.httpserver.WebServer) TestConsole(com.facebook.buck.testutil.TestConsole) Before(org.junit.Before)

Example 19 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class CxxCompileStepIntegrationTest method createsAnArgfile.

@Test
public void createsAnArgfile() throws Exception {
    ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
    CxxPlatform platform = CxxPlatformUtils.build(new CxxBuckConfig(FakeBuckConfig.builder().build()));
    // Build up the paths to various files the archive step will use.
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    Compiler compiler = platform.getCc().resolve(resolver);
    ImmutableList<String> compilerCommandPrefix = compiler.getCommandPrefix(pathResolver);
    Path output = filesystem.resolve(Paths.get("output.o"));
    Path depFile = filesystem.resolve(Paths.get("output.dep"));
    Path relativeInput = Paths.get("input.c");
    Path input = filesystem.resolve(relativeInput);
    filesystem.writeContentsToPath("int main() {}", relativeInput);
    Path scratchDir = filesystem.getPath("scratchDir");
    filesystem.mkdirs(scratchDir);
    ImmutableList.Builder<String> preprocessorArguments = ImmutableList.builder();
    ImmutableList.Builder<String> compilerArguments = ImmutableList.builder();
    compilerArguments.add("-g");
    // Build an archive step.
    CxxPreprocessAndCompileStep step = new CxxPreprocessAndCompileStep(filesystem, CxxPreprocessAndCompileStep.Operation.PREPROCESS_AND_COMPILE, output, depFile, relativeInput, CxxSource.Type.C, Optional.of(new CxxPreprocessAndCompileStep.ToolCommand(compilerCommandPrefix, preprocessorArguments.build(), ImmutableMap.of(), Optional.empty())), Optional.of(new CxxPreprocessAndCompileStep.ToolCommand(compilerCommandPrefix, compilerArguments.build(), ImmutableMap.of(), Optional.empty())), HeaderPathNormalizer.empty(pathResolver), CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, scratchDir, true, compiler);
    // Execute the archive step and verify it ran successfully.
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    TestConsole console = (TestConsole) executionContext.getConsole();
    int exitCode = step.execute(executionContext).getExitCode();
    assertEquals("compile step failed: " + console.getTextWrittenToStdErr(), 0, exitCode);
    Path argfile = filesystem.resolve(scratchDir.resolve("ppandcompile.argsfile"));
    assertThat(filesystem, pathExists(argfile));
    assertThat(Files.readAllLines(argfile, StandardCharsets.UTF_8), hasItem(equalTo("-g")));
    // Cleanup.
    Files.delete(input);
    Files.deleteIfExists(output);
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 20 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class ArchiveStepIntegrationTest method inputDirs.

@Test
public void inputDirs() throws IOException, InterruptedException {
    assumeTrue(Platform.detect() == Platform.MACOS || Platform.detect() == Platform.LINUX);
    ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
    CxxPlatform platform = CxxPlatformUtils.build(new CxxBuckConfig(FakeBuckConfig.builder().build()));
    // Build up the paths to various files the archive step will use.
    SourcePathResolver sourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    Archiver archiver = platform.getAr();
    Path output = filesystem.getPath("output.a");
    Path input = filesystem.getPath("foo/blah.dat");
    filesystem.mkdirs(input.getParent());
    filesystem.writeContentsToPath("blah", input);
    // Build an archive step.
    ArchiveStep archiveStep = new ArchiveStep(filesystem, archiver.getEnvironment(sourcePathResolver), archiver.getCommandPrefix(sourcePathResolver), ImmutableList.of(), getArchiveOptions(false), output, ImmutableList.of(input.getParent()), archiver);
    // Execute the archive step and verify it ran successfully.
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    TestConsole console = (TestConsole) executionContext.getConsole();
    int exitCode = archiveStep.execute(executionContext).getExitCode();
    assertEquals("archive step failed: " + console.getTextWrittenToStdErr(), 0, exitCode);
    // zero'd out.
    try (ArArchiveInputStream stream = new ArArchiveInputStream(new FileInputStream(filesystem.resolve(output).toFile()))) {
        ArArchiveEntry entry = stream.getNextArEntry();
        assertThat(entry.getName(), Matchers.equalTo("blah.dat"));
    }
}
Also used : Path(java.nio.file.Path) ArArchiveEntry(org.apache.commons.compress.archivers.ar.ArArchiveEntry) ArArchiveInputStream(org.apache.commons.compress.archivers.ar.ArArchiveInputStream) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FileInputStream(java.io.FileInputStream) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Aggregations

TestConsole (com.facebook.buck.testutil.TestConsole)100 Test (org.junit.Test)74 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)27 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)27 ExecutionContext (com.facebook.buck.step.ExecutionContext)25 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)25 Path (java.nio.file.Path)21 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)16 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)16 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)16 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)16 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)16 BuckEventBus (com.facebook.buck.event.BuckEventBus)15 FakeProcess (com.facebook.buck.util.FakeProcess)14 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)13 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)12 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)11 Clock (com.facebook.buck.timing.Clock)10 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)9 BuildTarget (com.facebook.buck.model.BuildTarget)8