From f80aa2c6f7b85de4bbe050fb96bd6852908f3e58 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Tue, 10 Jul 2018 14:47:40 +0200 Subject: [PATCH] AutoTest: Fix handling of cpp files for Quick tests Modifying C++ files of Quick tests had been ignored as they normally have little impact. But nevertheless this behavior is wrong and could lead to unexpected behavior later on if no complete rescan had been done and even with a rescan there could have been some cached artifacts. Fix this by tracking the paths of the C++ files that hold the main() or the respective macro to be able to handle changes of these files correctly as well. Task-number: QTCREATORBUG-20746 Change-Id: Iec860aa63ffd167511efdbf63a6ffa369f094edf Reviewed-by: David Schulz --- .../autotest/quick/quicktestparser.cpp | 24 ++++++++++++++++--- src/plugins/autotest/quick/quicktestparser.h | 4 +++- .../autotest/quick/quicktesttreeitem.cpp | 18 ++++++++++++++ .../autotest/quick/quicktesttreeitem.h | 1 + 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/plugins/autotest/quick/quicktestparser.cpp b/src/plugins/autotest/quick/quicktestparser.cpp index 73e6ed3080a..91c1bfb36e9 100644 --- a/src/plugins/autotest/quick/quicktestparser.cpp +++ b/src/plugins/autotest/quick/quicktestparser.cpp @@ -212,7 +212,7 @@ static bool checkQmlDocumentForQuickTestCode(QFutureInterface futureInterface, CPlusPlus::Document::Ptr document, - const Core::Id &id) const + const Core::Id &id) { const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance(); if (quickTestName(document).isEmpty()) @@ -223,7 +223,7 @@ bool QuickTestParser::handleQtQuickTest(QFutureInterface fut if (ppList.isEmpty()) // happens if shutting down while parsing return false; const QString &proFile = ppList.at(0)->projectFile; - + m_mainCppFiles.insert(cppFileName, proFile); const QString srcDir = quickTestSrcDir(modelManager, cppFileName); if (srcDir.isEmpty()) return false; @@ -306,8 +306,21 @@ QuickTestParser::~QuickTestParser() void QuickTestParser::init(const QStringList &filesToParse, bool fullParse) { m_qmlSnapshot = QmlJSTools::Internal::ModelManager::instance()->snapshot(); - if (!fullParse) // in a full parse we get the correct entry points by the respective main + if (!fullParse) { + // in a full parse we get the correct entry points by the respective main m_proFilesForQmlFiles = QuickTestUtils::proFilesForQmlFiles(id(), filesToParse); + // get rid of cached main cpp files that are going to get processed anyhow + for (const QString &file : filesToParse) { + if (m_mainCppFiles.contains(file)) { + m_mainCppFiles.remove(file); + if (m_mainCppFiles.isEmpty()) + break; + } + } + } else { + // get rid of all cached main cpp files + m_mainCppFiles.clear(); + } CppParser::init(filesToParse, fullParse); } @@ -336,5 +349,10 @@ bool QuickTestParser::processDocument(QFutureInterface futur return handleQtQuickTest(futureInterface, document, id()); } +QString QuickTestParser::projectFileForMainCppFile(const QString &fileName) const +{ + return m_mainCppFiles.contains(fileName) ? m_mainCppFiles.value(fileName) : QString(); +} + } // namespace Internal } // namespace Autotest diff --git a/src/plugins/autotest/quick/quicktestparser.h b/src/plugins/autotest/quick/quicktestparser.h index 94d0640fc06..6d005bec4e9 100644 --- a/src/plugins/autotest/quick/quicktestparser.h +++ b/src/plugins/autotest/quick/quicktestparser.h @@ -51,11 +51,12 @@ public: void release() override; bool processDocument(QFutureInterface futureInterface, const QString &fileName) override; + QString projectFileForMainCppFile(const QString &fileName) const; signals: void updateWatchPaths(const QStringList &directories) const; private: bool handleQtQuickTest(QFutureInterface futureInterface, - CPlusPlus::Document::Ptr document, const Core::Id &id) const; + CPlusPlus::Document::Ptr document, const Core::Id &id); void handleDirectoryChanged(const QString &directory); void doUpdateWatchPaths(const QStringList &directories); QList scanDirectoryForQuickTestQmlFiles(const QString &srcDir) const; @@ -63,6 +64,7 @@ private: QHash m_proFilesForQmlFiles; QFileSystemWatcher m_directoryWatcher; QMap > m_watchedFiles; + QMap m_mainCppFiles; }; } // namespace Internal diff --git a/src/plugins/autotest/quick/quicktesttreeitem.cpp b/src/plugins/autotest/quick/quicktesttreeitem.cpp index dc17be469b7..227c56410fe 100644 --- a/src/plugins/autotest/quick/quicktesttreeitem.cpp +++ b/src/plugins/autotest/quick/quicktesttreeitem.cpp @@ -25,6 +25,7 @@ #include "quicktesttreeitem.h" #include "quicktestconfiguration.h" +#include "quicktestframework.h" #include "quicktestparser.h" #include "../testframeworkmanager.h" @@ -426,6 +427,23 @@ QSet QuickTestTreeItem::internalTargets() const return result; } +void QuickTestTreeItem::markForRemovalRecursively(const QString &filePath) +{ + static const Core::Id id = Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix( + QuickTest::Constants::FRAMEWORK_NAME); + TestTreeItem::markForRemovalRecursively(filePath); + auto parser = dynamic_cast(TestFrameworkManager::instance() + ->testParserForTestFramework(id)); + const QString proFile = parser->projectFileForMainCppFile(filePath); + if (!proFile.isEmpty()) { + TestTreeItem *root = TestFrameworkManager::instance()->rootNodeForTestFramework(id); + root->forAllChildren([proFile](TestTreeItem *it) { + if (it->proFile() == proFile) + it->markForRemoval(true); + }); + } +} + TestTreeItem *QuickTestTreeItem::unnamedQuickTests() const { if (type() != Root) diff --git a/src/plugins/autotest/quick/quicktesttreeitem.h b/src/plugins/autotest/quick/quicktesttreeitem.h index e00afc434b2..97c287f38f2 100644 --- a/src/plugins/autotest/quick/quicktesttreeitem.h +++ b/src/plugins/autotest/quick/quicktesttreeitem.h @@ -54,6 +54,7 @@ public: bool removeOnSweepIfEmpty() const override; TestTreeItem *createParentGroupNode() const override; QSet internalTargets() const override; + void markForRemovalRecursively(const QString &filePath) override; private: TestTreeItem *unnamedQuickTests() const; };