MCPcopy Create free account
hub / github.com/KDE/kdevelop / testMissingInclude

Method testMissingInclude

plugins/clang/tests/test_duchain.cpp:339–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337}
338
339void TestDUChain::testMissingInclude()
340{
341 auto code = R"(
342#pragma once
343#include "missing1.h"
344
345template<class T>
346class A
347{
348 T a;
349};
350
351#include "missing2.h"
352
353class 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

Callers

nothing calls this directly

Calls 12

strMethod · 0.80
parseAndWaitMethod · 0.80
localDeclarationsMethod · 0.80
baseClassesSizeMethod · 0.80
urlMethod · 0.45
topContextMethod · 0.45
countMethod · 0.45
contextMethod · 0.45
firstMethod · 0.45
problemsMethod · 0.45
lastMethod · 0.45

Tested by

no test coverage detected