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"));
}
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());
}
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();
}
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);
}
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"));
}
}
Aggregations