AutoTest: Widen scope for run under cursor

..and debug under cursor for QtTest and GTest.

Depending on the information coming from the code model
we may be able to get a correct scope even when standing
inside the function that is defining the test.
This makes more sense than the original behavior which
made it a hard requirement to stand on a literal to
run or debug a test under cursor.
But as the codemodel does not provide usable information
for all frameworks keep the original behavior as fallback.

Task-number: QTCREATORBUG-28752
Change-Id: I13ea7b0ad1e8207da6cb884d212667c4c657957c
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2023-02-06 16:25:50 +01:00
parent 9277bb5111
commit d2656c60e6
9 changed files with 125 additions and 16 deletions

View File

@@ -271,6 +271,48 @@ TestTreeItem *TestTreeItem::findChildByNameAndFile(const QString &name, const Fi
});
}
static TestTreeItem *findMatchingTestAt(TestTreeItem *parent, const QStringList &testName,
const FilePath &filePath)
{
const QString &first = testName.first();
const QString &last = testName.last();
for (int i = 0, iEnd = parent->childCount(); i < iEnd; ++i) {
auto it = parent->childItem(i);
if (it->name() != first)
continue;
for (int j = 0, jEnd = it->childCount(); j < jEnd; ++j) {
auto grandchild = it->childItem(j);
if (grandchild->name() != last)
continue;
if (it->filePath() == filePath || grandchild->filePath() == filePath)
return grandchild;
}
}
return nullptr;
}
TestTreeItem *TestTreeItem::findTestByNameAndFile(const QStringList &testName,
const FilePath &filePath)
{
QTC_ASSERT(type() == Root, return nullptr);
QTC_ASSERT(testName.size() == 2, return nullptr);
if (!childCount())
return nullptr;
if (childAt(0)->type() != GroupNode) // process root's children directly
return findMatchingTestAt(this, testName, filePath);
// process children of groups instead of root
for (int i = 0, end = childCount(); i < end; ++i) {
if (TestTreeItem *found = findMatchingTestAt(childItem(i), testName, filePath))
return found;
}
return nullptr;
}
ITestConfiguration *TestTreeItem::asConfiguration(TestRunMode mode) const
{
switch (mode) {