Add support for testing with stdin (#4819)

In order to write language-server tests, we need some way to pass stdin
input. This adds support for a split "// --- STDIN" which will be
provided as a temp file for testing.

Note this does more stdin -> input_stream style renaming, this is just
bugging me more since I know shadowing works but it can be subtle to
read, particularly since I'm now making direct use of stdin in a handful
of spots.
This commit is contained in:
Jon Ross-Perkins
2025-01-21 22:04:13 +00:00
committed by GitHub
parent 667a010ae6
commit e393c769af
9 changed files with 225 additions and 136 deletions
+7 -6
View File
@@ -35,7 +35,8 @@ class ToolchainFileTest : public FileTestBase {
auto Run(const llvm::SmallVector<llvm::StringRef>& test_args,
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>& fs,
llvm::raw_pwrite_stream& stdout, llvm::raw_pwrite_stream& stderr)
FILE* input_stream, llvm::raw_pwrite_stream& output_stream,
llvm::raw_pwrite_stream& error_stream)
-> ErrorOr<RunResult> override {
CARBON_ASSIGN_OR_RETURN(auto prelude, installation_.ReadPreludeManifest());
if (!is_no_prelude()) {
@@ -46,16 +47,16 @@ class ToolchainFileTest : public FileTestBase {
Driver driver({.fs = fs,
.installation = &installation_,
.input_stream = nullptr,
.output_stream = &stdout,
.error_stream = &stderr});
.input_stream = input_stream,
.output_stream = &output_stream,
.error_stream = &error_stream});
auto driver_result = driver.RunCommand(test_args);
// If any diagnostics have been produced, add a trailing newline to make the
// last diagnostic match intermediate diagnostics (that have a newline
// separator between them). This reduces churn when adding new diagnostics
// to test cases.
if (stderr.tell() > 0) {
stderr << '\n';
if (error_stream.tell() > 0) {
error_stream << '\n';
}
RunResult result{