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

+90 -17
View File
@@ -45,44 +45,79 @@ private override default fn I();
// --- fail_identifier_instead_of_sig.carbon
// CHECK:STDERR: fail_identifier_instead_of_sig.carbon:[[@LINE+2]]:7: error: `fn` declarations must either end with a `;` or have a `{ ... }` block for a definition [ExpectedDeclSemiOrDefinition]
// CHECK:STDERR: ╭─┤ fail_identifier_instead_of_sig.carbon:[[@LINE+8]]:7
// CHECK:STDERR: -> │ fn foo bar;
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: `fn` declarations must either end with a `;` or have a
// CHECK:STDERR: · ┃ `{ ... }` block for a definition
// CHECK:STDERR: · ┃ [ExpectedDeclSemiOrDefinition]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn foo bar;
// --- fail_missing_implicit_close.carbon
// CHECK:STDERR: fail_missing_implicit_close.carbon:[[@LINE+3]]:7: error: opening symbol without a corresponding closing symbol [UnmatchedOpening]
// CHECK:STDERR: fail_missing_implicit_close.carbon:[[@LINE+2]]:10: note: possibly missing `]` here [PossiblyMissingBracketHere]
// CHECK:STDERR: ╭─┤ fail_missing_implicit_close.carbon:[[@LINE+8]]:7
// CHECK:STDERR: -> │ fn Div[();
// CHECK:STDERR: · ┳ ┬
// CHECK:STDERR: · ┗━━━━━┫ error: opening symbol without a corresponding closing symbol
// CHECK:STDERR: · │ ┃ [UnmatchedOpening]
// CHECK:STDERR: · ╰────┤ possibly missing `]` here [PossiblyMissingBracketHere]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn Div[();
// --- fail_missing_name.carbon
// CHECK:STDERR: fail_missing_name.carbon:[[@LINE+2]]:3: error: `fn` introducer should be followed by a name [ExpectedDeclName]
// CHECK:STDERR: ╭─┤ fail_missing_name.carbon:[[@LINE+6]]:3
// CHECK:STDERR: -> │ fn ();
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: `fn` introducer should be followed by a name [ExpectedDeclName]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn ();
// --- fail_no_sig_or_semi.carbon
// CHECK:STDERR: fail_no_sig_or_semi.carbon:[[@LINE+2]]:7: error: `fn` declarations must either end with a `;` or have a `{ ... }` block for a definition [ExpectedDeclSemiOrDefinition]
// CHECK:STDERR: ╭─┤ fail_no_sig_or_semi.carbon:[[@LINE+8]]:7
// CHECK:STDERR: -> │ fn foo
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: `fn` declarations must either end with a `;` or have a
// CHECK:STDERR: · ┃ `{ ... }` block for a definition
// CHECK:STDERR: · ┃ [ExpectedDeclSemiOrDefinition]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn foo
// --- fail_only_fn_and_semi.carbon
// CHECK:STDERR: fail_only_fn_and_semi.carbon:[[@LINE+2]]:3: error: `fn` introducer should be followed by a name [ExpectedDeclName]
// CHECK:STDERR: ╭─┤ fail_only_fn_and_semi.carbon:[[@LINE+6]]:3
// CHECK:STDERR: -> │ fn;
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: `fn` introducer should be followed by a name [ExpectedDeclName]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn;
// --- fail_repeated_fn_and_semi.carbon
// CHECK:STDERR: fail_repeated_fn_and_semi.carbon:[[@LINE+2]]:4-5: error: `fn` introducer should be followed by a name; prefix reserved word with `r#` to form a valid identifier [ExpectedDeclName]
// CHECK:STDERR: ╭─┤ fail_repeated_fn_and_semi.carbon:[[@LINE+8]]:4
// CHECK:STDERR: -> │ fn fn;
// CHECK:STDERR: · ┳━
// CHECK:STDERR: · ┗━━┫ error: `fn` introducer should be followed by a name; prefix reserved
// CHECK:STDERR: · ┃ word with `r#` to form a valid identifier
// CHECK:STDERR: · ┃ [ExpectedDeclName]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn fn;
// --- fail_skip_indented_newline_until_outdent.carbon
// CHECK:STDERR: fail_skip_indented_newline_until_outdent.carbon:[[@LINE+2]]:5: error: `fn` introducer should be followed by a name [ExpectedDeclName]
// CHECK:STDERR: ╭─┤ fail_skip_indented_newline_until_outdent.carbon:[[@LINE+6]]:5
// CHECK:STDERR: -> │ fn (x,
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: `fn` introducer should be followed by a name [ExpectedDeclName]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn (x,
y,
@@ -91,7 +126,11 @@ fn F();
// --- fail_skip_indented_newline_with_semi.carbon
// CHECK:STDERR: fail_skip_indented_newline_with_semi.carbon:[[@LINE+2]]:3: error: `fn` introducer should be followed by a name [ExpectedDeclName]
// CHECK:STDERR: ╭─┤ fail_skip_indented_newline_with_semi.carbon:[[@LINE+6]]:3
// CHECK:STDERR: -> │ fn (x,
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: `fn` introducer should be followed by a name [ExpectedDeclName]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn (x,
y,
@@ -100,7 +139,11 @@ fn F();
// --- fail_skip_indented_newline_without_semi.carbon
// CHECK:STDERR: fail_skip_indented_newline_without_semi.carbon:[[@LINE+2]]:3: error: `fn` introducer should be followed by a name [ExpectedDeclName]
// CHECK:STDERR: ╭─┤ fail_skip_indented_newline_without_semi.carbon:[[@LINE+6]]:3
// CHECK:STDERR: -> │ fn (x,
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: `fn` introducer should be followed by a name [ExpectedDeclName]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn (x,
y,
@@ -109,14 +152,22 @@ fn F();
// --- fail_skip_to_newline_without_semi.carbon
// CHECK:STDERR: fail_skip_to_newline_without_semi.carbon:[[@LINE+2]]:3: error: `fn` introducer should be followed by a name [ExpectedDeclName]
// CHECK:STDERR: ╭─┤ fail_skip_to_newline_without_semi.carbon:[[@LINE+6]]:3
// CHECK:STDERR: -> │ fn ()
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: `fn` introducer should be followed by a name [ExpectedDeclName]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn ()
fn F();
// --- fail_skip_without_semi_to_curly.carbon
// CHECK:STDERR: fail_skip_without_semi_to_curly.carbon:[[@LINE+2]]:1-6: error: unrecognized declaration introducer [UnrecognizedDecl]
// CHECK:STDERR: ╭─┤ fail_skip_without_semi_to_curly.carbon:[[@LINE+6]]:1
// CHECK:STDERR: -> │ struct X { fn () }
// CHECK:STDERR: · ━━━┳━━
// CHECK:STDERR: · ┗━━┫ error: unrecognized declaration introducer [UnrecognizedDecl]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
struct X { fn () }
fn F();
@@ -127,7 +178,11 @@ fn foo(bar);
// --- fail_without_name_and_many_tokens_in_params.carbon
// CHECK:STDERR: fail_without_name_and_many_tokens_in_params.carbon:[[@LINE+2]]:3: error: `fn` introducer should be followed by a name [ExpectedDeclName]
// CHECK:STDERR: ╭─┤ fail_without_name_and_many_tokens_in_params.carbon:[[@LINE+6]]:3
// CHECK:STDERR: -> │ fn (a tokens c d e f g h i j k l m n o p q r s t u v w x y z);
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: `fn` introducer should be followed by a name [ExpectedDeclName]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn (a tokens c d e f g h i j k l m n o p q r s t u v w x y z);
@@ -138,13 +193,23 @@ fn ComplexFormParam(x:? X.Y(Z));
// --- fail_ref_on_form_parameter.carbon
// CHECK:STDERR: fail_ref_on_form_parameter.carbon:[[@LINE+2]]:6-8: error: `ref` is only allowed on a runtime binding [ExpectedRuntimeBindingPatternAfterRef]
// CHECK:STDERR: ╭─┤ fail_ref_on_form_parameter.carbon:[[@LINE+7]]:6
// CHECK:STDERR: -> │ fn F(ref x:? Form);
// CHECK:STDERR: · ━┳━
// CHECK:STDERR: · ┗━━┫ error: `ref` is only allowed on a runtime binding
// CHECK:STDERR: · ┃ [ExpectedRuntimeBindingPatternAfterRef]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn F(ref x:? Form);
// --- fail_form_within_var.carbon
// CHECK:STDERR: fail_form_within_var.carbon:[[@LINE+2]]:26: error: found `:?` binding inside `var` pattern [NonRegularBindingInVarDecl]
// CHECK:STDERR: ╭─┤ fail_form_within_var.carbon:[[@LINE+7]]:26
// CHECK:STDERR: -> │ fn FormInVar(var x:? Form);
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: found `:?` binding inside `var` pattern
// CHECK:STDERR: · ┃ [NonRegularBindingInVarDecl]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn FormInVar(var x:? Form);
@@ -161,7 +226,11 @@ let a: auto = fn -> ref u32 { return 0; };
// --- fail_ref_return_missing_type.carbon
// CHECK:STDERR: fail_ref_return_missing_type.carbon:[[@LINE+2]]:22: error: expected expression [ExpectedExpr]
// CHECK:STDERR: ╭─┤ fail_ref_return_missing_type.carbon:[[@LINE+6]]:22
// CHECK:STDERR: -> │ fn RefReturn() -> ref;
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: expected expression [ExpectedExpr]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn RefReturn() -> ref;
@@ -175,7 +244,11 @@ let b: auto = fn -> var u32 { return 0; };
// --- fail_val_return_missing_type.carbon
// CHECK:STDERR: fail_val_return_missing_type.carbon:[[@LINE+2]]:22: error: expected expression [ExpectedExpr]
// CHECK:STDERR: ╭─┤ fail_val_return_missing_type.carbon:[[@LINE+6]]:22
// CHECK:STDERR: -> │ fn ValReturn() -> val;
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: expected expression [ExpectedExpr]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn ValReturn() -> val;
+23 -4
View File
@@ -35,7 +35,11 @@ fn foo() -> f64 {
fn F() {
// Note: this might become valid depending on the expression syntax. This test
// shouldn't be taken as a sign it should remain invalid.
// CHECK:STDERR: fail_identifier_in_statements.carbon:[[@LINE+2]]:6: error: expected `;` after expression statement [ExpectedExprSemi]
// CHECK:STDERR: ╭─┤ fail_identifier_in_statements.carbon:[[@LINE+6]]:6
// CHECK:STDERR: -> │ bar
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: expected `;` after expression statement [ExpectedExprSemi]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
bar
}
@@ -59,19 +63,34 @@ impl T as I {
// --- fail_builtin_identifier.carbon
// CHECK:STDERR: fail_builtin_identifier.carbon:[[@LINE+2]]:17: error: expected builtin function name after `=` [ExpectedBuiltinName]
// CHECK:STDERR: ╭─┤ fail_builtin_identifier.carbon:[[@LINE+7]]:17
// CHECK:STDERR: -> │ fn NotString() = banana;
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: expected builtin function name after `=`
// CHECK:STDERR: · ┃ [ExpectedBuiltinName]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn NotString() = banana;
// --- fail_builtin_two_strings.carbon
// CHECK:STDERR: fail_builtin_two_strings.carbon:[[@LINE+2]]:31: error: `fn` declarations must end with a `;` [ExpectedDeclSemi]
// CHECK:STDERR: ╭─┤ fail_builtin_two_strings.carbon:[[@LINE+7]]:31
// CHECK:STDERR: -> │ fn JunkAfterString() = "hello" "world";
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: `fn` declarations must end with a `;`
// CHECK:STDERR: · ┃ [ExpectedDeclSemi]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn JunkAfterString() = "hello" "world";
// --- fail_builtin_spurious_equals.carbon
// CHECK:STDERR: fail_builtin_spurious_equals.carbon:[[@LINE+2]]:22: error: expected builtin function name after `=` [ExpectedBuiltinName]
// CHECK:STDERR: ╭─┤ fail_builtin_spurious_equals.carbon:[[@LINE+7]]:22
// CHECK:STDERR: -> │ fn SpuriousEquals() = { }
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: expected builtin function name after `=`
// CHECK:STDERR: · ┃ [ExpectedBuiltinName]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn SpuriousEquals() = { }
fn TestRecoveryFromSpuriousEquals();
+20 -3
View File
@@ -22,15 +22,32 @@ extern library default fn G();
// --- fail_name_missing.carbon
// CHECK:STDERR: fail_name_missing.carbon:[[@LINE+2]]:15: error: expected `default` or a string literal to specify the library name [ExpectedLibraryNameOrDefault]
// CHECK:STDERR: ╭─┤ fail_name_missing.carbon:[[@LINE+8]]:15
// CHECK:STDERR: -> │ extern library fn G();
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: expected `default` or a string literal to specify the
// CHECK:STDERR: · ┃ library name
// CHECK:STDERR: · ┃ [ExpectedLibraryNameOrDefault]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
extern library fn G();
// --- fail_identifier.carbon
// CHECK:STDERR: fail_identifier.carbon:[[@LINE+4]]:15: error: expected `default` or a string literal to specify the library name [ExpectedLibraryNameOrDefault]
// CHECK:STDERR: ╭─┤ fail_identifier.carbon:[[@LINE+15]]:15
// CHECK:STDERR: -> │ extern library foo fn G();
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: expected `default` or a string literal to specify the
// CHECK:STDERR: · ┃ library name
// CHECK:STDERR: · ┃ [ExpectedLibraryNameOrDefault]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
// CHECK:STDERR: fail_identifier.carbon:[[@LINE+2]]:16-18: error: unrecognized declaration introducer [UnrecognizedDecl]
// CHECK:STDERR: ╭─┤ fail_identifier.carbon:[[@LINE+7]]:16
// CHECK:STDERR: -> │ extern library foo fn G();
// CHECK:STDERR: · ━┳━
// CHECK:STDERR: · ┗━━┫ error: unrecognized declaration introducer
// CHECK:STDERR: · ┃ [UnrecognizedDecl]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
extern library foo fn G();
@@ -9,7 +9,12 @@
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/function/fail_template_form_param.carbon
// `template` cannot be combined with a `:?` form binding.
// CHECK:STDERR: fail_template_form_param.carbon:[[@LINE+2]]:6-13: error: `template` is only allowed on a generic binding [ExpectedGenericBindingPatternAfterTemplate]
// CHECK:STDERR: ╭─┤ fail_template_form_param.carbon:[[@LINE+7]]:6
// CHECK:STDERR: -> │ fn F(template x:? Form);
// CHECK:STDERR: · ━━━━┳━━━
// CHECK:STDERR: · ┗━━┫ error: `template` is only allowed on a generic binding
// CHECK:STDERR: · ┃ [ExpectedGenericBindingPatternAfterTemplate]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn F(template x:? Form);