From 8d5e9c3636097c5115111a9e2b23c913d0c30f8e Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Thu, 20 May 2021 09:45:50 +0200 Subject: [PATCH] CMakePM: Fix running selected ctests Do not use a pattern to address tests when running selected. Instead get their respective test number and use this. This avoids executing unchecked test cases that match a shorter selected one. Beside this it shortens the commandline which might be also a benefit on Windows. Change-Id: Ic1c0cf8eedab478564f04fb494679eca4521f402 Reviewed-by: David Schulz --- .../cmakeprojectmanager/cmakebuildsystem.cpp | 18 +++++++++++------- src/plugins/projectexplorer/buildsystem.h | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp index eafbe2c9f23..d0b3db53009 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp @@ -70,7 +70,6 @@ #include #include #include -#include using namespace ProjectExplorer; using namespace Utils; @@ -994,7 +993,9 @@ void CMakeBuildSystem::runCTest() const QJsonArray cmakelists = btGraph.value("files").toArray(); const QJsonArray nodes = btGraph.value("nodes").toArray(); const QJsonArray tests = jsonObj.value("tests").toArray(); + int counter = 0; for (const QJsonValue &testVal : tests) { + ++counter; const QJsonObject test = testVal.toObject(); QTC_ASSERT(!test.isEmpty(), continue); const int bt = test.value("backtrace").toInt(-1); @@ -1003,7 +1004,7 @@ void CMakeBuildSystem::runCTest() int file = btRef.value("file").toInt(-1); int line = btRef.value("line").toInt(-1); QTC_ASSERT(file != -1 && line != -1, continue); - m_testNames.append({ test.value("name").toString(), + m_testNames.append({ test.value("name").toString(), counter, FilePath::fromString(cmakelists.at(file).toString()), line }); } } @@ -1109,14 +1110,17 @@ CommandLine CMakeBuildSystem::commandLineForTests(const QList &tests, const QStringList &options) const { QStringList args = options; + const QSet testsSet = Utils::toSet(tests); auto current = Utils::transform>(m_testNames, &TestCaseInfo::name); - if (tests.isEmpty() || current == Utils::toSet(tests)) + if (tests.isEmpty() || current == testsSet) return {m_ctestPath, args}; - const QString regex = Utils::transform(tests, [](const QString ¤t) { - return QRegularExpression::escape(current); - }).join('|'); - args << "-R" << QString('(' + regex + ')'); + QString testNumbers("0,0,0"); // start, end, stride + for (const TestCaseInfo &info : m_testNames) { + if (testsSet.contains(info.name)) + testNumbers += QString(",%1").arg(info.number); + } + args << "-I" << testNumbers; return {m_ctestPath, args}; } diff --git a/src/plugins/projectexplorer/buildsystem.h b/src/plugins/projectexplorer/buildsystem.h index bedaa7d5ee5..de610811cf8 100644 --- a/src/plugins/projectexplorer/buildsystem.h +++ b/src/plugins/projectexplorer/buildsystem.h @@ -45,6 +45,7 @@ class Node; struct TestCaseInfo { QString name; + int number = -1; Utils::FilePath path; int line = 0; };