Files
carbon-lang/toolchain/check/testdata/interop/cpp/basics/inline/decl.carbon
T
Chandler Carruth d0badecd2a 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
2026-11-05 07:19:59 +00:00

170 lines
5.6 KiB
Plaintext

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/inline/decl.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/inline/decl.carbon
// --- inline_decl.carbon
library "[[@TEST_NAME]]";
import Cpp;
inline Cpp '''
void func1() {}
''';
fn Run1() {
Cpp.func1();
}
inline Cpp '''
void func2() {
Carbon::Run1();
}
''';
fn Run2() {
Cpp.func2();
}
// --- fail_redefinition.carbon
library "[[@TEST_NAME]]";
import Cpp;
inline Cpp '''
void f() {}
''';
inline Cpp '''
// CHECK:STDERR: ╭─┤ fail_redefinition.carbon:[[@LINE+10]]:6
// CHECK:STDERR: │ void f() {}
// CHECK:STDERR: · ┬
// CHECK:STDERR: · ╰──┤ previous definition is here [CppInteropParseNote]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ void f() {}
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: redefinition of 'f' [CppInteropParseError]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
void f() {}
''';
// --- fail_diag_location.carbon
library "[[@TEST_NAME]]";
import Cpp;
// CHECK:STDERR: ╭─┤ fail_diag_location.carbon:[[@LINE+7]]:12
// CHECK:STDERR: -> │ void f() { undeclared = 0; }
// CHECK:STDERR: · ━━━━━┳━━━━
// CHECK:STDERR: · ┗━━┫ error: use of undeclared identifier 'undeclared'
// CHECK:STDERR: · ┃ [CppInteropParseError]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
inline Cpp "void f() { undeclared = 0; }";
inline Cpp '''
void g() {
// CHECK:STDERR: ╭─┤ fail_diag_location.carbon:[[@LINE+7]]:3
// CHECK:STDERR: -> │ undeclared = 0;
// CHECK:STDERR: · ━━━━━┳━━━━
// CHECK:STDERR: · ┗━━┫ error: use of undeclared identifier 'undeclared'
// CHECK:STDERR: · ┃ [CppInteropParseError]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
undeclared = 0;
}
''';
// --- fail_inline_no_import.carbon
library "[[@TEST_NAME]]";
// CHECK:STDERR: ╭─┤ fail_inline_no_import.carbon:[[@LINE+6]]:8
// CHECK:STDERR: -> │ inline Cpp "";
// CHECK:STDERR: · ━┳━
// CHECK:STDERR: · ┗━━┫ error: name `Cpp` not found [NameNotFound]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
inline Cpp "";
// --- fail_nested.carbon
library "[[@TEST_NAME]]";
import Cpp;
class C {
// CHECK:STDERR: ╭─┤ fail_nested.carbon:[[@LINE+7]]:3
// CHECK:STDERR: -> │ inline Cpp "";
// CHECK:STDERR: · ━━━━━━━┳━━━━━━
// CHECK:STDERR: · ┗━━┫ error: `inline Cpp` declaration not at file scope
// CHECK:STDERR: · ┃ [InlineDeclNotAtFileScope]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
inline Cpp "";
}
interface I {
// CHECK:STDERR: ╭─┤ fail_nested.carbon:[[@LINE+7]]:3
// CHECK:STDERR: -> │ inline Cpp "";
// CHECK:STDERR: · ━━━━━━━┳━━━━━━
// CHECK:STDERR: · ┗━━┫ error: `inline Cpp` declaration not at file scope
// CHECK:STDERR: · ┃ [InlineDeclNotAtFileScope]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
inline Cpp "";
}
constraint N {
// CHECK:STDERR: ╭─┤ fail_nested.carbon:[[@LINE+7]]:3
// CHECK:STDERR: -> │ inline Cpp "";
// CHECK:STDERR: · ━━━━━━━┳━━━━━━
// CHECK:STDERR: · ┗━━┫ error: `inline Cpp` declaration not at file scope
// CHECK:STDERR: · ┃ [InlineDeclNotAtFileScope]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
inline Cpp "";
}
impl C as I {
// CHECK:STDERR: ╭─┤ fail_nested.carbon:[[@LINE+7]]:3
// CHECK:STDERR: -> │ inline Cpp "";
// CHECK:STDERR: · ━━━━━━━┳━━━━━━
// CHECK:STDERR: · ┗━━┫ error: `inline Cpp` declaration not at file scope
// CHECK:STDERR: · ┃ [InlineDeclNotAtFileScope]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
inline Cpp "";
}
// --- fail_nested_fn.carbon
fn F() {
// TODO: Should this be a check error rather than a parse error?
// CHECK:STDERR: ╭─┤ fail_nested_fn.carbon:[[@LINE+13]]:3
// CHECK:STDERR: -> │ inline Cpp "";
// CHECK:STDERR: · ━━━┳━━
// CHECK:STDERR: · ┗━━┫ error: expected expression [ExpectedExpr]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
// CHECK:STDERR: ╭─┤ fail_nested_fn.carbon:[[@LINE+7]]:3
// CHECK:STDERR: -> │ inline Cpp "";
// CHECK:STDERR: · ━━━┳━━
// CHECK:STDERR: · ┗━━┫ error: semantics TODO: `handle invalid parse trees in `check``
// CHECK:STDERR: · ┃ [SemanticsTodo]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
inline Cpp "";
}