diff options
author | Christian Stenger <christian.stenger@qt.io> | 2018-07-10 14:47:40 +0200 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2018-07-11 13:18:04 +0000 |
commit | f80aa2c6f7b85de4bbe050fb96bd6852908f3e58 (patch) | |
tree | d0b0a274725433779f8cb0cb2fa354f8a21ac0f4 | |
parent | f18d2ded9b6febef0d9c47b03e1a00f4fc526ddc (diff) |
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 <david.schulz@qt.io>
-rw-r--r-- | src/plugins/autotest/quick/quicktestparser.cpp | 24 | ||||
-rw-r--r-- | src/plugins/autotest/quick/quicktestparser.h | 4 | ||||
-rw-r--r-- | src/plugins/autotest/quick/quicktesttreeitem.cpp | 18 | ||||
-rw-r--r-- | src/plugins/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 73e6ed3080..91c1bfb36e 100644 --- a/src/plugins/autotest/quick/quicktestparser.cpp +++ b/src/plugins/autotest/quick/quicktestparser.cpp @@ -212,7 +212,7 @@ static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr bool QuickTestParser::handleQtQuickTest(QFutureInterface<TestParseResultPtr> 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<TestParseResultPtr> 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<TestParseResultPtr> 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 94d0640fc0..6d005bec4e 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<TestParseResultPtr> futureInterface, const QString &fileName) override; + QString projectFileForMainCppFile(const QString &fileName) const; signals: void updateWatchPaths(const QStringList &directories) const; private: bool handleQtQuickTest(QFutureInterface<TestParseResultPtr> 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<QmlJS::Document::Ptr> scanDirectoryForQuickTestQmlFiles(const QString &srcDir) const; @@ -63,6 +64,7 @@ private: QHash<QString, QString> m_proFilesForQmlFiles; QFileSystemWatcher m_directoryWatcher; QMap<QString, QMap<QString, QDateTime> > m_watchedFiles; + QMap<QString, QString> m_mainCppFiles; }; } // namespace Internal diff --git a/src/plugins/autotest/quick/quicktesttreeitem.cpp b/src/plugins/autotest/quick/quicktesttreeitem.cpp index dc17be469b..227c56410f 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<QString> 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<QuickTestParser *>(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 e00afc434b..97c287f38f 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<QString> internalTargets() const override; + void markForRemovalRecursively(const QString &filePath) override; private: TestTreeItem *unnamedQuickTests() const; }; |