forked from qt-creator/qt-creator
AutoTest: Fix running test cases with grouping
When gathering information for running tests we need to
take the grouping into account if enabled.
This patch amends 4eabcda3a1.
Task-number: QTCREATORBUG-17979
Change-Id: I27c17a5de8596c95f3b207530560d2a7c2cb5e99
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -153,6 +153,43 @@ TestConfiguration *QuickTestTreeItem::testConfiguration() const
|
||||
return config;
|
||||
}
|
||||
|
||||
static void testConfigurationFromCheckState(const TestTreeItem *item,
|
||||
QHash<QString, QuickTestConfiguration *> &foundProFiles)
|
||||
{
|
||||
QTC_ASSERT(item, return);
|
||||
if (item->type() == TestTreeItem::GroupNode) {
|
||||
for (int row = 0, count = item->childCount(); row < count; ++row)
|
||||
testConfigurationFromCheckState(item->childItem(row), foundProFiles);
|
||||
return;
|
||||
}
|
||||
QTC_ASSERT(item->type() == TestTreeItem::TestCase, return);
|
||||
QuickTestConfiguration *tc = nullptr;
|
||||
if (item->checked() == Qt::Unchecked)
|
||||
return;
|
||||
|
||||
QStringList testFunctions;
|
||||
const int childCount = item->childCount();
|
||||
for (int childRow = 0; childRow < childCount; ++childRow) {
|
||||
const TestTreeItem *child = item->childItem(childRow);
|
||||
if (child->checked() != Qt::Checked || child->type() != TestTreeItem::TestFunctionOrSet)
|
||||
continue;
|
||||
testFunctions << item->name() + "::" + child->name();
|
||||
}
|
||||
if (foundProFiles.contains(item->proFile())) {
|
||||
tc = foundProFiles[item->proFile()];
|
||||
QStringList oldFunctions(tc->testCases());
|
||||
oldFunctions << testFunctions;
|
||||
tc->setTestCases(oldFunctions);
|
||||
} else {
|
||||
tc = new QuickTestConfiguration;
|
||||
tc->setTestCases(testFunctions);
|
||||
tc->setProjectFile(item->proFile());
|
||||
tc->setProject(ProjectExplorer::SessionManager::startupProject());
|
||||
tc->setInternalTargets(item->internalTargets());
|
||||
foundProFiles.insert(item->proFile(), tc);
|
||||
}
|
||||
}
|
||||
|
||||
TestConfiguration *QuickTestTreeItem::debugConfiguration() const
|
||||
{
|
||||
QuickTestConfiguration *config = static_cast<QuickTestConfiguration *>(testConfiguration());
|
||||
@@ -161,6 +198,17 @@ TestConfiguration *QuickTestTreeItem::debugConfiguration() const
|
||||
return config;
|
||||
}
|
||||
|
||||
struct Tests {
|
||||
int testCount = 0;
|
||||
QSet<QString> internalTargets;
|
||||
};
|
||||
|
||||
static void addTestsForItem(Tests &tests, const TestTreeItem *item)
|
||||
{
|
||||
tests.testCount += item->childCount();
|
||||
tests.internalTargets = item->internalTargets();
|
||||
}
|
||||
|
||||
QList<TestConfiguration *> QuickTestTreeItem::getAllTestConfigurations() const
|
||||
{
|
||||
QList<TestConfiguration *> result;
|
||||
@@ -169,8 +217,7 @@ QList<TestConfiguration *> QuickTestTreeItem::getAllTestConfigurations() const
|
||||
if (!project || type() != Root)
|
||||
return result;
|
||||
|
||||
QHash<QString, int> foundProFiles;
|
||||
QHash<QString, QSet<QString> > proFilesWithTargets;
|
||||
QHash<QString, Tests> testsForProfile;
|
||||
for (int row = 0, count = childCount(); row < count; ++row) {
|
||||
const TestTreeItem *child = childItem(row);
|
||||
// unnamed Quick Tests must be handled separately
|
||||
@@ -178,25 +225,29 @@ QList<TestConfiguration *> QuickTestTreeItem::getAllTestConfigurations() const
|
||||
for (int childRow = 0, ccount = child->childCount(); childRow < ccount; ++ childRow) {
|
||||
const TestTreeItem *grandChild = child->childItem(childRow);
|
||||
const QString &proFile = grandChild->proFile();
|
||||
foundProFiles.insert(proFile, foundProFiles[proFile] + 1);
|
||||
proFilesWithTargets.insert(proFile, grandChild->internalTargets());
|
||||
++(testsForProfile[proFile].testCount);
|
||||
testsForProfile[proFile].internalTargets = grandChild->internalTargets();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// named Quick Test
|
||||
const QString &proFile = child->proFile();
|
||||
foundProFiles.insert(proFile, foundProFiles[proFile] + child->childCount());
|
||||
proFilesWithTargets.insert(proFile, child->internalTargets());
|
||||
if (child->type() == TestCase) {
|
||||
addTestsForItem(testsForProfile[child->proFile()], child);
|
||||
} else if (child->type() == GroupNode) {
|
||||
const int groupCount = child->childCount();
|
||||
for (int groupRow = 0; groupRow < groupCount; ++groupRow) {
|
||||
const TestTreeItem *grandChild = child->childItem(groupRow);
|
||||
addTestsForItem(testsForProfile[grandChild->proFile()], grandChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
// create TestConfiguration for each project file
|
||||
QHash<QString, int>::ConstIterator it = foundProFiles.begin();
|
||||
QHash<QString, int>::ConstIterator end = foundProFiles.end();
|
||||
for ( ; it != end; ++it) {
|
||||
for (auto it = testsForProfile.begin(), end = testsForProfile.end(); it != end; ++it) {
|
||||
QuickTestConfiguration *tc = new QuickTestConfiguration;
|
||||
tc->setTestCaseCount(it.value());
|
||||
tc->setTestCaseCount(it.value().testCount);
|
||||
tc->setProjectFile(it.key());
|
||||
tc->setProject(project);
|
||||
tc->setInternalTargets(proFilesWithTargets[it.key()]);
|
||||
tc->setInternalTargets(it.value().internalTargets);
|
||||
result << tc;
|
||||
}
|
||||
return result;
|
||||
@@ -209,7 +260,6 @@ QList<TestConfiguration *> QuickTestTreeItem::getSelectedTestConfigurations() co
|
||||
if (!project || type() != Root)
|
||||
return result;
|
||||
|
||||
QuickTestConfiguration *tc = nullptr;
|
||||
QHash<QString, QuickTestConfiguration *> foundProFiles;
|
||||
|
||||
for (int row = 0, count = childCount(); row < count; ++row) {
|
||||
@@ -219,39 +269,10 @@ QList<TestConfiguration *> QuickTestTreeItem::getSelectedTestConfigurations() co
|
||||
continue;
|
||||
|
||||
// named Quick Tests
|
||||
switch (child->checked()) {
|
||||
case Qt::Unchecked:
|
||||
continue;
|
||||
case Qt::Checked:
|
||||
case Qt::PartiallyChecked:
|
||||
default:
|
||||
QStringList testFunctions;
|
||||
int grandChildCount = child->childCount();
|
||||
for (int grandChildRow = 0; grandChildRow < grandChildCount; ++grandChildRow) {
|
||||
const TestTreeItem *grandChild = child->childItem(grandChildRow);
|
||||
if (grandChild->checked() != Qt::Checked || grandChild->type() != TestFunctionOrSet)
|
||||
continue;
|
||||
testFunctions << child->name() + "::" + grandChild->name();
|
||||
}
|
||||
if (foundProFiles.contains(child->proFile())) {
|
||||
tc = foundProFiles[child->proFile()];
|
||||
QStringList oldFunctions(tc->testCases());
|
||||
oldFunctions << testFunctions;
|
||||
tc->setTestCases(oldFunctions);
|
||||
} else {
|
||||
tc = new QuickTestConfiguration;
|
||||
tc->setTestCases(testFunctions);
|
||||
tc->setProjectFile(child->proFile());
|
||||
tc->setProject(project);
|
||||
tc->setInternalTargets(child->internalTargets());
|
||||
foundProFiles.insert(child->proFile(), tc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
testConfigurationFromCheckState(child, foundProFiles);
|
||||
}
|
||||
QHash<QString, QuickTestConfiguration *>::ConstIterator it = foundProFiles.begin();
|
||||
QHash<QString, QuickTestConfiguration *>::ConstIterator end = foundProFiles.end();
|
||||
for ( ; it != end; ++it) {
|
||||
|
||||
for (auto it = foundProFiles.begin(), end = foundProFiles.end(); it != end; ++it) {
|
||||
QuickTestConfiguration *config = it.value();
|
||||
if (!config->unnamedOnly())
|
||||
result << config;
|
||||
|
||||
Reference in New Issue
Block a user