bad_import.carbon 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/bad_import.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/bad_import.carbon
  12. // --- fail_import_cpp_library_empty.carbon
  13. library "[[@TEST_NAME]]";
  14. // CHECK:STDERR: fail_import_cpp_library_empty.carbon:[[@LINE+4]]:10: error: empty filename [CppInteropParseError]
  15. // CHECK:STDERR: 8 | #include ""
  16. // CHECK:STDERR: | ^
  17. // CHECK:STDERR:
  18. import Cpp library "";
  19. // --- fail_import_cpp_library_file_with_quotes.carbon
  20. library "[[@TEST_NAME]]";
  21. // CHECK:STDERR: fail_import_cpp_library_file_with_quotes.carbon:[[@LINE+4]]:10: error: '\"foo.h\"' file not found [CppInteropParseError]
  22. // CHECK:STDERR: 8 | #include "\"foo.h\""
  23. // CHECK:STDERR: | ^~~~~~~~~~~
  24. // CHECK:STDERR:
  25. import Cpp library "\"foo.h\"";
  26. // --- todo_fail_unterminated_import_inline.carbon
  27. import Cpp inline '''c++
  28. void f() {
  29. ''';
  30. // TODO: We should diagnose that the inline C++ code didn't leave us at the top
  31. // level.
  32. import Cpp inline '''c++
  33. }
  34. ''';
  35. // --- fail_import_cpp_library_without_name_and_inline_without_content.carbon
  36. library "[[@TEST_NAME]]";
  37. // CHECK:STDERR: fail_import_cpp_library_without_name_and_inline_without_content.carbon:[[@LINE+8]]:20: error: expected a string literal to specify the library name [ExpectedLibraryName]
  38. // CHECK:STDERR: import Cpp library inline;
  39. // CHECK:STDERR: ^~~~~~
  40. // CHECK:STDERR:
  41. // CHECK:STDERR: fail_import_cpp_library_without_name_and_inline_without_content.carbon:[[@LINE+4]]:20: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
  42. // CHECK:STDERR: import Cpp library inline;
  43. // CHECK:STDERR: ^~~~~~
  44. // CHECK:STDERR:
  45. import Cpp library inline;
  46. // --- fail_import_cpp_library_with_name_and_inline_without_content.carbon
  47. library "[[@TEST_NAME]]";
  48. // CHECK:STDERR: fail_import_cpp_library_with_name_and_inline_without_content.carbon:[[@LINE+8]]:28: error: `import` declarations must end with a `;` [ExpectedDeclSemi]
  49. // CHECK:STDERR: import Cpp library "foo.h" inline;
  50. // CHECK:STDERR: ^~~~~~
  51. // CHECK:STDERR:
  52. // CHECK:STDERR: fail_import_cpp_library_with_name_and_inline_without_content.carbon:[[@LINE+4]]:1: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
  53. // CHECK:STDERR: import Cpp library "foo.h" inline;
  54. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. // CHECK:STDERR:
  56. import Cpp library "foo.h" inline;
  57. // --- fail_import_cpp_library_without_name_and_inline_with_content.carbon
  58. library "[[@TEST_NAME]]";
  59. // CHECK:STDERR: fail_import_cpp_library_without_name_and_inline_with_content.carbon:[[@LINE+8]]:20: error: expected a string literal to specify the library name [ExpectedLibraryName]
  60. // CHECK:STDERR: import Cpp library inline "";
  61. // CHECK:STDERR: ^~~~~~
  62. // CHECK:STDERR:
  63. // CHECK:STDERR: fail_import_cpp_library_without_name_and_inline_with_content.carbon:[[@LINE+4]]:20: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
  64. // CHECK:STDERR: import Cpp library inline "";
  65. // CHECK:STDERR: ^~~~~~
  66. // CHECK:STDERR:
  67. import Cpp library inline "";
  68. // --- fail_import_cpp_library_with_name_and_inline_with_content.carbon
  69. library "[[@TEST_NAME]]";
  70. // CHECK:STDERR: fail_import_cpp_library_with_name_and_inline_with_content.carbon:[[@LINE+8]]:28: error: `import` declarations must end with a `;` [ExpectedDeclSemi]
  71. // CHECK:STDERR: import Cpp library "foo.h" inline "";
  72. // CHECK:STDERR: ^~~~~~
  73. // CHECK:STDERR:
  74. // CHECK:STDERR: fail_import_cpp_library_with_name_and_inline_with_content.carbon:[[@LINE+4]]:1: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
  75. // CHECK:STDERR: import Cpp library "foo.h" inline "";
  76. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  77. // CHECK:STDERR:
  78. import Cpp library "foo.h" inline "";