From ee2b3888ef5c5756ef2231fafe98e5836d7c163a Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 6 Aug 2026 15:55:25 -0700 Subject: [PATCH] Split up tests for bad imports. (#7612) Clang treats "file not found" as a fatal error and stops emitting more diagnostics after reaching it, so these tests don't work in `--share-cpp-ast` mode if they are all in the same file. So split them into distinct test files. --- .../cpp/basics/import/bad_import.carbon | 42 ------------------- .../cpp/basics/import/bad_import_empty.carbon | 25 +++++++++++ .../import/bad_import_nested_quotes.carbon | 37 ++++++++++++++++ ...und.carbon => bad_import_not_found.carbon} | 8 +++- 4 files changed, 68 insertions(+), 44 deletions(-) create mode 100644 toolchain/check/testdata/interop/cpp/basics/import/bad_import_empty.carbon create mode 100644 toolchain/check/testdata/interop/cpp/basics/import/bad_import_nested_quotes.carbon rename toolchain/check/testdata/interop/cpp/basics/import/{file_not_found.carbon => bad_import_not_found.carbon} (75%) diff --git a/toolchain/check/testdata/interop/cpp/basics/import/bad_import.carbon b/toolchain/check/testdata/interop/cpp/basics/import/bad_import.carbon index d8135a86fd54..00eb8a0d6642 100644 --- a/toolchain/check/testdata/interop/cpp/basics/import/bad_import.carbon +++ b/toolchain/check/testdata/interop/cpp/basics/import/bad_import.carbon @@ -10,48 +10,6 @@ // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/import/bad_import.carbon -// --- fail_import_cpp_library_empty.carbon - -library "[[@TEST_NAME]]"; - -// CHECK:STDERR: fail_import_cpp_library_empty.carbon:[[@LINE+4]]:10: error: empty filename [CppInteropParseError] -// CHECK:STDERR: 8 | #include "" -// CHECK:STDERR: | ^ -// CHECK:STDERR: -import Cpp library ""; - -// --- fail_import_cpp_library_nonexistent.carbon - -library "[[@TEST_NAME]]"; - -// CHECK:STDERR: fail_import_cpp_library_nonexistent.carbon:[[@LINE+4]]:10: error: 'does_not_exist.h' file not found [CppInteropParseError] -// CHECK:STDERR: 8 | #include "does_not_exist.h" -// CHECK:STDERR: | ^~~~~~~~~~~~~~~~~~ -// CHECK:STDERR: -import Cpp library "does_not_exist.h"; - -// --- fail_todo_import_cpp_library_file_with_quotes.carbon - -library "[[@TEST_NAME]]"; - -// TODO: Translate the file to a `#include` that includes the named file -// properly. `\` escapes aren't processed in regular `#include`s. -// CHECK:STDERR: fail_todo_import_cpp_library_file_with_quotes.carbon:[[@LINE+14]]:10: error: '\' file not found [CppInteropParseError] -// CHECK:STDERR: 20 | #include "\"foo.h\"" -// CHECK:STDERR: | ^~~ -// CHECK:STDERR: -// CHECK:STDERR: fail_todo_import_cpp_library_file_with_quotes.carbon:[[@LINE+10]]:13: error: invalid suffix on literal; C++11 requires a space between literal and identifier [CppInteropParseError] -// CHECK:STDERR: 20 | #include "\"foo.h\"" -// CHECK:STDERR: | ^ -// CHECK:STDERR: | {{}} -// CHECK:STDERR: -// CHECK:STDERR: fail_todo_import_cpp_library_file_with_quotes.carbon:[[@LINE+5]]:13: warning: extra tokens at end of #include directive [CppInteropParseWarning] -// CHECK:STDERR: 20 | #include "\"foo.h\"" -// CHECK:STDERR: | ^ -// CHECK:STDERR: | // -// CHECK:STDERR: -import Cpp library "\"foo.h\""; - // --- fail_unterminated_import_inline.carbon library "[[@TEST_NAME]]"; diff --git a/toolchain/check/testdata/interop/cpp/basics/import/bad_import_empty.carbon b/toolchain/check/testdata/interop/cpp/basics/import/bad_import_empty.carbon new file mode 100644 index 000000000000..57505070d434 --- /dev/null +++ b/toolchain/check/testdata/interop/cpp/basics/import/bad_import_empty.carbon @@ -0,0 +1,25 @@ +// 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/import/bad_import_empty.carbon +// TIP: To dump output, run: +// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/import/bad_import_empty.carbon + +// This test must be in a file by itself because it produces a fatal clang error +// (file not found), which suppresses all later clang errors in the same +// compilation. + +// --- fail_import_cpp_library_empty.carbon + +library "[[@TEST_NAME]]"; + +// CHECK:STDERR: fail_import_cpp_library_empty.carbon:[[@LINE+4]]:10: error: empty filename [CppInteropParseError] +// CHECK:STDERR: 8 | #include "" +// CHECK:STDERR: | ^ +// CHECK:STDERR: +import Cpp library ""; diff --git a/toolchain/check/testdata/interop/cpp/basics/import/bad_import_nested_quotes.carbon b/toolchain/check/testdata/interop/cpp/basics/import/bad_import_nested_quotes.carbon new file mode 100644 index 000000000000..e3c4704a1bc9 --- /dev/null +++ b/toolchain/check/testdata/interop/cpp/basics/import/bad_import_nested_quotes.carbon @@ -0,0 +1,37 @@ +// 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/import/bad_import_nested_quotes.carbon +// TIP: To dump output, run: +// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/import/bad_import_nested_quotes.carbon + +// This test must be in a file by itself because it produces a fatal clang error +// (file not found), which suppresses all later clang errors in the same +// compilation. + +// --- fail_todo_import_cpp_library_file_with_quotes.carbon + +library "[[@TEST_NAME]]"; + +// TODO: Translate the file to a `#include` that includes the named file +// properly. `\` escapes aren't processed in regular `#include`s. +// CHECK:STDERR: fail_todo_import_cpp_library_file_with_quotes.carbon:[[@LINE+14]]:10: error: '\' file not found [CppInteropParseError] +// CHECK:STDERR: 20 | #include "\"foo.h\"" +// CHECK:STDERR: | ^~~ +// CHECK:STDERR: +// CHECK:STDERR: fail_todo_import_cpp_library_file_with_quotes.carbon:[[@LINE+10]]:13: error: invalid suffix on literal; C++11 requires a space between literal and identifier [CppInteropParseError] +// CHECK:STDERR: 20 | #include "\"foo.h\"" +// CHECK:STDERR: | ^ +// CHECK:STDERR: | {{}} +// CHECK:STDERR: +// CHECK:STDERR: fail_todo_import_cpp_library_file_with_quotes.carbon:[[@LINE+5]]:13: warning: extra tokens at end of #include directive [CppInteropParseWarning] +// CHECK:STDERR: 20 | #include "\"foo.h\"" +// CHECK:STDERR: | ^ +// CHECK:STDERR: | // +// CHECK:STDERR: +import Cpp library "\"foo.h\""; diff --git a/toolchain/check/testdata/interop/cpp/basics/import/file_not_found.carbon b/toolchain/check/testdata/interop/cpp/basics/import/bad_import_not_found.carbon similarity index 75% rename from toolchain/check/testdata/interop/cpp/basics/import/file_not_found.carbon rename to toolchain/check/testdata/interop/cpp/basics/import/bad_import_not_found.carbon index 22e73899ccd6..9516f9842ac6 100644 --- a/toolchain/check/testdata/interop/cpp/basics/import/file_not_found.carbon +++ b/toolchain/check/testdata/interop/cpp/basics/import/bad_import_not_found.carbon @@ -6,9 +6,13 @@ // // 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/import/file_not_found.carbon +// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/basics/import/bad_import_not_found.carbon // TIP: To dump output, run: -// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/import/file_not_found.carbon +// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/import/bad_import_not_found.carbon + +// This test must be in a file by itself because it produces a fatal clang error +// (file not found), which suppresses all later clang errors in the same +// compilation. // --- fail_cpp_file_not_found.carbon