From 4f50b6b791e1988bfb10f113baf0d94cc7e046cb Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 10 Jul 2023 12:59:00 +0200 Subject: [PATCH] AutoTest: Postpone removal of root node If a root node should get removed while scanning we may end up crashing when still getting results. As there is currently no mechanism to stop a certain parser postpone the removal of the root node until the parsing is done. Change-Id: I3766f9e67780e241801166339fa67f39536314b4 Reviewed-by: Marcus Tillmanns --- src/plugins/autotest/testprojectsettings.cpp | 6 +++++- src/plugins/autotest/testtreeitem.cpp | 11 ++++++++--- src/plugins/autotest/testtreeitem.h | 1 + src/plugins/autotest/testtreemodel.cpp | 4 ++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/plugins/autotest/testprojectsettings.cpp b/src/plugins/autotest/testprojectsettings.cpp index 5f745637db8..dd0c05079cc 100644 --- a/src/plugins/autotest/testprojectsettings.cpp +++ b/src/plugins/autotest/testprojectsettings.cpp @@ -4,7 +4,9 @@ #include "testprojectsettings.h" #include "autotestconstants.h" +#include "testcodeparser.h" #include "testframeworkmanager.h" +#include "testtreemodel.h" #include #include @@ -49,7 +51,9 @@ void TestProjectSettings::activateFramework(const Id &id, bool activate) { ITestFramework *framework = TestFrameworkManager::frameworkForId(id); m_activeTestFrameworks[framework] = activate; - if (!activate) + if (TestTreeModel::instance()->parser()->isParsing()) + framework->rootNode()->markForRemoval(!activate); + else if (!activate) framework->resetRootNode(); } diff --git a/src/plugins/autotest/testtreeitem.cpp b/src/plugins/autotest/testtreeitem.cpp index f18adb812d4..69481b60cad 100644 --- a/src/plugins/autotest/testtreeitem.cpp +++ b/src/plugins/autotest/testtreeitem.cpp @@ -214,12 +214,16 @@ bool TestTreeItem::modifyLineAndColumn(const TestParseResult *result) void TestTreeItem::markForRemoval(bool mark) { - m_status = mark ? MarkedForRemoval : Cleared; + if (type() == Root) + m_status = mark ? ForcedRootRemoval : NewlyAdded; + else + m_status = mark ? MarkedForRemoval : Cleared; } void TestTreeItem::markForRemovalRecursively(bool mark) { - markForRemoval(mark); + if (type() != Root) + markForRemoval(mark); for (int row = 0, count = childCount(); row < count; ++row) childItem(row)->markForRemovalRecursively(mark); } @@ -231,7 +235,8 @@ void TestTreeItem::markForRemovalRecursively(const QSet &filePaths) child->markForRemovalRecursively(filePaths); mark &= child->markedForRemoval(); }); - markForRemoval(mark); + if (type() != Root) + markForRemoval(mark); } TestTreeItem *TestTreeItem::childItem(int at) const diff --git a/src/plugins/autotest/testtreeitem.h b/src/plugins/autotest/testtreeitem.h index 3737d2a3607..4f4065c62d8 100644 --- a/src/plugins/autotest/testtreeitem.h +++ b/src/plugins/autotest/testtreeitem.h @@ -167,6 +167,7 @@ private: { NewlyAdded, MarkedForRemoval, + ForcedRootRemoval, // only valid on rootNode Cleared }; diff --git a/src/plugins/autotest/testtreemodel.cpp b/src/plugins/autotest/testtreemodel.cpp index 5e7fcb85a86..7d0dd3954d0 100644 --- a/src/plugins/autotest/testtreemodel.cpp +++ b/src/plugins/autotest/testtreemodel.cpp @@ -485,6 +485,10 @@ void TestTreeModel::markForRemoval(const QSet &filePaths) void TestTreeModel::sweep() { for (TestTreeItem *frameworkRoot : frameworkRootNodes()) { + if (frameworkRoot->m_status == TestTreeItem::ForcedRootRemoval) { + frameworkRoot->framework()->resetRootNode(); + continue; + } sweepChildren(frameworkRoot); revalidateCheckState(frameworkRoot); }