Add support for capturing console output to FileTest. (#4339)

One of the things that ClangRunnerTest is doing is capturing
stderr/stdout because clang prints to it directly. This adds support for
that to FileTest.

I'm renaming the current `capture_output` field to `dump_output` because
the name is ambiguous after this change, and the flag is already named
`--dump_output`. It's still not great, but at least it's more distinct.

Note ClangRunner still doesn't use the vfs; that still needs work. I'm
just moving the NoArgs test over as a trivial test of the functionality.
This commit is contained in:
Jon Ross-Perkins
2024-09-27 16:10:44 +00:00
committed by GitHub
parent bdbd1079a6
commit 73c6f67378
10 changed files with 139 additions and 50 deletions
+14 -2
View File
@@ -17,8 +17,9 @@ namespace {
class FileTestBaseTest : public FileTestBase {
public:
FileTestBaseTest(llvm::StringRef /*exe_path*/, llvm::StringRef test_name)
: FileTestBase(test_name) {}
FileTestBaseTest(llvm::StringRef /*exe_path*/, std::mutex* output_mutex,
llvm::StringRef test_name)
: FileTestBase(output_mutex, test_name) {}
auto Run(const llvm::SmallVector<llvm::StringRef>& test_args,
llvm::vfs::InMemoryFileSystem& fs, llvm::raw_pwrite_stream& stdout,
@@ -108,6 +109,16 @@ static auto TestAlternatingFiles(TestParams& params)
return {{.success = true}};
}
// Does printing and returns expected results for capture_console_output.carbon.
static auto TestCaptureConsoleOutput(TestParams& params)
-> ErrorOr<FileTestBaseTest::RunResult> {
llvm::errs() << "llvm::errs\n";
params.stderr << "params.stderr\n";
llvm::outs() << "llvm::outs\n";
params.stdout << "params.stdout\n";
return {{.success = true}};
}
// Does printing and returns expected results for example.carbon.
static auto TestExample(TestParams& params)
-> ErrorOr<FileTestBaseTest::RunResult> {
@@ -225,6 +236,7 @@ auto FileTestBaseTest::Run(const llvm::SmallVector<llvm::StringRef>& test_args,
llvm::StringSwitch<std::function<ErrorOr<RunResult>(TestParams&)>>(
filename.string())
.Case("alternating_files.carbon", &TestAlternatingFiles)
.Case("capture_console_output.carbon", &TestCaptureConsoleOutput)
.Case("example.carbon", &TestExample)
.Case("fail_example.carbon", &TestFailExample)
.Case("file_only_re_one_file.carbon", &TestFileOnlyREOneFile)