forked from qt-creator/qt-creator
AutoTest: Consolidate common functionality
While at it remove unused code path. Change-Id: I15dff61131c5f3c9301cd733e1c8b92bd848f084 Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -87,10 +87,5 @@ Utils::Environment QuickTestConfiguration::filteredEnvironment(const Utils::Envi
|
|||||||
return QTestUtils::prepareBasicEnvironment(original);
|
return QTestUtils::prepareBasicEnvironment(original);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuickTestConfiguration::setUnnamedOnly(bool unnamedOnly)
|
|
||||||
{
|
|
||||||
m_unnamedOnly = unnamedOnly;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Autotest
|
} // namespace Autotest
|
||||||
|
@@ -38,11 +38,6 @@ public:
|
|||||||
QProcess *app) const override;
|
QProcess *app) const override;
|
||||||
QStringList argumentsForTestRunner(QStringList *omitted = nullptr) const override;
|
QStringList argumentsForTestRunner(QStringList *omitted = nullptr) const override;
|
||||||
Utils::Environment filteredEnvironment(const Utils::Environment &original) const override;
|
Utils::Environment filteredEnvironment(const Utils::Environment &original) const override;
|
||||||
void setUnnamedOnly(bool unnamedOnly);
|
|
||||||
bool unnamedOnly() const { return m_unnamedOnly; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_unnamedOnly = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -160,78 +160,44 @@ TestConfiguration *QuickTestTreeItem::testConfiguration() const
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void testConfigurationFromCheckState(const TestTreeItem *item,
|
static QList<TestConfiguration *> testConfigurationsFor(
|
||||||
QHash<QString, QuickTestConfiguration *> &foundProFiles)
|
const TestTreeItem *rootNode, const std::function<bool(TestTreeItem *)> &predicate)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(item, return);
|
QTC_ASSERT(rootNode, return {});
|
||||||
if (item->type() == TestTreeItem::GroupNode) {
|
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||||
for (int row = 0, count = item->childCount(); row < count; ++row)
|
if (!project || rootNode->type() != TestTreeItem::Root)
|
||||||
testConfigurationFromCheckState(item->childAt(row), foundProFiles);
|
return {};
|
||||||
return;
|
|
||||||
}
|
|
||||||
QTC_ASSERT(item->type() == TestTreeItem::TestCase, return);
|
|
||||||
QuickTestConfiguration *tc = nullptr;
|
|
||||||
if (item->checked() == Qt::Unchecked)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const QString testName = item->name();
|
QHash<QString, QuickTestConfiguration *> configurationForProFiles;
|
||||||
QStringList testFunctions;
|
rootNode->forSelectedChildren([&predicate, &configurationForProFiles](Utils::TreeItem *it) {
|
||||||
item->forFirstLevelChildren([&testFunctions, &testName](TestTreeItem *child) {
|
auto treeItem = static_cast<TestTreeItem *>(it);
|
||||||
if (child->checked() == Qt::Checked && child->type() == TestTreeItem::TestFunction)
|
if (treeItem->type() == TestTreeItem::Root || treeItem->type() == TestTreeItem::GroupNode)
|
||||||
testFunctions << testName + "::" + child->name();
|
return true;
|
||||||
|
if (treeItem->type() == TestTreeItem::TestCase) {
|
||||||
|
const QString name = treeItem->name();
|
||||||
|
|
||||||
|
QStringList functions;
|
||||||
|
treeItem->forFirstLevelChildren([&functions, &name, &predicate](TestTreeItem *child) {
|
||||||
|
if (predicate(child))
|
||||||
|
functions << name + "::" + child->name();
|
||||||
});
|
});
|
||||||
if (foundProFiles.contains(item->proFile())) {
|
if (functions.isEmpty())
|
||||||
tc = foundProFiles[item->proFile()];
|
return false;
|
||||||
QStringList oldFunctions(tc->testCases());
|
|
||||||
oldFunctions << testFunctions;
|
auto it = configurationForProFiles.find(treeItem->proFile());
|
||||||
tc->setTestCases(oldFunctions);
|
if (it == configurationForProFiles.end()) {
|
||||||
} else {
|
auto tc = new QuickTestConfiguration(treeItem->framework());
|
||||||
tc = new QuickTestConfiguration(item->framework());
|
tc->setProjectFile(treeItem->proFile());
|
||||||
tc->setTestCases(testFunctions);
|
|
||||||
tc->setProjectFile(item->proFile());
|
|
||||||
tc->setProject(ProjectExplorer::SessionManager::startupProject());
|
tc->setProject(ProjectExplorer::SessionManager::startupProject());
|
||||||
tc->setInternalTargets(item->internalTargets());
|
tc->setInternalTargets(treeItem->internalTargets());
|
||||||
foundProFiles.insert(item->proFile(), tc);
|
it = configurationForProFiles.insert(treeItem->proFile(), tc);
|
||||||
}
|
}
|
||||||
|
it.value()->setTestCases(it.value()->testCases() + functions);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
static void testConfigurationsForFailed(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)
|
|
||||||
testConfigurationsForFailed(item->childAt(row), foundProfiles);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QTC_ASSERT(item->type() == TestTreeItem::TestCase, return);
|
|
||||||
|
|
||||||
const QString testName = item->name();
|
|
||||||
if (testName.isEmpty()) // skip unnamed quick tests as we cannot address them
|
|
||||||
return;
|
|
||||||
|
|
||||||
QStringList testFunctions;
|
|
||||||
item->forFirstLevelChildren([&testFunctions, &testName](TestTreeItem *child) {
|
|
||||||
if (child->data(0, FailedRole).toBool())
|
|
||||||
testFunctions << testName + "::" + child->name();
|
|
||||||
});
|
});
|
||||||
if (testFunctions.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
QuickTestConfiguration *tc = nullptr;
|
return Utils::static_container_cast<TestConfiguration *>(configurationForProFiles.values());
|
||||||
if (foundProfiles.contains(item->proFile())) {
|
|
||||||
tc = foundProfiles[item->proFile()];
|
|
||||||
QStringList oldFunctions(tc->testCases());
|
|
||||||
oldFunctions << testFunctions;
|
|
||||||
tc->setTestCases(oldFunctions);
|
|
||||||
} else {
|
|
||||||
tc = new QuickTestConfiguration(item->framework());
|
|
||||||
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
|
TestConfiguration *QuickTestTreeItem::debugConfiguration() const
|
||||||
@@ -295,80 +261,25 @@ QList<TestConfiguration *> QuickTestTreeItem::getAllTestConfigurations() const
|
|||||||
|
|
||||||
QList<TestConfiguration *> QuickTestTreeItem::getSelectedTestConfigurations() const
|
QList<TestConfiguration *> QuickTestTreeItem::getSelectedTestConfigurations() const
|
||||||
{
|
{
|
||||||
QList<TestConfiguration *> result;
|
return testConfigurationsFor(this, [](TestTreeItem *it) {
|
||||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
return it->checked() == Qt::Checked && it->type() == TestTreeItem::TestFunction;
|
||||||
if (!project || type() != Root)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
QHash<QString, QuickTestConfiguration *> foundProFiles;
|
|
||||||
|
|
||||||
forFirstLevelChildren([&foundProFiles](TestTreeItem *child) {
|
|
||||||
// unnamed Quick Tests cannot get selected explicitly - only handle named Quick Tests
|
|
||||||
if (!child->name().isEmpty())
|
|
||||||
testConfigurationFromCheckState(child, foundProFiles);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto it = foundProFiles.begin(), end = foundProFiles.end(); it != end; ++it) {
|
|
||||||
QuickTestConfiguration *config = it.value();
|
|
||||||
if (!config->unnamedOnly())
|
|
||||||
result << config;
|
|
||||||
else
|
|
||||||
delete config;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<TestConfiguration *> QuickTestTreeItem::getFailedTestConfigurations() const
|
QList<TestConfiguration *> QuickTestTreeItem::getFailedTestConfigurations() const
|
||||||
{
|
{
|
||||||
QList<TestConfiguration *> result;
|
return testConfigurationsFor(this, [](TestTreeItem *it) {
|
||||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
return it->data(0, FailedRole).toBool();
|
||||||
if (!project || type() != Root)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
QHash<QString, QuickTestConfiguration *> foundProFiles;
|
|
||||||
forFirstLevelChildren([&foundProFiles](TestTreeItem *child) {
|
|
||||||
testConfigurationsForFailed(child, foundProFiles);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto it = foundProFiles.begin(), end = foundProFiles.end(); it != end; ++it) {
|
|
||||||
QuickTestConfiguration *config = it.value();
|
|
||||||
if (!config->unnamedOnly())
|
|
||||||
result << config;
|
|
||||||
else
|
|
||||||
delete config;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<TestConfiguration *> QuickTestTreeItem::getTestConfigurationsForFile(const Utils::FilePath &fileName) const
|
QList<TestConfiguration *> QuickTestTreeItem::getTestConfigurationsForFile(
|
||||||
|
const Utils::FilePath &fileName) const
|
||||||
{
|
{
|
||||||
QList<TestConfiguration *> result;
|
|
||||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
|
||||||
if (!project || type() != Root)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
QHash<TestTreeItem *, QStringList> testFunctions;
|
|
||||||
const QString &file = fileName.toString();
|
const QString &file = fileName.toString();
|
||||||
forAllChildren([&testFunctions, &file](TestTreeItem *node) {
|
return testConfigurationsFor(this, [&file](TestTreeItem *it) {
|
||||||
if (node->type() == Type::TestFunction && node->filePath() == file) {
|
return it->filePath() == file;
|
||||||
QTC_ASSERT(node->parentItem(), return);
|
|
||||||
TestTreeItem *testCase = node->parentItem();
|
|
||||||
QTC_ASSERT(testCase->type() == Type::TestCase, return);
|
|
||||||
if (testCase->name().isEmpty())
|
|
||||||
return;
|
|
||||||
testFunctions[testCase] << testCase->name() + "::" + node->name();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto it = testFunctions.cbegin(), end = testFunctions.cend(); it != end; ++it) {
|
|
||||||
TestConfiguration *tc = it.key()->testConfiguration();
|
|
||||||
QTC_ASSERT(tc, continue);
|
|
||||||
tc->setTestCases(it.value());
|
|
||||||
result << tc;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TestTreeItem *QuickTestTreeItem::find(const TestParseResult *result)
|
TestTreeItem *QuickTestTreeItem::find(const TestParseResult *result)
|
||||||
|
Reference in New Issue
Block a user