1 //===-- ModulesTests.cpp ---------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 #include "gmock/gmock.h"
12 #include "gtest/gtest.h"
21 TEST(Modules
, TextualIncludeInPreamble
) {
22 TestTU TU
= TestTU::withCode(R
"cpp(
27 TU
.ExtraArgs
.push_back("-fmodule-name=M");
28 TU
.ExtraArgs
.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
29 TU
.AdditionalFiles
["Textual.h"] = "void foo();";
30 TU
.AdditionalFiles
["m.modulemap"] = R
"modulemap(
33 textual header "Textual
.h
"
37 // Test that we do not crash.
41 // Verify that visibility of AST nodes belonging to modules, but loaded from
42 // preamble PCH, is restored.
43 TEST(Modules
, PreambleBuildVisibility
) {
44 TestTU TU
= TestTU::withCode(R
"cpp(
49 TU
.OverlayRealFileSystemForModules
= true;
50 TU
.ExtraArgs
.push_back("-fmodules");
51 TU
.ExtraArgs
.push_back("-fmodules-strict-decluse");
52 TU
.ExtraArgs
.push_back("-Xclang");
53 TU
.ExtraArgs
.push_back("-fmodules-local-submodule-visibility");
54 TU
.ExtraArgs
.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
55 TU
.AdditionalFiles
["module.h"] = R
"cpp(
58 TU
.AdditionalFiles
["m.modulemap"] = R
"modulemap(
63 EXPECT_TRUE(TU
.build().getDiagnostics().empty());
66 TEST(Modules
, Diagnostic
) {
67 // Produce a diagnostic while building an implicit module. Use
68 // -fmodules-strict-decluse, but any non-silenced diagnostic will do.
69 TestTU TU
= TestTU::withCode(R
"cpp(
75 TU
.OverlayRealFileSystemForModules
= true;
76 TU
.ExtraArgs
.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
77 TU
.ExtraArgs
.push_back("-fmodules");
78 TU
.ExtraArgs
.push_back("-fimplicit-modules");
79 TU
.ExtraArgs
.push_back("-fmodules-strict-decluse");
80 TU
.AdditionalFiles
["modular.h"] = R
"cpp(
81 #include "non
-modular
.h
"
83 TU
.AdditionalFiles
["non-modular.h"] = "";
84 TU
.AdditionalFiles
["m.modulemap"] = R
"modulemap(
90 // Test that we do not crash.
94 // Unknown module formats are a fatal failure for clang. Ensure we don't crash.
95 TEST(Modules
, UnknownFormat
) {
96 TestTU TU
= TestTU::withCode(R
"(#include "modular
.h
")");
97 TU
.OverlayRealFileSystemForModules
= true;
98 TU
.ExtraArgs
.push_back("-Xclang");
99 TU
.ExtraArgs
.push_back("-fmodule-format=obj");
100 TU
.ExtraArgs
.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
101 TU
.ExtraArgs
.push_back("-fmodules");
102 TU
.ExtraArgs
.push_back("-fimplicit-modules");
103 TU
.AdditionalFiles
["modular.h"] = "";
104 TU
.AdditionalFiles
["m.modulemap"] = R
"modulemap(
109 // Test that we do not crash.
113 } // namespace clangd