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

Method testMoveIntoSource

plugins/clang/tests/test_assistants.cpp:638–685  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

636}
637
638void TestAssistants::testMoveIntoSource()
639{
640 QFETCH(QString, origHeader);
641 QFETCH(QString, origImpl);
642 QFETCH(QString, newHeader);
643 QFETCH(QString, newImpl);
644 QFETCH(QualifiedIdentifier, id);
645
646 TestFile header(origHeader, QStringLiteral("h"));
647 TestFile impl("#include \"" + header.url().byteArray() + "\"\n" + origImpl, QStringLiteral("cpp"), &header);
648
649 {
650 TopDUContext* headerCtx = nullptr;
651 {
652 DUChainReadLocker lock;
653 headerCtx = DUChain::self()->chainForDocument(header.url());
654 }
655 // Here is a problem: when launching tests one by one, we can reuse the same tmp file for headers.
656 // But because of document chain for header wasn't unloaded properly in previous run we reuse it here
657 // Therefore when using headerCtx->findDeclarations below we find declarations from the previous launch -> tests fail
658 if (headerCtx) {
659 // TODO: Investigate why this chain doesn't get updated when parsing source file
660 DUChainWriteLocker lock;
661 DUChain::self()->removeDocumentChain(headerCtx);
662 }
663 }
664
665 impl.parse(KDevelop::TopDUContext::AllDeclarationsContextsAndUses);
666 QVERIFY(impl.waitForParsed());
667
668 IndexedDeclaration declaration;
669 {
670 DUChainReadLocker lock;
671 auto headerCtx = DUChain::self()->chainForDocument(header.url());
672 QVERIFY(headerCtx);
673 auto decls = headerCtx->findDeclarations(id);
674 Q_ASSERT(!decls.isEmpty());
675 declaration = IndexedDeclaration(decls.first());
676 QVERIFY(declaration.isValid());
677 }
678 CodeRepresentation::setDiskChangesForbidden(false);
679 ClangRefactoring refactoring;
680 QCOMPARE(refactoring.moveIntoSource(declaration), QString());
681 CodeRepresentation::setDiskChangesForbidden(true);
682
683 QCOMPARE(header.fileContents(), newHeader);
684 QVERIFY(impl.fileContents().endsWith(newImpl));
685}
686
687void TestAssistants::testMoveIntoSource_data()
688{

Callers

nothing calls this directly

Calls 15

byteArrayMethod · 0.80
chainForDocumentMethod · 0.80
removeDocumentChainMethod · 0.80
waitForParsedMethod · 0.80
findDeclarationsMethod · 0.80
moveIntoSourceMethod · 0.80
fileContentsMethod · 0.80
endsWithMethod · 0.80
IndexedDeclarationClass · 0.50
QStringClass · 0.50
urlMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected