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 <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2021-05-20 09:45:50 +02:00
parent 61a3457729
commit 8d5e9c3636
2 changed files with 12 additions and 7 deletions

View File

@@ -70,7 +70,6 @@
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QRegularExpression>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
@@ -994,7 +993,9 @@ void CMakeBuildSystem::runCTest()
const QJsonArray cmakelists = btGraph.value("files").toArray(); const QJsonArray cmakelists = btGraph.value("files").toArray();
const QJsonArray nodes = btGraph.value("nodes").toArray(); const QJsonArray nodes = btGraph.value("nodes").toArray();
const QJsonArray tests = jsonObj.value("tests").toArray(); const QJsonArray tests = jsonObj.value("tests").toArray();
int counter = 0;
for (const QJsonValue &testVal : tests) { for (const QJsonValue &testVal : tests) {
++counter;
const QJsonObject test = testVal.toObject(); const QJsonObject test = testVal.toObject();
QTC_ASSERT(!test.isEmpty(), continue); QTC_ASSERT(!test.isEmpty(), continue);
const int bt = test.value("backtrace").toInt(-1); const int bt = test.value("backtrace").toInt(-1);
@@ -1003,7 +1004,7 @@ void CMakeBuildSystem::runCTest()
int file = btRef.value("file").toInt(-1); int file = btRef.value("file").toInt(-1);
int line = btRef.value("line").toInt(-1); int line = btRef.value("line").toInt(-1);
QTC_ASSERT(file != -1 && line != -1, continue); 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 }); FilePath::fromString(cmakelists.at(file).toString()), line });
} }
} }
@@ -1109,14 +1110,17 @@ CommandLine CMakeBuildSystem::commandLineForTests(const QList<QString> &tests,
const QStringList &options) const const QStringList &options) const
{ {
QStringList args = options; QStringList args = options;
const QSet<QString> testsSet = Utils::toSet(tests);
auto current = Utils::transform<QSet<QString>>(m_testNames, &TestCaseInfo::name); auto current = Utils::transform<QSet<QString>>(m_testNames, &TestCaseInfo::name);
if (tests.isEmpty() || current == Utils::toSet(tests)) if (tests.isEmpty() || current == testsSet)
return {m_ctestPath, args}; return {m_ctestPath, args};
const QString regex = Utils::transform(tests, [](const QString &current) { QString testNumbers("0,0,0"); // start, end, stride
return QRegularExpression::escape(current); for (const TestCaseInfo &info : m_testNames) {
}).join('|'); if (testsSet.contains(info.name))
args << "-R" << QString('(' + regex + ')'); testNumbers += QString(",%1").arg(info.number);
}
args << "-I" << testNumbers;
return {m_ctestPath, args}; return {m_ctestPath, args};
} }

View File

@@ -45,6 +45,7 @@ class Node;
struct TestCaseInfo struct TestCaseInfo
{ {
QString name; QString name;
int number = -1;
Utils::FilePath path; Utils::FilePath path;
int line = 0; int line = 0;
}; };