Dmitri Gribenko | f85b929 | 2014-02-18 15:29:17 +0000 | [diff] [blame] | 1 | //===- unittests/libclang/LibclangTest.cpp --- libclang tests -------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "clang-c/Index.h" |
| 11 | #include "gtest/gtest.h" |
Ben Langmuir | f3050d2 | 2014-06-27 17:04:26 +0000 | [diff] [blame] | 12 | #include "llvm/Support/Debug.h" |
| 13 | #include "llvm/Support/FileSystem.h" |
| 14 | #include "llvm/Support/Path.h" |
| 15 | #include "llvm/Support/raw_ostream.h" |
| 16 | #include <fstream> |
| 17 | #include <set> |
| 18 | #define DEBUG_TYPE "libclang-test" |
Dmitri Gribenko | f85b929 | 2014-02-18 15:29:17 +0000 | [diff] [blame] | 19 | |
Dmitri Gribenko | 8850cda | 2014-02-19 10:24:00 +0000 | [diff] [blame] | 20 | TEST(libclang, clang_parseTranslationUnit2_InvalidArgs) { |
Dmitri Gribenko | f85b929 | 2014-02-18 15:29:17 +0000 | [diff] [blame] | 21 | EXPECT_EQ(CXError_InvalidArguments, |
Craig Topper | 416fa34 | 2014-06-08 08:38:12 +0000 | [diff] [blame] | 22 | clang_parseTranslationUnit2(nullptr, nullptr, nullptr, 0, nullptr, |
| 23 | 0, 0, nullptr)); |
Dmitri Gribenko | f85b929 | 2014-02-18 15:29:17 +0000 | [diff] [blame] | 24 | } |
| 25 | |
Dmitri Gribenko | 8850cda | 2014-02-19 10:24:00 +0000 | [diff] [blame] | 26 | TEST(libclang, clang_createTranslationUnit_InvalidArgs) { |
Craig Topper | 416fa34 | 2014-06-08 08:38:12 +0000 | [diff] [blame] | 27 | EXPECT_EQ(nullptr, clang_createTranslationUnit(nullptr, nullptr)); |
Dmitri Gribenko | 8850cda | 2014-02-19 10:24:00 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | TEST(libclang, clang_createTranslationUnit2_InvalidArgs) { |
| 31 | EXPECT_EQ(CXError_InvalidArguments, |
Craig Topper | 416fa34 | 2014-06-08 08:38:12 +0000 | [diff] [blame] | 32 | clang_createTranslationUnit2(nullptr, nullptr, nullptr)); |
Dmitri Gribenko | 8850cda | 2014-02-19 10:24:00 +0000 | [diff] [blame] | 33 | |
| 34 | CXTranslationUnit TU = reinterpret_cast<CXTranslationUnit>(1); |
| 35 | EXPECT_EQ(CXError_InvalidArguments, |
Craig Topper | 416fa34 | 2014-06-08 08:38:12 +0000 | [diff] [blame] | 36 | clang_createTranslationUnit2(nullptr, nullptr, &TU)); |
| 37 | EXPECT_EQ(nullptr, TU); |
Dmitri Gribenko | 8850cda | 2014-02-19 10:24:00 +0000 | [diff] [blame] | 38 | } |
Argyrios Kyrtzidis | 0b9682e | 2014-02-25 03:59:23 +0000 | [diff] [blame] | 39 | |
| 40 | namespace { |
| 41 | struct TestVFO { |
| 42 | const char *Contents; |
| 43 | CXVirtualFileOverlay VFO; |
| 44 | |
| 45 | TestVFO(const char *Contents) : Contents(Contents) { |
| 46 | VFO = clang_VirtualFileOverlay_create(0); |
| 47 | } |
| 48 | |
| 49 | void map(const char *VPath, const char *RPath) { |
| 50 | CXErrorCode Err = clang_VirtualFileOverlay_addFileMapping(VFO, VPath, RPath); |
| 51 | EXPECT_EQ(Err, CXError_Success); |
| 52 | } |
| 53 | |
| 54 | void mapError(const char *VPath, const char *RPath, CXErrorCode ExpErr) { |
| 55 | CXErrorCode Err = clang_VirtualFileOverlay_addFileMapping(VFO, VPath, RPath); |
| 56 | EXPECT_EQ(Err, ExpErr); |
| 57 | } |
| 58 | |
| 59 | ~TestVFO() { |
Nico Weber | 655af09 | 2014-04-24 19:04:10 +0000 | [diff] [blame] | 60 | if (Contents) { |
| 61 | char *BufPtr; |
| 62 | unsigned BufSize; |
| 63 | clang_VirtualFileOverlay_writeToBuffer(VFO, 0, &BufPtr, &BufSize); |
| 64 | std::string BufStr(BufPtr, BufSize); |
| 65 | EXPECT_STREQ(Contents, BufStr.c_str()); |
| 66 | free(BufPtr); |
| 67 | } |
Argyrios Kyrtzidis | 0b9682e | 2014-02-25 03:59:23 +0000 | [diff] [blame] | 68 | clang_VirtualFileOverlay_dispose(VFO); |
| 69 | } |
| 70 | }; |
| 71 | } |
| 72 | |
Justin Bogner | 5719614 | 2014-05-20 23:52:11 +0000 | [diff] [blame] | 73 | TEST(libclang, VirtualFileOverlay_Basic) { |
| 74 | const char *contents = |
| 75 | "{\n" |
| 76 | " 'version': 0,\n" |
| 77 | " 'roots': [\n" |
| 78 | " {\n" |
| 79 | " 'type': 'directory',\n" |
| 80 | " 'name': \"/path/virtual\",\n" |
| 81 | " 'contents': [\n" |
| 82 | " {\n" |
| 83 | " 'type': 'file',\n" |
| 84 | " 'name': \"foo.h\",\n" |
| 85 | " 'external-contents': \"/real/foo.h\"\n" |
| 86 | " }\n" |
| 87 | " ]\n" |
| 88 | " }\n" |
| 89 | " ]\n" |
| 90 | "}\n"; |
| 91 | TestVFO T(contents); |
| 92 | T.map("/path/virtual/foo.h", "/real/foo.h"); |
| 93 | } |
| 94 | |
| 95 | TEST(libclang, VirtualFileOverlay_Unicode) { |
| 96 | const char *contents = |
| 97 | "{\n" |
| 98 | " 'version': 0,\n" |
| 99 | " 'roots': [\n" |
| 100 | " {\n" |
| 101 | " 'type': 'directory',\n" |
| 102 | " 'name': \"/path/\\u266B\",\n" |
| 103 | " 'contents': [\n" |
| 104 | " {\n" |
| 105 | " 'type': 'file',\n" |
| 106 | " 'name': \"\\u2602.h\",\n" |
| 107 | " 'external-contents': \"/real/\\u2602.h\"\n" |
| 108 | " }\n" |
| 109 | " ]\n" |
| 110 | " }\n" |
| 111 | " ]\n" |
| 112 | "}\n"; |
| 113 | TestVFO T(contents); |
| 114 | T.map("/path/♫/☂.h", "/real/☂.h"); |
| 115 | } |
| 116 | |
| 117 | TEST(libclang, VirtualFileOverlay_InvalidArgs) { |
Craig Topper | 416fa34 | 2014-06-08 08:38:12 +0000 | [diff] [blame] | 118 | TestVFO T(nullptr); |
Justin Bogner | 5719614 | 2014-05-20 23:52:11 +0000 | [diff] [blame] | 119 | T.mapError("/path/./virtual/../foo.h", "/real/foo.h", |
| 120 | CXError_InvalidArguments); |
| 121 | } |
| 122 | |
| 123 | TEST(libclang, VirtualFileOverlay_RemapDirectories) { |
| 124 | const char *contents = |
| 125 | "{\n" |
| 126 | " 'version': 0,\n" |
| 127 | " 'roots': [\n" |
| 128 | " {\n" |
| 129 | " 'type': 'directory',\n" |
| 130 | " 'name': \"/another/dir\",\n" |
| 131 | " 'contents': [\n" |
| 132 | " {\n" |
| 133 | " 'type': 'file',\n" |
| 134 | " 'name': \"foo2.h\",\n" |
| 135 | " 'external-contents': \"/real/foo2.h\"\n" |
| 136 | " }\n" |
| 137 | " ]\n" |
| 138 | " },\n" |
| 139 | " {\n" |
| 140 | " 'type': 'directory',\n" |
| 141 | " 'name': \"/path/virtual/dir\",\n" |
| 142 | " 'contents': [\n" |
| 143 | " {\n" |
| 144 | " 'type': 'file',\n" |
| 145 | " 'name': \"foo1.h\",\n" |
| 146 | " 'external-contents': \"/real/foo1.h\"\n" |
| 147 | " },\n" |
| 148 | " {\n" |
| 149 | " 'type': 'file',\n" |
| 150 | " 'name': \"foo3.h\",\n" |
| 151 | " 'external-contents': \"/real/foo3.h\"\n" |
| 152 | " },\n" |
| 153 | " {\n" |
| 154 | " 'type': 'directory',\n" |
| 155 | " 'name': \"in/subdir\",\n" |
| 156 | " 'contents': [\n" |
| 157 | " {\n" |
| 158 | " 'type': 'file',\n" |
| 159 | " 'name': \"foo4.h\",\n" |
| 160 | " 'external-contents': \"/real/foo4.h\"\n" |
| 161 | " }\n" |
| 162 | " ]\n" |
| 163 | " }\n" |
| 164 | " ]\n" |
| 165 | " }\n" |
| 166 | " ]\n" |
| 167 | "}\n"; |
| 168 | TestVFO T(contents); |
| 169 | T.map("/path/virtual/dir/foo1.h", "/real/foo1.h"); |
| 170 | T.map("/another/dir/foo2.h", "/real/foo2.h"); |
| 171 | T.map("/path/virtual/dir/foo3.h", "/real/foo3.h"); |
| 172 | T.map("/path/virtual/dir/in/subdir/foo4.h", "/real/foo4.h"); |
| 173 | } |
| 174 | |
| 175 | TEST(libclang, VirtualFileOverlay_CaseInsensitive) { |
| 176 | const char *contents = |
| 177 | "{\n" |
| 178 | " 'version': 0,\n" |
| 179 | " 'case-sensitive': 'false',\n" |
| 180 | " 'roots': [\n" |
| 181 | " {\n" |
| 182 | " 'type': 'directory',\n" |
| 183 | " 'name': \"/path/virtual\",\n" |
| 184 | " 'contents': [\n" |
| 185 | " {\n" |
| 186 | " 'type': 'file',\n" |
| 187 | " 'name': \"foo.h\",\n" |
| 188 | " 'external-contents': \"/real/foo.h\"\n" |
| 189 | " }\n" |
| 190 | " ]\n" |
| 191 | " }\n" |
| 192 | " ]\n" |
| 193 | "}\n"; |
| 194 | TestVFO T(contents); |
| 195 | T.map("/path/virtual/foo.h", "/real/foo.h"); |
| 196 | clang_VirtualFileOverlay_setCaseSensitivity(T.VFO, false); |
| 197 | } |
| 198 | |
| 199 | TEST(libclang, VirtualFileOverlay_SharedPrefix) { |
| 200 | const char *contents = |
| 201 | "{\n" |
| 202 | " 'version': 0,\n" |
| 203 | " 'roots': [\n" |
| 204 | " {\n" |
| 205 | " 'type': 'directory',\n" |
| 206 | " 'name': \"/path/foo\",\n" |
| 207 | " 'contents': [\n" |
| 208 | " {\n" |
| 209 | " 'type': 'file',\n" |
| 210 | " 'name': \"bar\",\n" |
| 211 | " 'external-contents': \"/real/bar\"\n" |
| 212 | " },\n" |
| 213 | " {\n" |
| 214 | " 'type': 'file',\n" |
| 215 | " 'name': \"bar.h\",\n" |
| 216 | " 'external-contents': \"/real/bar.h\"\n" |
| 217 | " }\n" |
| 218 | " ]\n" |
| 219 | " },\n" |
| 220 | " {\n" |
| 221 | " 'type': 'directory',\n" |
| 222 | " 'name': \"/path/foobar\",\n" |
| 223 | " 'contents': [\n" |
| 224 | " {\n" |
| 225 | " 'type': 'file',\n" |
| 226 | " 'name': \"baz.h\",\n" |
| 227 | " 'external-contents': \"/real/baz.h\"\n" |
| 228 | " }\n" |
| 229 | " ]\n" |
| 230 | " },\n" |
| 231 | " {\n" |
| 232 | " 'type': 'directory',\n" |
| 233 | " 'name': \"/path\",\n" |
| 234 | " 'contents': [\n" |
| 235 | " {\n" |
| 236 | " 'type': 'file',\n" |
| 237 | " 'name': \"foobarbaz.h\",\n" |
| 238 | " 'external-contents': \"/real/foobarbaz.h\"\n" |
| 239 | " }\n" |
| 240 | " ]\n" |
| 241 | " }\n" |
| 242 | " ]\n" |
| 243 | "}\n"; |
| 244 | TestVFO T(contents); |
| 245 | T.map("/path/foo/bar.h", "/real/bar.h"); |
| 246 | T.map("/path/foo/bar", "/real/bar"); |
| 247 | T.map("/path/foobar/baz.h", "/real/baz.h"); |
| 248 | T.map("/path/foobarbaz.h", "/real/foobarbaz.h"); |
Argyrios Kyrtzidis | 0b9682e | 2014-02-25 03:59:23 +0000 | [diff] [blame] | 249 | } |
Argyrios Kyrtzidis | d502a10 | 2014-03-03 07:41:45 +0000 | [diff] [blame] | 250 | |
Justin Bogner | 44fa45034 | 2014-05-21 22:46:51 +0000 | [diff] [blame] | 251 | TEST(libclang, VirtualFileOverlay_AdjacentDirectory) { |
| 252 | const char *contents = |
| 253 | "{\n" |
| 254 | " 'version': 0,\n" |
| 255 | " 'roots': [\n" |
| 256 | " {\n" |
| 257 | " 'type': 'directory',\n" |
| 258 | " 'name': \"/path/dir1\",\n" |
| 259 | " 'contents': [\n" |
| 260 | " {\n" |
| 261 | " 'type': 'file',\n" |
| 262 | " 'name': \"foo.h\",\n" |
| 263 | " 'external-contents': \"/real/foo.h\"\n" |
| 264 | " },\n" |
| 265 | " {\n" |
| 266 | " 'type': 'directory',\n" |
| 267 | " 'name': \"subdir\",\n" |
| 268 | " 'contents': [\n" |
| 269 | " {\n" |
| 270 | " 'type': 'file',\n" |
| 271 | " 'name': \"bar.h\",\n" |
| 272 | " 'external-contents': \"/real/bar.h\"\n" |
| 273 | " }\n" |
| 274 | " ]\n" |
| 275 | " }\n" |
| 276 | " ]\n" |
| 277 | " },\n" |
| 278 | " {\n" |
| 279 | " 'type': 'directory',\n" |
| 280 | " 'name': \"/path/dir2\",\n" |
| 281 | " 'contents': [\n" |
| 282 | " {\n" |
| 283 | " 'type': 'file',\n" |
| 284 | " 'name': \"baz.h\",\n" |
| 285 | " 'external-contents': \"/real/baz.h\"\n" |
| 286 | " }\n" |
| 287 | " ]\n" |
| 288 | " }\n" |
| 289 | " ]\n" |
| 290 | "}\n"; |
| 291 | TestVFO T(contents); |
| 292 | T.map("/path/dir1/foo.h", "/real/foo.h"); |
| 293 | T.map("/path/dir1/subdir/bar.h", "/real/bar.h"); |
| 294 | T.map("/path/dir2/baz.h", "/real/baz.h"); |
| 295 | } |
| 296 | |
| 297 | TEST(libclang, VirtualFileOverlay_TopLevel) { |
| 298 | const char *contents = |
| 299 | "{\n" |
| 300 | " 'version': 0,\n" |
| 301 | " 'roots': [\n" |
| 302 | " {\n" |
| 303 | " 'type': 'directory',\n" |
| 304 | " 'name': \"/\",\n" |
| 305 | " 'contents': [\n" |
| 306 | " {\n" |
| 307 | " 'type': 'file',\n" |
| 308 | " 'name': \"foo.h\",\n" |
| 309 | " 'external-contents': \"/real/foo.h\"\n" |
| 310 | " }\n" |
| 311 | " ]\n" |
| 312 | " }\n" |
| 313 | " ]\n" |
| 314 | "}\n"; |
| 315 | TestVFO T(contents); |
| 316 | T.map("/foo.h", "/real/foo.h"); |
| 317 | } |
| 318 | |
Justin Bogner | 7346640 | 2014-07-15 01:24:35 +0000 | [diff] [blame] | 319 | TEST(libclang, VirtualFileOverlay_Empty) { |
| 320 | const char *contents = |
| 321 | "{\n" |
| 322 | " 'version': 0,\n" |
| 323 | " 'roots': [\n" |
| 324 | " ]\n" |
| 325 | "}\n"; |
| 326 | TestVFO T(contents); |
| 327 | } |
| 328 | |
Argyrios Kyrtzidis | d502a10 | 2014-03-03 07:41:45 +0000 | [diff] [blame] | 329 | TEST(libclang, ModuleMapDescriptor) { |
| 330 | const char *Contents = |
| 331 | "framework module TestFrame {\n" |
| 332 | " umbrella header \"TestFrame.h\"\n" |
| 333 | "\n" |
| 334 | " export *\n" |
| 335 | " module * { export * }\n" |
| 336 | "}\n"; |
| 337 | |
| 338 | CXModuleMapDescriptor MMD = clang_ModuleMapDescriptor_create(0); |
| 339 | |
| 340 | clang_ModuleMapDescriptor_setFrameworkModuleName(MMD, "TestFrame"); |
| 341 | clang_ModuleMapDescriptor_setUmbrellaHeader(MMD, "TestFrame.h"); |
| 342 | |
| 343 | char *BufPtr; |
| 344 | unsigned BufSize; |
| 345 | clang_ModuleMapDescriptor_writeToBuffer(MMD, 0, &BufPtr, &BufSize); |
| 346 | std::string BufStr(BufPtr, BufSize); |
| 347 | EXPECT_STREQ(Contents, BufStr.c_str()); |
| 348 | free(BufPtr); |
| 349 | clang_ModuleMapDescriptor_dispose(MMD); |
| 350 | } |
Ben Langmuir | f3050d2 | 2014-06-27 17:04:26 +0000 | [diff] [blame] | 351 | |
| 352 | class LibclangReparseTest : public ::testing::Test { |
Ben Langmuir | f3050d2 | 2014-06-27 17:04:26 +0000 | [diff] [blame] | 353 | std::set<std::string> Files; |
| 354 | public: |
Ben Langmuir | 33c8090 | 2014-06-30 20:04:14 +0000 | [diff] [blame] | 355 | std::string TestDir; |
Ben Langmuir | f3050d2 | 2014-06-27 17:04:26 +0000 | [diff] [blame] | 356 | CXIndex Index; |
| 357 | CXTranslationUnit ClangTU; |
| 358 | unsigned TUFlags; |
| 359 | |
| 360 | void SetUp() { |
| 361 | llvm::SmallString<256> Dir; |
| 362 | ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory("libclang-test", Dir)); |
| 363 | TestDir = Dir.str(); |
| 364 | TUFlags = CXTranslationUnit_DetailedPreprocessingRecord | |
| 365 | clang_defaultEditingTranslationUnitOptions(); |
| 366 | Index = clang_createIndex(0, 0); |
| 367 | } |
| 368 | void TearDown() { |
| 369 | clang_disposeTranslationUnit(ClangTU); |
| 370 | clang_disposeIndex(Index); |
| 371 | for (const std::string &Path : Files) |
| 372 | llvm::sys::fs::remove(Path); |
| 373 | llvm::sys::fs::remove(TestDir); |
| 374 | } |
| 375 | void WriteFile(std::string &Filename, const std::string &Contents) { |
| 376 | if (!llvm::sys::path::is_absolute(Filename)) { |
| 377 | llvm::SmallString<256> Path(TestDir); |
| 378 | llvm::sys::path::append(Path, Filename); |
| 379 | Filename = Path.str(); |
| 380 | Files.insert(Filename); |
| 381 | } |
| 382 | std::ofstream OS(Filename); |
| 383 | OS << Contents; |
| 384 | } |
| 385 | void DisplayDiagnostics() { |
NAKAMURA Takumi | 6189422 | 2014-06-29 11:07:48 +0000 | [diff] [blame] | 386 | unsigned NumDiagnostics = clang_getNumDiagnostics(ClangTU); |
| 387 | for (unsigned i = 0; i < NumDiagnostics; ++i) { |
Ben Langmuir | f3050d2 | 2014-06-27 17:04:26 +0000 | [diff] [blame] | 388 | auto Diag = clang_getDiagnostic(ClangTU, i); |
| 389 | DEBUG(llvm::dbgs() << clang_getCString(clang_formatDiagnostic( |
| 390 | Diag, clang_defaultDiagnosticDisplayOptions())) << "\n"); |
| 391 | clang_disposeDiagnostic(Diag); |
| 392 | } |
| 393 | } |
NAKAMURA Takumi | 6189422 | 2014-06-29 11:07:48 +0000 | [diff] [blame] | 394 | bool ReparseTU(unsigned num_unsaved_files, CXUnsavedFile* unsaved_files) { |
Ben Langmuir | f3050d2 | 2014-06-27 17:04:26 +0000 | [diff] [blame] | 395 | if (clang_reparseTranslationUnit(ClangTU, num_unsaved_files, unsaved_files, |
| 396 | clang_defaultReparseOptions(ClangTU))) { |
| 397 | DEBUG(llvm::dbgs() << "Reparse failed\n"); |
| 398 | return false; |
| 399 | } |
| 400 | DisplayDiagnostics(); |
| 401 | return true; |
| 402 | } |
| 403 | }; |
| 404 | |
| 405 | |
| 406 | TEST_F(LibclangReparseTest, Reparse) { |
| 407 | const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;"; |
| 408 | const char *HeaderBottom = "\n};\n#endif\n"; |
| 409 | const char *CppFile = "#include \"HeaderFile.h\"\nint main() {" |
| 410 | " Foo foo; foo.bar = 7; foo.baz = 8; }\n"; |
| 411 | std::string HeaderName = "HeaderFile.h"; |
| 412 | std::string CppName = "CppFile.cpp"; |
| 413 | WriteFile(CppName, CppFile); |
| 414 | WriteFile(HeaderName, std::string(HeaderTop) + HeaderBottom); |
| 415 | |
| 416 | ClangTU = clang_parseTranslationUnit(Index, CppName.c_str(), nullptr, 0, |
| 417 | nullptr, 0, TUFlags); |
| 418 | EXPECT_EQ(1U, clang_getNumDiagnostics(ClangTU)); |
| 419 | DisplayDiagnostics(); |
| 420 | |
| 421 | // Immedaitely reparse. |
| 422 | ASSERT_TRUE(ReparseTU(0, nullptr /* No unsaved files. */)); |
| 423 | EXPECT_EQ(1U, clang_getNumDiagnostics(ClangTU)); |
| 424 | |
| 425 | std::string NewHeaderContents = |
| 426 | std::string(HeaderTop) + "int baz;" + HeaderBottom; |
| 427 | WriteFile(HeaderName, NewHeaderContents); |
| 428 | |
| 429 | // Reparse after fix. |
| 430 | ASSERT_TRUE(ReparseTU(0, nullptr /* No unsaved files. */)); |
| 431 | EXPECT_EQ(0U, clang_getNumDiagnostics(ClangTU)); |
| 432 | } |
Ben Langmuir | 33c8090 | 2014-06-30 20:04:14 +0000 | [diff] [blame] | 433 | |
| 434 | TEST_F(LibclangReparseTest, ReparseWithModule) { |
| 435 | const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;"; |
| 436 | const char *HeaderBottom = "\n};\n#endif\n"; |
| 437 | const char *MFile = "#include \"HeaderFile.h\"\nint main() {" |
| 438 | " struct Foo foo; foo.bar = 7; foo.baz = 8; }\n"; |
| 439 | const char *ModFile = "module A { header \"HeaderFile.h\" }\n"; |
| 440 | std::string HeaderName = "HeaderFile.h"; |
| 441 | std::string MName = "MFile.m"; |
| 442 | std::string ModName = "module.modulemap"; |
| 443 | WriteFile(MName, MFile); |
| 444 | WriteFile(HeaderName, std::string(HeaderTop) + HeaderBottom); |
| 445 | WriteFile(ModName, ModFile); |
| 446 | |
Ben Langmuir | e218cd7 | 2014-07-07 17:34:37 +0000 | [diff] [blame] | 447 | std::string ModulesCache = std::string("-fmodules-cache-path=") + TestDir; |
| 448 | const char *Args[] = { "-fmodules", ModulesCache.c_str(), |
| 449 | "-I", TestDir.c_str() }; |
Ben Langmuir | 33c8090 | 2014-06-30 20:04:14 +0000 | [diff] [blame] | 450 | int NumArgs = sizeof(Args) / sizeof(Args[0]); |
| 451 | ClangTU = clang_parseTranslationUnit(Index, MName.c_str(), Args, NumArgs, |
| 452 | nullptr, 0, TUFlags); |
| 453 | EXPECT_EQ(1U, clang_getNumDiagnostics(ClangTU)); |
| 454 | DisplayDiagnostics(); |
| 455 | |
| 456 | // Immedaitely reparse. |
| 457 | ASSERT_TRUE(ReparseTU(0, nullptr /* No unsaved files. */)); |
| 458 | EXPECT_EQ(1U, clang_getNumDiagnostics(ClangTU)); |
| 459 | |
| 460 | std::string NewHeaderContents = |
| 461 | std::string(HeaderTop) + "int baz;" + HeaderBottom; |
| 462 | WriteFile(HeaderName, NewHeaderContents); |
| 463 | |
| 464 | // Reparse after fix. |
| 465 | ASSERT_TRUE(ReparseTU(0, nullptr /* No unsaved files. */)); |
| 466 | EXPECT_EQ(0U, clang_getNumDiagnostics(ClangTU)); |
| 467 | } |