use of com.facebook.buck.util.CapturingPrintStream in project buck by facebook.
the class BuildCommandTest method testGenerateBuildReportForConsole.
@Test
public void testGenerateBuildReportForConsole() {
String expectedReport = "[1m[42m[30mOK [0m //fake:rule1 " + "BUILT_LOCALLY " + MorePaths.pathWithPlatformSeparators("buck-out/gen/fake/rule1.txt") + "\n" + "[31mFAIL[0m //fake:rule2\n" + "[1m[42m[30mOK [0m //fake:rule3 FETCHED_FROM_CACHE\n" + "[31mFAIL[0m //fake:rule4\n";
String observedReport = new BuildReport(buildExecutionResult, resolver).generateForConsole(new Console(Verbosity.STANDARD_INFORMATION, new CapturingPrintStream(), new CapturingPrintStream(), Ansi.forceTty()));
assertEquals(expectedReport, observedReport);
}
use of com.facebook.buck.util.CapturingPrintStream in project buck by facebook.
the class DaemonIntegrationTest method whenClientDisconnectionDetectedThenTestIsInterrupted.
/**
* This verifies that a client disconnection will be detected by a Nailgun
* NGInputStream reading from an empty heartbeat stream and that the generated
* InterruptedException will interrupt command execution causing it to fail.
*/
@Test
public void whenClientDisconnectionDetectedThenTestIsInterrupted() throws InterruptedException, IOException {
// Sub process interruption not supported on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
// Stream timeout > test timeout.
final long timeoutMillis = 2000;
// Disconnect before test timeout.
final long disconnectMillis = 100;
final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "exclusive_execution", tmp);
workspace.setUp();
// Start with an input stream that sends heartbeats at a regular rate.
final DelegatingInputStream inputStream = new DelegatingInputStream(TestContext.createHeartBeatStream(timeoutMillis / 10));
// Build an NGContext connected to an NGInputStream reading from stream that will timeout.
try (TestContext context = new TestContext(ImmutableMap.copyOf(System.getenv()), inputStream, timeoutMillis)) {
ProcessResult result = workspace.runBuckdCommand(context, new CapturingPrintStream() {
@Override
public void println(String x) {
if (x.contains("TESTING //:test")) {
// When tests start running, make the heartbeat stream simulate a disconnection.
inputStream.setDelegate(TestContext.createDisconnectionStream(disconnectMillis));
}
super.println(x);
}
}, "test", "//:test");
result.assertFailure();
assertThat(result.getStderr(), containsString("InterruptedException"));
}
}
use of com.facebook.buck.util.CapturingPrintStream in project buck by facebook.
the class StepFailedException method createForFailingStepWithException.
static StepFailedException createForFailingStepWithException(Step step, Throwable throwable, Optional<BuildTarget> buildTarget) {
CapturingPrintStream printStream = new CapturingPrintStream();
throwable.printStackTrace(printStream);
String stackTrace = printStream.getContentsAsString(Charsets.UTF_8);
String message;
if (buildTarget.isPresent()) {
message = String.format("%s failed on step %s with an exception:\n%s\n%s", buildTarget.get().getFullyQualifiedName(), step.getShortName(), throwable.getMessage(), stackTrace);
} else {
message = String.format("Failed on step %s with an exception:\n%s\n%s", step.getShortName(), throwable.getMessage(), stackTrace);
}
return new StepFailedException(message, step, 1);
}
use of com.facebook.buck.util.CapturingPrintStream in project buck by facebook.
the class JavacStep method tryBuildWithFirstOrderDeps.
private StepExecutionResult tryBuildWithFirstOrderDeps(ExecutionContext context, ProjectFilesystem filesystem) throws InterruptedException, IOException {
try {
javacOptions.validateOptions(classpathChecker::validateClasspath);
} catch (IOException e) {
context.postEvent(ConsoleEvent.severe("Invalid Java compiler options: %s", e.getMessage()));
return StepExecutionResult.ERROR;
}
Verbosity verbosity = context.getVerbosity().isSilent() ? Verbosity.STANDARD_INFORMATION : context.getVerbosity();
try (CapturingPrintStream stdout = new CapturingPrintStream();
CapturingPrintStream stderr = new CapturingPrintStream();
ExecutionContext firstOrderContext = context.createSubContext(stdout, stderr, Optional.of(verbosity))) {
Javac javac = getJavac();
JavacExecutionContext javacExecutionContext = JavacExecutionContext.of(new JavacEventSinkToBuckEventBusBridge(firstOrderContext.getBuckEventBus()), stderr, firstOrderContext.getClassLoaderCache(), firstOrderContext.getObjectMapper(), verbosity, firstOrderContext.getCellPathResolver(), firstOrderContext.getJavaPackageFinder(), filesystem, usedClassesFileWriter, firstOrderContext.getEnvironment(), firstOrderContext.getProcessExecutor(), getAbsolutePathsForJavacInputs(javac), directToJarOutputSettings);
return performBuild(context, stdout, stderr, javac, javacExecutionContext);
}
}
use of com.facebook.buck.util.CapturingPrintStream in project buck by facebook.
the class ProjectWorkspace method runBuckCommandWithEnvironmentOverridesAndContext.
public ProcessResult runBuckCommandWithEnvironmentOverridesAndContext(Path repoRoot, Optional<NGContext> context, ImmutableMap<String, String> environmentOverrides, CapturingPrintStream stderr, String... args) throws IOException {
assertTrue("setUp() must be run before this method is invoked", isSetUp);
CapturingPrintStream stdout = new CapturingPrintStream();
InputStream stdin = new ByteArrayInputStream("".getBytes());
// Construct a limited view of the parent environment for the child.
// TODO(#5754812): we should eventually get tests working without requiring these be set.
ImmutableList<String> inheritedEnvVars = ImmutableList.of("ANDROID_HOME", "ANDROID_NDK", "ANDROID_NDK_REPOSITORY", "ANDROID_SDK", // scripts provided by the groovy distribution in order to remove these two.
"GROOVY_HOME", "JAVA_HOME", "NDK_HOME", "PATH", "PATHEXT", // Needed by ndk-build on Windows
"OS", "ProgramW6432", "ProgramFiles(x86)", // The haskell integration tests call into GHC, which needs HOME to be set.
"HOME", // TODO(#6586154): set TMP variable for ShellSteps
"TMP");
Map<String, String> envBuilder = new HashMap<>();
for (String variable : inheritedEnvVars) {
String value = System.getenv(variable);
if (value != null) {
envBuilder.put(variable, value);
}
}
envBuilder.putAll(environmentOverrides);
ImmutableMap<String, String> sanizitedEnv = ImmutableMap.copyOf(envBuilder);
Main main = new Main(stdout, stderr, stdin);
int exitCode;
try {
exitCode = main.runMainWithExitCode(new BuildId(), repoRoot, context, sanizitedEnv, CommandMode.TEST, WatchmanWatcher.FreshInstanceAction.NONE, System.nanoTime(), args);
} catch (InterruptedException e) {
e.printStackTrace(stderr);
exitCode = Main.FAIL_EXIT_CODE;
Thread.currentThread().interrupt();
}
return new ProcessResult(exitCode, stdout.getContentsAsString(Charsets.UTF_8), stderr.getContentsAsString(Charsets.UTF_8));
}
Aggregations