Files
carbon-lang/toolchain/check/testdata/interop/cpp/basics/inline/modules.carbon
T
Richard SmithandChandler Carruth c588eadb57 Rename and rearrange entities in tests to avoid name reuse (#7656)
Fix a bunch of cases where we use the same external name to mean
multiple different things in the same test. We've historically gotten
away with this, but under `--share-cpp-ast`, it becomes an error, at
least if the entity is either defined in, or used from, C++ code.

Assisted-by: Gemini via Antigravity (original change) and Claude Code
(suggested edits in review)

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2026-08-21 01:36:40 +00:00

106 lines
4.7 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
// EXTRA-ARGS: --clang-arg=--std=c++20
//
// 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/modules.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/inline/modules.carbon
// --- fail_export_module_in_inline_cpp.carbon
library "[[@TEST_NAME]]";
// TODO: This diagnostic isn't very good.
import Cpp inline '''
// CHECK:STDERR: fail_export_module_in_inline_cpp.carbon:[[@LINE+11]]:8: error: module declaration must not come from an #include directive [CppInteropParseError]
// CHECK:STDERR: 17 | export module Foo;
// CHECK:STDERR: | ^~~~~~~~~~~
// CHECK:STDERR:
// CHECK:STDERR: fail_export_module_in_inline_cpp.carbon:[[@LINE+7]]:8: error: module declaration must occur at the start of the translation unit [CppInteropParseError]
// CHECK:STDERR: 17 | export module Foo;
// CHECK:STDERR: | ^
// CHECK:STDERR: <carbon Cpp imports>:1:1: note: add 'module;' to the start of the file to introduce a global module fragment [CppInteropParseNote]
// CHECK:STDERR: 1 | ;
// CHECK:STDERR: | ^
// CHECK:STDERR:
export module Foo;
''';
// --- fail_module_in_inline_cpp.carbon
library "[[@TEST_NAME]]";
// TODO: This diagnostic isn't very good.
import Cpp inline '''
// CHECK:STDERR: fail_module_in_inline_cpp.carbon:[[@LINE+15]]:1: error: module declaration must not come from an #include directive [CppInteropParseError]
// CHECK:STDERR: 21 | module Bar;
// CHECK:STDERR: | ^~~~~~~~~~~
// CHECK:STDERR:
// CHECK:STDERR: fail_module_in_inline_cpp.carbon:[[@LINE+11]]:1: error: module declaration must occur at the start of the translation unit [CppInteropParseError]
// CHECK:STDERR: 21 | module Bar;
// CHECK:STDERR: | ^
// CHECK:STDERR: <carbon Cpp imports>:1:1: note: add 'module;' to the start of the file to introduce a global module fragment [CppInteropParseNote]
// CHECK:STDERR: 1 | ;
// CHECK:STDERR: | ^
// CHECK:STDERR:
// CHECK:STDERR: fail_module_in_inline_cpp.carbon:[[@LINE+4]]:8: error: module name 'Foo' specified on command line does not match name of module [CppInteropParseError]
// CHECK:STDERR: 21 | module Bar;
// CHECK:STDERR: | ^~~
// CHECK:STDERR:
module Bar;
''';
// --- fail_global_module_in_inline_cpp.carbon
library "[[@TEST_NAME]]";
// TODO: This diagnostic isn't very good.
import Cpp inline '''
// CHECK:STDERR: fail_global_module_in_inline_cpp.carbon:[[@LINE+8]]:1: error: module declaration must not come from an #include directive [CppInteropParseError]
// CHECK:STDERR: 14 | module;
// CHECK:STDERR: | ^~~~~~~
// CHECK:STDERR:
// CHECK:STDERR: fail_global_module_in_inline_cpp.carbon:[[@LINE+4]]:1: error: 'module;' introducing a global module fragment can appear only at the start of the translation unit [CppInteropParseError]
// CHECK:STDERR: 14 | module;
// CHECK:STDERR: | ^~~~~~~
// CHECK:STDERR:
module;
int n;
// CHECK:STDERR: fail_global_module_in_inline_cpp.carbon:[[@LINE+15]]:1: error: module declaration must not come from an #include directive [CppInteropParseError]
// CHECK:STDERR: 33 | module Baz;
// CHECK:STDERR: | ^~~~~~~~~~~
// CHECK:STDERR:
// CHECK:STDERR: fail_global_module_in_inline_cpp.carbon:[[@LINE+11]]:1: error: module declaration must occur at the start of the translation unit [CppInteropParseError]
// CHECK:STDERR: 33 | module Baz;
// CHECK:STDERR: | ^
// CHECK:STDERR: <carbon Cpp imports>:1:1: note: add 'module;' to the start of the file to introduce a global module fragment [CppInteropParseNote]
// CHECK:STDERR: 1 | ;
// CHECK:STDERR: | ^
// CHECK:STDERR:
// CHECK:STDERR: fail_global_module_in_inline_cpp.carbon:[[@LINE+4]]:8: error: module name 'Foo' specified on command line does not match name of module [CppInteropParseError]
// CHECK:STDERR: 33 | module Baz;
// CHECK:STDERR: | ^~~
// CHECK:STDERR:
module Baz;
''';
// --- fail_import_in_inline_cpp.carbon
library "[[@TEST_NAME]]";
// TODO: Also test that a valid module import works.
import Cpp inline '''
// CHECK:STDERR: fail_import_in_inline_cpp.carbon:[[@LINE+4]]:8: error: 'file_that_does_not_exist.h' file not found [CppInteropParseError]
// CHECK:STDERR: 10 | import "file_that_does_not_exist.h";
// CHECK:STDERR: | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
import "file_that_does_not_exist.h";
''';