AutoTest: Fix handling of multiple build targets

If project files are not mapped 1:1 to targets the result
of the chosen executable was more or less random.
Try to handle multiple targets as correct as possible by
checking for build targets already where we still know
which files are part of the respective test cases.

Task-number: QTCREATORBUG-17783
Task-number: QTCREATORBUG-18357
Change-Id: I82dcc26bf52c9918e2727b439a719af08879ef49
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Christian Stenger
2017-06-09 09:30:21 +02:00
parent bde8ebc56c
commit cce1e130d7
13 changed files with 78 additions and 23 deletions

View File

@@ -27,6 +27,7 @@
#include "quicktestconfiguration.h"
#include "quicktestparser.h"
#include <cpptools/cppmodelmanager.h>
#include <projectexplorer/session.h>
#include <utils/qtcassert.h>
@@ -138,6 +139,8 @@ TestConfiguration *QuickTestTreeItem::testConfiguration() const
default:
return nullptr;
}
if (config)
config->setInternalTargets(internalTargets());
return config;
}
@@ -150,6 +153,7 @@ QList<TestConfiguration *> QuickTestTreeItem::getAllTestConfigurations() const
return result;
QHash<QString, int> foundProFiles;
QHash<QString, QSet<QString> > proFilesWithTargets;
for (int row = 0, count = childCount(); row < count; ++row) {
const TestTreeItem *child = childItem(row);
// unnamed Quick Tests must be handled separately
@@ -158,12 +162,14 @@ QList<TestConfiguration *> QuickTestTreeItem::getAllTestConfigurations() const
const TestTreeItem *grandChild = child->childItem(childRow);
const QString &proFile = grandChild->proFile();
foundProFiles.insert(proFile, foundProFiles[proFile] + 1);
proFilesWithTargets.insert(proFile, grandChild->internalTargets());
}
continue;
}
// named Quick Test
const QString &proFile = child->proFile();
foundProFiles.insert(proFile, foundProFiles[proFile] + child->childCount());
proFilesWithTargets.insert(proFile, child->internalTargets());
}
// create TestConfiguration for each project file
QHash<QString, int>::ConstIterator it = foundProFiles.begin();
@@ -173,6 +179,7 @@ QList<TestConfiguration *> QuickTestTreeItem::getAllTestConfigurations() const
tc->setTestCaseCount(it.value());
tc->setProjectFile(it.key());
tc->setProject(project);
tc->setInternalTargets(proFilesWithTargets[it.key()]);
result << tc;
}
return result;
@@ -203,6 +210,7 @@ QList<TestConfiguration *> QuickTestTreeItem::getSelectedTestConfigurations() co
tc->setUnnamedOnly(true);
tc->setProjectFile(proFile);
tc->setProject(project);
tc->setInternalTargets(grandChild->internalTargets());
foundProFiles.insert(proFile, tc);
}
}
@@ -246,6 +254,7 @@ QList<TestConfiguration *> QuickTestTreeItem::getSelectedTestConfigurations() co
tc->setTestCases(testFunctions);
tc->setProjectFile(child->proFile());
tc->setProject(project);
tc->setInternalTargets(child->internalTargets());
foundProFiles.insert(child->proFile(), tc);
}
break;
@@ -307,6 +316,20 @@ bool QuickTestTreeItem::lessThan(const TestTreeItem *other, TestTreeItem::SortMo
return TestTreeItem::lessThan(other, mode);
}
QSet<QString> QuickTestTreeItem::internalTargets() const
{
QSet<QString> result;
const auto cppMM = CppTools::CppModelManager::instance();
const auto projectInfo = cppMM->projectInfo(ProjectExplorer::SessionManager::startupProject());
for (const CppTools::ProjectPart::Ptr projectPart : projectInfo.projectParts()) {
if (projectPart->projectFile == proFile()) {
result.insert(projectPart->buildSystemTarget);
break;
}
}
return result;
}
TestTreeItem *QuickTestTreeItem::unnamedQuickTests() const
{
if (type() != Root)