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

Method testReparseChangeEnvironment

plugins/clang/tests/test_duchain.cpp:1222–1263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1220}
1221
1222void TestDUChain::testReparseChangeEnvironment()
1223{
1224 TestFile header(QStringLiteral("int foo() { return 42; }\n"), QStringLiteral("h"));
1225 TestFile impl("#include \"" + header.url().str() + "\"\n"
1226 "int main() { return foo(); }", QStringLiteral("cpp"), &header);
1227
1228 uint hashes[3] = {0, 0, 0};
1229
1230 for (int i = 0; i < 3; ++i) {
1231 impl.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST | TopDUContext::ForceUpdate);
1232 QVERIFY(impl.waitForParsed(5000));
1233
1234 {
1235 DUChainReadLocker lock;
1236 QVERIFY(impl.topContext());
1237 auto env = dynamic_cast<ClangParsingEnvironmentFile*>(impl.topContext()->parsingEnvironmentFile().data());
1238 QVERIFY(env);
1239 QCOMPARE(env->environmentQuality(), ClangParsingEnvironment::Source);
1240 hashes[i] = env->environmentHash();
1241 QVERIFY(hashes[i]);
1242
1243 // we should never end up with multiple env files or chains in memory for these files
1244 QCOMPARE(DUChain::self()->allEnvironmentFiles(impl.url()).size(), 1);
1245 QCOMPARE(DUChain::self()->chainsForDocument(impl.url()).size(), 1);
1246 QCOMPARE(DUChain::self()->allEnvironmentFiles(header.url()).size(), 1);
1247 QCOMPARE(DUChain::self()->chainsForDocument(header.url()).size(), 1);
1248 }
1249
1250 // in every run, we expect the environment to have changed
1251 for (int j = 0; j < i; ++j) {
1252 QVERIFY(hashes[i] != hashes[j]);
1253 }
1254
1255 if (i == 0) {
1256 // 1) change defines
1257 m_provider->defines.insert(QStringLiteral("foooooooo"), QStringLiteral("baaar!"));
1258 } else if (i == 1) {
1259 // 2) change includes
1260 m_provider->includes.append(Path(QStringLiteral("/foo/bar/asdf/lalala")));
1261 } // 3) stop
1262 }
1263}
1264
1265void TestDUChain::testMacroDependentHeader()
1266{

Callers

nothing calls this directly

Calls 15

strMethod · 0.80
waitForParsedMethod · 0.80
environmentQualityMethod · 0.80
environmentHashMethod · 0.80
allEnvironmentFilesMethod · 0.80
chainsForDocumentMethod · 0.80
PathClass · 0.50
urlMethod · 0.45
parseMethod · 0.45
topContextMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected