From dba75f3d2cadbaf4e602555861e88d994f5a7805 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 21 Sep 2020 17:12:20 +0200 Subject: [PATCH] AutoTest: Improve matching test results to tree item ...when using Boost UTF. We need to take parameterized and templated tests into account differently and we may have results that do not provide file information at all, so try to find a matching tree item from what we have got. Change-Id: Ia0b1894d5dd729d39e5724d9fdeadd574a9cfde5 Reviewed-by: Christian Stenger Reviewed-by: David Schulz --- .../autotest/boost/boosttestoutputreader.cpp | 4 +++ .../autotest/boost/boosttestresult.cpp | 30 ++++++++++++------- .../autotest/boost/boosttesttreeitem.cpp | 6 ++-- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/plugins/autotest/boost/boosttestoutputreader.cpp b/src/plugins/autotest/boost/boosttestoutputreader.cpp index 84cd3e45a08..a21891f4cce 100644 --- a/src/plugins/autotest/boost/boosttestoutputreader.cpp +++ b/src/plugins/autotest/boost/boosttestoutputreader.cpp @@ -26,6 +26,7 @@ #include "boosttestoutputreader.h" #include "boosttestsettings.h" #include "boosttestresult.h" +#include "boosttesttreeitem.h" #include @@ -107,6 +108,9 @@ void BoostTestOutputReader::sendCompleteInformation() if (m_lineNumber) { result->setLine(m_lineNumber); result->setFileName(m_fileName); + } else if (const TestTreeItem *it = result->findTestTreeItem()) { + result->setLine(it->line()); + result->setFileName(it->filePath()); } result->setDescription(m_description); diff --git a/src/plugins/autotest/boost/boosttestresult.cpp b/src/plugins/autotest/boost/boosttestresult.cpp index ba21b0851b2..470d01047c4 100644 --- a/src/plugins/autotest/boost/boosttestresult.cpp +++ b/src/plugins/autotest/boost/boosttestresult.cpp @@ -85,10 +85,10 @@ const TestTreeItem *BoostTestResult::findTestTreeItem() const if (!rootNode) return nullptr; - const auto item = rootNode->findAnyChild([this](const Utils::TreeItem *item) { + const auto foundItem = rootNode->findAnyChild([this](const Utils::TreeItem *item) { return matches(static_cast(item)); }); - return static_cast(item); + return static_cast(foundItem); } bool BoostTestResult::matches(const BoostTestTreeItem *item) const @@ -99,16 +99,26 @@ bool BoostTestResult::matches(const BoostTestTreeItem *item) const return false; if (m_testCase.isEmpty()) // a top level module node return item->proFile() == m_projectFile; + if (item->proFile() != m_projectFile) + return false; + if (!fileName().isEmpty() && fileName() != item->filePath()) + return false; - if (item->state() & BoostTestTreeItem::Parameterized) { - if (!m_testCase.startsWith(item->name())) - return false; - } else { - if (item->name() != m_testCase) - return false; + QString fullName = "::" + m_testCase; + fullName.prepend(m_testSuite.isEmpty() ? QString(BoostTest::Constants::BOOST_MASTER_SUITE) + : m_testSuite); + + BoostTestTreeItem::TestStates states = item->state(); + if (states & BoostTestTreeItem::Templated) { + const QRegularExpression regex( + QRegularExpression::wildcardToRegularExpression(item->fullName() + "<*>")); + return regex.match(fullName).hasMatch(); + } else if (states & BoostTestTreeItem::Parameterized) { + const QRegularExpression regex( + QRegularExpression::anchoredPattern(item->fullName() + "_\\d+")); + return regex.isValid() && regex.match(fullName).hasMatch(); } - - return item->filePath() == fileName() && item->proFile() == m_projectFile; + return item->fullName() == fullName; } } // namespace Internal diff --git a/src/plugins/autotest/boost/boosttesttreeitem.cpp b/src/plugins/autotest/boost/boosttesttreeitem.cpp index 67c798369ee..5d6a9092c4f 100644 --- a/src/plugins/autotest/boost/boosttesttreeitem.cpp +++ b/src/plugins/autotest/boost/boosttesttreeitem.cpp @@ -240,7 +240,7 @@ QList BoostTestTreeItem::getTestConfigurations( if (item->state().testFlag(BoostTestTreeItem::Templated)) tcName.append("<*"); else if (item->state().testFlag(BoostTestTreeItem::Parameterized)) - tcName.append('*'); + tcName.append("_*"); tcName = handleSpecialFunctionNames(tcName); testCasesForProjectFile[item->proFile()].testCases.append( item->prependWithParentsSuitePaths(tcName)); @@ -293,7 +293,7 @@ TestConfiguration *BoostTestTreeItem::testConfiguration() const if (boostItem->type() == TestSuite) // execute everything below a suite tcName.append("/*"); else if (boostItem->state().testFlag(BoostTestTreeItem::Parameterized)) - tcName.append('*'); + tcName.append("_*"); else if (boostItem->state().testFlag(BoostTestTreeItem::Templated)) tcName.append("<*"); testCases.append(boostItem->prependWithParentsSuitePaths(tcName)); @@ -305,7 +305,7 @@ TestConfiguration *BoostTestTreeItem::testConfiguration() const if (state().testFlag(BoostTestTreeItem::Templated)) tcName.append("<*"); else if (state().testFlag(BoostTestTreeItem::Parameterized)) - tcName.append('*'); + tcName.append("_*"); testCases.append(prependWithParentsSuitePaths(handleSpecialFunctionNames(tcName))); }