mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 12:51:04 +01:00
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:
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user