Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using --dump_output with file_test, dump stderr directly. #3901

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions testing/file_test/file_test_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ auto FileTestBase::Autoupdate() -> ErrorOr<bool> {

auto FileTestBase::DumpOutput() -> ErrorOr<Success> {
TestContext context;
context.capture_output = false;
std::string banner(79, '=');
banner.append("\n");
llvm::errs() << banner << "= " << test_name_ << "\n";
Expand All @@ -227,9 +228,7 @@ auto FileTestBase::DumpOutput() -> ErrorOr<Success> {
return ErrorBuilder() << "Error updating " << test_name_ << ": "
<< run_result.error();
}
llvm::errs() << banner << "= stderr\n"
<< banner << context.stderr << banner << "= stdout\n"
<< banner << context.stdout << banner << "= Exit with success: "
llvm::errs() << banner << context.stdout << banner << "= Exit with success: "
<< (context.run_result.success ? "true" : "false") << "\n"
<< banner;
return Success();
Expand Down Expand Up @@ -287,11 +286,16 @@ auto FileTestBase::ProcessTestFileAndRun(TestContext& context)
llvm::PrettyStackTraceProgram stack_trace_entry(
test_argv_for_stack_trace.size() - 1, test_argv_for_stack_trace.data());

// Capture trace streaming, but only when in debug mode.
// Prepare string streams to capture output. In order to address casting
// constraints, we split calls to Run as a ternary based on whether we want to
// capture output.
llvm::raw_svector_ostream stdout(context.stdout);
llvm::raw_svector_ostream stderr(context.stderr);
CARBON_ASSIGN_OR_RETURN(context.run_result,
Run(test_args_ref, fs, stdout, stderr));
CARBON_ASSIGN_OR_RETURN(
context.run_result,
context.capture_output
? Run(test_args_ref, fs, stdout, stderr)
: Run(test_args_ref, fs, llvm::outs(), llvm::errs()));
return Success();
}

Expand Down
4 changes: 4 additions & 0 deletions testing/file_test/file_test_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ class FileTestBase : public testing::Test {
// Whether checks are a subset, generated from SET-CHECK-SUBSET.
bool check_subset = false;

// Output is typically captured for tests and autoupdate, but not when
// dumping to console.
bool capture_output = true;

// stdout and stderr based on CHECK lines in the file.
llvm::SmallVector<testing::Matcher<std::string>> expected_stdout;
llvm::SmallVector<testing::Matcher<std::string>> expected_stderr;
Expand Down
Loading