modules.carbon 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
  6. // EXTRA-ARGS: --clang-arg=--std=c++20
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/modules.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/modules.carbon
  13. // --- fail_export_module_in_inline_cpp.carbon
  14. library "[[@TEST_NAME]]";
  15. // TODO: This diagnostic isn't very good.
  16. import Cpp inline '''
  17. // 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]
  18. // CHECK:STDERR: 13 | export module Foo;
  19. // CHECK:STDERR: | ^
  20. // CHECK:STDERR: <carbon Cpp imports>:1:1: note: add 'module;' to the start of the file to introduce a global module fragment [CppInteropParseNote]
  21. // CHECK:STDERR: 1 | # 6 "fail_export_module_in_inline_cpp.carbon"
  22. // CHECK:STDERR: | ^
  23. // CHECK:STDERR:
  24. export module Foo;
  25. ''';
  26. // --- fail_module_in_inline_cpp.carbon
  27. library "[[@TEST_NAME]]";
  28. // TODO: This diagnostic isn't very good.
  29. import Cpp inline '''
  30. // CHECK:STDERR: fail_module_in_inline_cpp.carbon:[[@LINE+11]]:1: error: module declaration must occur at the start of the translation unit [CppInteropParseError]
  31. // CHECK:STDERR: 17 | module Foo;
  32. // CHECK:STDERR: | ^
  33. // CHECK:STDERR: <carbon Cpp imports>:1:1: note: add 'module;' to the start of the file to introduce a global module fragment [CppInteropParseNote]
  34. // CHECK:STDERR: 1 | # 6 "fail_module_in_inline_cpp.carbon"
  35. // CHECK:STDERR: | ^
  36. // CHECK:STDERR:
  37. // CHECK:STDERR: fail_module_in_inline_cpp.carbon:[[@LINE+4]]:8: error: module 'Foo' not found [CppInteropParseError]
  38. // CHECK:STDERR: 17 | module Foo;
  39. // CHECK:STDERR: | ^~~~
  40. // CHECK:STDERR:
  41. module Foo;
  42. ''';
  43. // --- fail_global_module_in_inline_cpp.carbon
  44. library "[[@TEST_NAME]]";
  45. // TODO: This diagnostic isn't very good.
  46. import Cpp inline '''
  47. // 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]
  48. // CHECK:STDERR: 10 | module;
  49. // CHECK:STDERR: | ^~~~~~~
  50. // CHECK:STDERR:
  51. module;
  52. int n;
  53. // 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]
  54. // CHECK:STDERR: 25 | module Foo;
  55. // CHECK:STDERR: | ^
  56. // CHECK:STDERR: <carbon Cpp imports>:1:1: note: add 'module;' to the start of the file to introduce a global module fragment [CppInteropParseNote]
  57. // CHECK:STDERR: 1 | # 6 "fail_global_module_in_inline_cpp.carbon"
  58. // CHECK:STDERR: | ^
  59. // CHECK:STDERR:
  60. // CHECK:STDERR: fail_global_module_in_inline_cpp.carbon:[[@LINE+4]]:8: error: module 'Foo' not found [CppInteropParseError]
  61. // CHECK:STDERR: 25 | module Foo;
  62. // CHECK:STDERR: | ^~~~
  63. // CHECK:STDERR:
  64. module Foo;
  65. ''';
  66. // --- fail_import_in_inline_cpp.carbon
  67. library "[[@TEST_NAME]]";
  68. // TODO: Also test that a valid module import works.
  69. import Cpp inline '''
  70. // CHECK:STDERR: fail_import_in_inline_cpp.carbon:[[@LINE+4]]:8: error: 'file_that_does_not_exist.h' file not found [CppInteropParseError]
  71. // CHECK:STDERR: 10 | import "file_that_does_not_exist.h";
  72. // CHECK:STDERR: | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. // CHECK:STDERR:
  74. import "file_that_does_not_exist.h";
  75. ''';