| 337 | } |
| 338 | |
| 339 | void TestDUChain::testMissingInclude() |
| 340 | { |
| 341 | auto code = R"( |
| 342 | #pragma once |
| 343 | #include "missing1.h" |
| 344 | |
| 345 | template<class T> |
| 346 | class A |
| 347 | { |
| 348 | T a; |
| 349 | }; |
| 350 | |
| 351 | #include "missing2.h" |
| 352 | |
| 353 | class B : public A<int> |
| 354 | { |
| 355 | }; |
| 356 | )"; |
| 357 | |
| 358 | TestFile header(code, QStringLiteral("h")); |
| 359 | TestFile impl("#include \"" + header.url().str() + "\"\n", QStringLiteral("cpp"), &header); |
| 360 | QVERIFY(impl.parseAndWait(TopDUContext::AllDeclarationsContextsAndUses)); |
| 361 | |
| 362 | DUChainReadLocker lock; |
| 363 | |
| 364 | auto top = impl.topContext(); |
| 365 | QVERIFY(top); |
| 366 | |
| 367 | QCOMPARE(top->importedParentContexts().count(), 1); |
| 368 | |
| 369 | TopDUContext* headerCtx = dynamic_cast<TopDUContext*>(top->importedParentContexts().first().context(top)); |
| 370 | QVERIFY(headerCtx); |
| 371 | QCOMPARE(headerCtx->url(), header.url()); |
| 372 | |
| 373 | #if CINDEX_VERSION_MINOR < 34 |
| 374 | QEXPECT_FAIL("", "Second missing header isn't reported", Continue); |
| 375 | #endif |
| 376 | QCOMPARE(headerCtx->problems().count(), 2); |
| 377 | |
| 378 | QCOMPARE(headerCtx->localDeclarations().count(), 2); |
| 379 | |
| 380 | auto a = dynamic_cast<ClassDeclaration*>(headerCtx->localDeclarations().first()); |
| 381 | QVERIFY(a); |
| 382 | |
| 383 | auto b = dynamic_cast<ClassDeclaration*>(headerCtx->localDeclarations().last()); |
| 384 | QVERIFY(b); |
| 385 | |
| 386 | // NOTE: This fails and needs fixing. If the include of "missing2.h" |
| 387 | // above is commented out, then it doesn't fail. Maybe |
| 388 | // clang stops processing when it encounters the second missing |
| 389 | // header, or similar. |
| 390 | // XFAIL this check until https://bugs.llvm.org/show_bug.cgi?id=38155 is fixed |
| 391 | if (QVersionNumber::fromString(ClangHelpers::clangVersion()) < QVersionNumber(9, 0, 0)) |
| 392 | QEXPECT_FAIL("", "Base class isn't assigned correctly", Continue); |
| 393 | QCOMPARE(b->baseClassesSize(), 1u); |
| 394 | |
| 395 | #if CINDEX_VERSION_MINOR < 34 |
| 396 | // at least the one problem we have should have been propagated |
nothing calls this directly
no test coverage detected