@@ -23,6 +23,7 @@ TEST(IncludeTree, IncludeTreeScan) {
23
23
StringRef MainContents = R"(
24
24
#include "a1.h"
25
25
#include "sys.h"
26
+ #include "sys_directive.h"
26
27
)" ;
27
28
StringRef A1Contents = R"(
28
29
#if __has_include("other.h")
@@ -32,10 +33,16 @@ TEST(IncludeTree, IncludeTreeScan) {
32
33
#include "b1.h"
33
34
#endif
34
35
)" ;
36
+ StringRef SysDirectiveContents = R"(
37
+ #pragma clang system_header
38
+ #include "sys_indirect.h"
39
+ )" ;
35
40
add (" t.cpp" , MainContents);
36
41
add (" a1.h" , A1Contents);
37
42
add (" b1.h" , " " );
38
43
add (" sys/sys.h" , " " );
44
+ add (" sys_directive.h" , SysDirectiveContents);
45
+ add (" sys_indirect.h" , " " );
39
46
std::unique_ptr<llvm::vfs::FileSystem> VFS =
40
47
llvm::cas::createCASProvidingFileSystem (DB, FS);
41
48
@@ -63,6 +70,8 @@ TEST(IncludeTree, IncludeTreeScan) {
63
70
Optional<IncludeTree::File> A1File;
64
71
Optional<IncludeTree::File> B1File;
65
72
Optional<IncludeTree::File> SysFile;
73
+ Optional<IncludeTree::File> SysDirectiveFile;
74
+ Optional<IncludeTree::File> SysIndirectFile;
66
75
67
76
Optional<IncludeTree> Main;
68
77
ASSERT_THAT_ERROR (Root->getMainFileTree ().moveInto (Main), llvm::Succeeded ());
@@ -75,7 +84,7 @@ TEST(IncludeTree, IncludeTreeScan) {
75
84
EXPECT_EQ (FI.Filename , " t.cpp" );
76
85
EXPECT_EQ (FI.Contents , MainContents);
77
86
}
78
- ASSERT_EQ (Main->getNumIncludes (), uint32_t (3 ));
87
+ ASSERT_EQ (Main->getNumIncludes (), uint32_t (4 ));
79
88
80
89
Optional<IncludeTree> Predef;
81
90
ASSERT_THAT_ERROR (Main->getIncludeTree (0 ).moveInto (Predef),
@@ -132,6 +141,28 @@ TEST(IncludeTree, IncludeTreeScan) {
132
141
ASSERT_EQ (Sys->getNumIncludes (), uint32_t (0 ));
133
142
}
134
143
144
+ Optional<IncludeTree> SysDirective;
145
+ ASSERT_THAT_ERROR (Main->getIncludeTree (3 ).moveInto (SysDirective),
146
+ llvm::Succeeded ());
147
+ EXPECT_EQ (Main->getIncludeOffset (3 ), uint32_t (73 ));
148
+ {
149
+ ASSERT_THAT_ERROR (SysDirective->getBaseFile ().moveInto (SysDirectiveFile),
150
+ llvm::Succeeded ());
151
+ // Note: system_header directive injects a line directive, so C_User is for
152
+ // the start of the file here.
153
+ EXPECT_EQ (SysDirective->getFileCharacteristic (), SrcMgr::C_User);
154
+ ASSERT_EQ (SysDirective->getNumIncludes (), uint32_t (1 ));
155
+ Optional<IncludeTree> SysIndirect;
156
+ ASSERT_THAT_ERROR (SysDirective->getIncludeTree (0 ).moveInto (SysIndirect),
157
+ llvm::Succeeded ());
158
+ {
159
+ ASSERT_THAT_ERROR (SysIndirect->getBaseFile ().moveInto (SysIndirectFile),
160
+ llvm::Succeeded ());
161
+ EXPECT_EQ (SysIndirect->getFileCharacteristic (), SrcMgr::C_System);
162
+ ASSERT_EQ (SysIndirect->getNumIncludes (), uint32_t (0 ));
163
+ }
164
+ }
165
+
135
166
Optional<IncludeTree::FileList> FileList;
136
167
ASSERT_THAT_ERROR (Root->getFileList ().moveInto (FileList), llvm::Succeeded ());
137
168
@@ -143,7 +174,7 @@ TEST(IncludeTree, IncludeTreeScan) {
143
174
}),
144
175
llvm::Succeeded ());
145
176
146
- ASSERT_EQ (Files.size (), size_t (4 ));
177
+ ASSERT_EQ (Files.size (), size_t (6 ));
147
178
EXPECT_EQ (Files[0 ].first .getRef (), MainFile->getRef ());
148
179
EXPECT_EQ (Files[0 ].second , MainContents.size ());
149
180
EXPECT_EQ (Files[1 ].first .getRef (), A1File->getRef ());
@@ -152,6 +183,10 @@ TEST(IncludeTree, IncludeTreeScan) {
152
183
EXPECT_EQ (Files[2 ].second , IncludeTree::FileList::FileSizeTy (0 ));
153
184
EXPECT_EQ (Files[3 ].first .getRef (), SysFile->getRef ());
154
185
EXPECT_EQ (Files[3 ].second , IncludeTree::FileList::FileSizeTy (0 ));
186
+ EXPECT_EQ (Files[4 ].first .getRef (), SysDirectiveFile->getRef ());
187
+ EXPECT_EQ (Files[4 ].second , SysDirectiveContents.size ());
188
+ EXPECT_EQ (Files[5 ].first .getRef (), SysIndirectFile->getRef ());
189
+ EXPECT_EQ (Files[5 ].second , IncludeTree::FileList::FileSizeTy (0 ));
155
190
}
156
191
157
192
TEST (IncludeTree, IncludeTreeFileList) {
0 commit comments