diff --git a/plugins/clang/tests/test_duchain.cpp b/plugins/clang/tests/test_duchain.cpp --- a/plugins/clang/tests/test_duchain.cpp +++ b/plugins/clang/tests/test_duchain.cpp @@ -982,22 +982,32 @@ auto documentController = ICore::self()->documentController(); // open first document (no activation) - auto doc = documentController->openDocument(file1.url().toUrl(), KTextEditor::Range::invalid(), {IDocumentController::DoNotActivate}); - QVERIFY(doc); + auto doc1 = documentController->openDocument(file1.url().toUrl(), KTextEditor::Range::invalid(), {IDocumentController::DoNotActivate}); + QVERIFY(doc1); QVERIFY(backgroundParser->isQueued(file1.url())); QCOMPARE(backgroundParser->priorityForDocument(file1.url()), (int)BackgroundParser::NormalPriority); // open second document, activate - doc = documentController->openDocument(file2.url().toUrl()); - QVERIFY(doc); + auto doc2 = documentController->openDocument(file2.url().toUrl()); + QVERIFY(doc2); QVERIFY(backgroundParser->isQueued(file2.url())); QCOMPARE(backgroundParser->priorityForDocument(file2.url()), (int)BackgroundParser::BestPriority); // open third document, activate, too - doc = documentController->openDocument(file3.url().toUrl()); - QVERIFY(doc); + auto doc3 = documentController->openDocument(file3.url().toUrl()); + QVERIFY(doc3); QVERIFY(backgroundParser->isQueued(file3.url())); QCOMPARE(backgroundParser->priorityForDocument(file3.url()), (int)BackgroundParser::BestPriority); + + // Wait for the parsing to finish to avoid errors like "error: error reading '/tmp/testfile_SD1554.cpp'" + // due to the TestFiles getting removed. + file1.parseAndWait(); + file2.parseAndWait(); + file3.parseAndWait(); + + doc1->close(KDevelop::IDocument::Discard); + doc2->close(KDevelop::IDocument::Discard); + doc3->close(KDevelop::IDocument::Discard); } void TestDUChain::testSystemIncludes()