Switch tests to use the rendered form of diagnostics (#8070)

Historically, we disabled the rendered form in tests outside of
`toolchain/diagnostics`. The idea was to keep tests shorter and avoid
very long chains of autoupdate before stabilizing due to all the line
numbers and other artifacts in the rendered form.

This PR adds `--diagnostic-line-numbers=[all|first]` and defaults to
`first` in tests. This keeps the rendered form so that we can easily
code review that form and the visual cues it does or doesn't provide.
But it removes all but the first location's line numbers to provide
significantly more stability in tests.

By default, tests get the full unicode line-drawing form of diagnostics
so we can ensure all of the artifacts there make sense with the specific
case being diagnosed, but we do retain some focused ASCII-rendering
tests to ensure that fallback remains usable.

There are some issues here that will be fixed in subsequent PRs.
Notably, we try to keep the frame together in the check lines, and so
force some parts to use the first location. This largely works, but
fails in some edge cases, causing the entire frame to be located
incorrectly. There is a TODO about this that we need to fix, and it only
occurs 6 times across the test suite, so it didn't seem worth
front-loading a fix for here.

Assisted-by: Claude Code
This commit is contained in:
Chandler Carruth authored and GitHub committed 2026-11-05 07:19:59 +00:00
1 parent 0b7059a360
commit d0badecd2a
888 files changed
+39731 -12799

No files matched your search

+30 -1
View File
@@ -12,6 +12,7 @@
#include "common/command_line.h"
#include "common/pretty_stack_trace_function.h"
#include "common/version.h"
#include "toolchain/diagnostics/renderer.h"
#include "toolchain/diagnostics/stream_consumer.h"
#include "toolchain/driver/build_runtimes_subcommand.h"
#include "toolchain/driver/build_subcommand.h"
@@ -36,6 +37,8 @@ struct Options {
bool fuzzing = false;
bool include_diagnostic_kind = false;
bool diagnostic_snippets = true;
Diagnostics::LineNumbers diagnostic_line_numbers =
Diagnostics::LineNumbers::All;
bool threads = true;
bool build_runtimes_on_demand = false;
@@ -148,7 +151,7 @@ By default a diagnostic shows one view of each file it points into, with the
lines between its ranges elided, so a message and a label near it read as one
piece of code. `--no-diagnostic-snippets` drops that: each part of a diagnostic
is one line, led by its location and the extent of its range, positioned
against nothing, which is what a build log and a golden file want.
against nothing, which suits a build log.
)""",
},
[&](auto& arg_b) {
@@ -156,6 +159,31 @@ against nothing, which is what a build log and a golden file want.
arg_b.Set(&diagnostic_snippets);
});
b.AddOneOfOption(
{
.name = "diagnostic-line-numbers",
.value_name = "(all|first)",
.help = R"""(
Which line numbers diagnostics show.
By default every line of source shown is numbered, and every location has its
line and column. With `first`, only the first location in each diagnostic keeps
its line and column, normally the one it is reported at. The lines of source are
unnumbered, and every other location shows only its file name. Golden test
files use `first` so that their expected output doesn't change when lines of a
test move.
)""",
},
[&](auto& arg_b) {
arg_b.SetOneOf(
{
arg_b.OneOfValue("all", Diagnostics::LineNumbers::All)
.Default(true),
arg_b.OneOfValue("first", Diagnostics::LineNumbers::First),
},
&diagnostic_line_numbers);
});
b.AddOneOfOption(
{
.name = "terminal-background",
@@ -358,6 +386,7 @@ auto Driver::RunCommand(llvm::ArrayRef<llvm::StringRef> args) -> DriverResult {
// flag and render for whatever is behind the error stream.
consumer.set_include_diagnostic_kind(options.include_diagnostic_kind);
consumer.set_diagnostic_snippets(options.diagnostic_snippets);
consumer.set_diagnostic_line_numbers(options.diagnostic_line_numbers);
consumer.set_capabilities(ErrorCapabilities(options.terminal));
if (env.installation->error()) {