mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 10:51:06 +01:00
Add stdin to driver's streams, and refactor stream passing (#4812)
The language server needs stdin, and for tests we should be passing it around. My intent is to pass in a faux stdin to Driver for language server tests. As long as I'm adding a new parameter, I was looking at also changing the way streams are passed in to Driver for style (pointers since they're held past construction lifetime). Since these are all stored in DriverEnv, I thought it might be a net improvement to use the struct directly, getting more explicit parameter names and also removing the need for `SetFuzzing`. I'm trying here to avoid functional changes, but there are a couple additional fixes like removing an obsolete `find_insensitive` and refactoring how `ValidateOptions` handles errors (because it reduces the number of spots that operate on error_stream).
This commit is contained in:
@@ -56,8 +56,9 @@ auto FormatSubcommand::Run(DriverEnv& driver_env) -> DriverResult {
|
||||
DriverResult result = {.success = true};
|
||||
if (options_.input_filenames.size() > 1 &&
|
||||
!options_.output_filename.empty()) {
|
||||
driver_env.error_stream << "error: cannot format multiple input files when "
|
||||
"--output is set\n";
|
||||
*driver_env.error_stream
|
||||
<< "error: cannot format multiple input files when "
|
||||
"--output is set\n";
|
||||
result.success = false;
|
||||
return result;
|
||||
}
|
||||
@@ -67,7 +68,7 @@ auto FormatSubcommand::Run(DriverEnv& driver_env) -> DriverResult {
|
||||
result.per_file_success.back().second = false;
|
||||
};
|
||||
|
||||
StreamDiagnosticConsumer consumer(driver_env.error_stream,
|
||||
StreamDiagnosticConsumer consumer(*driver_env.error_stream,
|
||||
/*include_diagnostic_kind=*/false);
|
||||
for (auto& f : options_.input_filenames) {
|
||||
// Push a result, which we'll update on failure.
|
||||
@@ -89,11 +90,11 @@ auto FormatSubcommand::Run(DriverEnv& driver_env) -> DriverResult {
|
||||
// TODO: Figure out a multi-file output setup that supports good
|
||||
// multi-file testing.
|
||||
// TODO: Use --output values (and default to overwrite).
|
||||
driver_env.output_stream << buffer.TakeStr();
|
||||
*driver_env.output_stream << buffer.TakeStr();
|
||||
} else {
|
||||
buffer.clear();
|
||||
mark_per_file_error();
|
||||
driver_env.output_stream << source->text();
|
||||
*driver_env.output_stream << source->text();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user