ModulesTests.cpp
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//===-- ModulesTests.cpp ---------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "Annotations.h"
#include "TestFS.h"
#include "TestTU.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <memory>
#include <string>
namespace clang {
namespace clangd {
namespace {
TEST(Modules, TextualIncludeInPreamble) {
TestTU TU = TestTU::withCode(R"cpp(
#include "Textual.h"
void foo() {}
)cpp");
TU.ExtraArgs.push_back("-fmodule-name=M");
TU.ExtraArgs.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
TU.AdditionalFiles["Textual.h"] = "void foo();";
TU.AdditionalFiles["m.modulemap"] = R"modulemap(
module M {
module Textual {
textual header "Textual.h"
}
}
)modulemap";
// Test that we do not crash.
TU.index();
}
// Verify that visibility of AST nodes belonging to modules, but loaded from
// preamble PCH, is restored.
TEST(Modules, PreambleBuildVisibility) {
TestTU TU = TestTU::withCode(R"cpp(
#include "module.h"
foo x;
)cpp");
TU.OverlayRealFileSystemForModules = true;
TU.ExtraArgs.push_back("-fmodules");
TU.ExtraArgs.push_back("-fmodules-strict-decluse");
TU.ExtraArgs.push_back("-Xclang");
TU.ExtraArgs.push_back("-fmodules-local-submodule-visibility");
TU.ExtraArgs.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
TU.AdditionalFiles["module.h"] = R"cpp(
typedef int foo;
)cpp";
TU.AdditionalFiles["m.modulemap"] = R"modulemap(
module M {
header "module.h"
}
)modulemap";
EXPECT_TRUE(TU.build().getDiagnostics().empty());
}
TEST(Modules, Diagnostic) {
// Produce a diagnostic while building an implicit module. Use
// -fmodules-strict-decluse, but any non-silenced diagnostic will do.
TestTU TU = TestTU::withCode(R"cpp(
/*error-ok*/
#include "modular.h"
void bar() {}
)cpp");
TU.OverlayRealFileSystemForModules = true;
TU.ExtraArgs.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
TU.ExtraArgs.push_back("-fmodules");
TU.ExtraArgs.push_back("-fimplicit-modules");
TU.ExtraArgs.push_back("-fmodules-strict-decluse");
TU.AdditionalFiles["modular.h"] = R"cpp(
#include "non-modular.h"
)cpp";
TU.AdditionalFiles["non-modular.h"] = "";
TU.AdditionalFiles["m.modulemap"] = R"modulemap(
module M {
header "modular.h"
}
)modulemap";
// Test that we do not crash.
TU.build();
}
} // namespace
} // namespace clangd
} // namespace clang