AutoTest: Use using namespace Utils more often

Change-Id: I9d20cd3496c4719d58a977f8fd53253c86d55463
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2023-01-16 15:00:15 +01:00
parent d05c5b7d07
commit bc3ebef7ce
41 changed files with 343 additions and 310 deletions

View File

@@ -9,6 +9,8 @@
#include <QByteArrayList>
using namespace Utils;
namespace Autotest {
namespace Internal {
namespace QuickTestUtils {
@@ -20,10 +22,9 @@ bool isQuickTestMacro(const QByteArray &macro)
return valid.contains(macro);
}
QHash<Utils::FilePath, Utils::FilePath> proFilesForQmlFiles(ITestFramework *framework,
const Utils::FilePaths &files)
QHash<FilePath, FilePath> proFilesForQmlFiles(ITestFramework *framework, const FilePaths &files)
{
QHash<Utils::FilePath, Utils::FilePath> result;
QHash<FilePath, FilePath> result;
TestTreeItem *rootNode = framework->rootNode();
QTC_ASSERT(rootNode, return result);
@@ -31,16 +32,16 @@ QHash<Utils::FilePath, Utils::FilePath> proFilesForQmlFiles(ITestFramework *fram
return result;
rootNode->forFirstLevelChildItems([&result, &files](TestTreeItem *child) {
const Utils::FilePath &file = child->filePath();
const FilePath &file = child->filePath();
if (!file.isEmpty() && files.contains(file)) {
const Utils::FilePath &proFile = child->proFile();
const FilePath &proFile = child->proFile();
if (!proFile.isEmpty())
result.insert(file, proFile);
}
child->forFirstLevelChildItems([&result, &files](TestTreeItem *grandChild) {
const Utils::FilePath &file = grandChild->filePath();
const FilePath &file = grandChild->filePath();
if (!file.isEmpty() && files.contains(file)) {
const Utils::FilePath &proFile = grandChild->proFile();
const FilePath &proFile = grandChild->proFile();
if (!proFile.isEmpty())
result.insert(file, proFile);
}

View File

@@ -12,6 +12,8 @@
#include <utils/stringutils.h>
using namespace Utils;
namespace Autotest {
namespace Internal {
@@ -22,7 +24,7 @@ QuickTestConfiguration::QuickTestConfiguration(ITestFramework *framework)
}
TestOutputReader *QuickTestConfiguration::createOutputReader(
const QFutureInterface<TestResult> &fi, Utils::QtcProcess *app) const
const QFutureInterface<TestResult> &fi, QtcProcess *app) const
{
auto qtSettings = static_cast<QtTestSettings *>(framework()->testSettings());
const QtTestOutputReader::OutputMode mode = qtSettings && qtSettings->useXMLOutput.value()
@@ -64,7 +66,7 @@ QStringList QuickTestConfiguration::argumentsForTestRunner(QStringList *omitted)
return arguments;
}
Utils::Environment QuickTestConfiguration::filteredEnvironment(const Utils::Environment &original) const
Environment QuickTestConfiguration::filteredEnvironment(const Environment &original) const
{
return QTestUtils::prepareBasicEnvironment(original);
}

View File

@@ -43,8 +43,7 @@ TestTreeItem *QuickTestParseResult::createTestTreeItem() const
static bool includesQtQuickTest(const CPlusPlus::Document::Ptr &doc,
const CPlusPlus::Snapshot &snapshot)
{
static QStringList expectedHeaderPrefixes
= Utils::HostOsInfo::isMacHost()
static QStringList expectedHeaderPrefixes = HostOsInfo::isMacHost()
? QStringList({"QtQuickTest.framework/Headers", "QtQuickTest"})
: QStringList({"QtQuickTest"});
@@ -78,8 +77,7 @@ static bool includesQtQuickTest(const CPlusPlus::Document::Ptr &doc,
return false;
}
static QString quickTestSrcDir(const CppEditor::CppModelManager *cppMM,
const Utils::FilePath &fileName)
static QString quickTestSrcDir(const CppEditor::CppModelManager *cppMM, const FilePath &fileName)
{
const QList<CppEditor::ProjectPart::ConstPtr> parts = cppMM->projectPart(fileName);
if (parts.size() > 0) {
@@ -103,7 +101,7 @@ static QString quickTestSrcDir(const CppEditor::CppModelManager *cppMM,
QString QuickTestParser::quickTestName(const CPlusPlus::Document::Ptr &doc) const
{
const QList<CPlusPlus::Document::MacroUse> macros = doc->macroUses();
const Utils::FilePath filePath = doc->filePath();
const FilePath filePath = doc->filePath();
for (const CPlusPlus::Document::MacroUse &macro : macros) {
if (!macro.isFunctionLike() || macro.arguments().isEmpty())
@@ -130,8 +128,7 @@ QString QuickTestParser::quickTestName(const CPlusPlus::Document::Ptr &doc) cons
return astVisitor.testBaseName();
// check for precompiled headers
static QStringList expectedHeaderPrefixes
= Utils::HostOsInfo::isMacHost()
static QStringList expectedHeaderPrefixes = HostOsInfo::isMacHost()
? QStringList({"QtQuickTest.framework/Headers", "QtQuickTest"})
: QStringList({"QtQuickTest"});
bool pchIncludes = false;
@@ -152,9 +149,9 @@ QString QuickTestParser::quickTestName(const CPlusPlus::Document::Ptr &doc) cons
return {};
}
QList<Document::Ptr> QuickTestParser::scanDirectoryForQuickTestQmlFiles(const Utils::FilePath &srcDir)
QList<Document::Ptr> QuickTestParser::scanDirectoryForQuickTestQmlFiles(const FilePath &srcDir)
{
Utils::FilePaths dirs({srcDir});
FilePaths dirs({srcDir});
QStringList dirsStr({srcDir.toString()});
ModelManagerInterface *qmlJsMM = QmlJSTools::Internal::ModelManager::instance();
// make sure even files not listed in pro file are available inside the snapshot
@@ -171,7 +168,7 @@ QList<Document::Ptr> QuickTestParser::scanDirectoryForQuickTestQmlFiles(const Ut
QDirIterator::Subdirectories);
while (it.hasNext()) {
it.next();
auto subDir = Utils::FilePath::fromFileInfo(it.fileInfo()).canonicalPath();
auto subDir = FilePath::fromFileInfo(it.fileInfo()).canonicalPath();
dirs.append(subDir);
dirsStr.append(subDir.toString());
}
@@ -182,10 +179,10 @@ QList<Document::Ptr> QuickTestParser::scanDirectoryForQuickTestQmlFiles(const Ut
QList<Document::Ptr> foundDocs;
for (const Utils::FilePath &path : std::as_const(dirs)) {
for (const FilePath &path : std::as_const(dirs)) {
const QList<Document::Ptr> docs = snapshot.documentsInDirectory(path);
for (const Document::Ptr &doc : docs) {
Utils::FilePath fi = doc->fileName();
const FilePath fi = doc->fileName();
//const QFileInfo fi(doc->fileName());
// using working copy above might provide no more existing files
if (!fi.exists())
@@ -202,7 +199,7 @@ QList<Document::Ptr> QuickTestParser::scanDirectoryForQuickTestQmlFiles(const Ut
static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr> &futureInterface,
const Document::Ptr &qmlJSDoc,
ITestFramework *framework,
const Utils::FilePath &proFile = {},
const FilePath &proFile = {},
bool checkForDerivedTest = false)
{
if (qmlJSDoc.isNull())
@@ -260,10 +257,9 @@ bool QuickTestParser::handleQtQuickTest(QFutureInterface<TestParseResultPtr> &fu
if (ppList.isEmpty()) // happens if shutting down while parsing
return false;
const FilePath cppFileName = document->filePath();
const FilePath proFile = Utils::FilePath::fromString(ppList.at(0)->projectFile);
const FilePath proFile = FilePath::fromString(ppList.at(0)->projectFile);
m_mainCppFiles.insert(cppFileName, proFile);
const Utils::FilePath srcDir = Utils::FilePath::fromString(
quickTestSrcDir(modelManager, cppFileName));
const FilePath srcDir = FilePath::fromString(quickTestSrcDir(modelManager, cppFileName));
if (srcDir.isEmpty())
return false;
@@ -308,7 +304,7 @@ void QuickTestParser::handleDirectoryChanged(const QString &directory)
if (timestampChanged) {
m_watchedFiles[directory] = filesAndDates;
PathsAndLanguages paths;
paths.maybeInsert(Utils::FilePath::fromString(directory), Dialect::Qml);
paths.maybeInsert(FilePath::fromString(directory), Dialect::Qml);
QFutureInterface<void> future;
ModelManagerInterface *qmlJsMM = ModelManagerInterface::instance();
ModelManagerInterface::importScan(future, ModelManagerInterface::workingCopy(), paths,
@@ -342,14 +338,14 @@ QuickTestParser::QuickTestParser(ITestFramework *framework)
this, &QuickTestParser::handleDirectoryChanged);
}
void QuickTestParser::init(const Utils::FilePaths &filesToParse, bool fullParse)
void QuickTestParser::init(const FilePaths &filesToParse, bool fullParse)
{
m_qmlSnapshot = QmlJSTools::Internal::ModelManager::instance()->snapshot();
if (!fullParse) {
// in a full parse we get the correct entry points by the respective main
m_proFilesForQmlFiles = QuickTestUtils::proFilesForQmlFiles(framework(), filesToParse);
// get rid of cached main cpp files that are going to get processed anyhow
for (const Utils::FilePath &file : filesToParse) {
for (const FilePath &file : filesToParse) {
if (m_mainCppFiles.contains(file)) {
m_mainCppFiles.remove(file);
if (m_mainCppFiles.isEmpty())
@@ -375,10 +371,10 @@ void QuickTestParser::release()
}
bool QuickTestParser::processDocument(QFutureInterface<TestParseResultPtr> &futureInterface,
const Utils::FilePath &fileName)
const FilePath &fileName)
{
if (fileName.endsWith(".qml")) {
const Utils::FilePath &proFile = m_proFilesForQmlFiles.value(fileName);
const FilePath &proFile = m_proFilesForQmlFiles.value(fileName);
if (proFile.isEmpty())
return false;
Document::Ptr qmlJSDoc = m_qmlSnapshot.document(fileName);
@@ -396,9 +392,9 @@ bool QuickTestParser::processDocument(QFutureInterface<TestParseResultPtr> &futu
return handleQtQuickTest(futureInterface, cppdoc, framework());
}
Utils::FilePath QuickTestParser::projectFileForMainCppFile(const Utils::FilePath &fileName) const
FilePath QuickTestParser::projectFileForMainCppFile(const FilePath &fileName) const
{
return m_mainCppFiles.contains(fileName) ? m_mainCppFiles.value(fileName) : Utils::FilePath();
return m_mainCppFiles.contains(fileName) ? m_mainCppFiles.value(fileName) : FilePath();
}
} // namespace Internal

View File

@@ -12,10 +12,12 @@
#include <projectexplorer/session.h>
#include <utils/qtcassert.h>
using namespace Utils;
namespace Autotest {
namespace Internal {
static QSet<QString> internalTargets(const Utils::FilePath &proFile);
static QSet<QString> internalTargets(const FilePath &proFile);
TestTreeItem *QuickTestTreeItem::copyWithoutChildren()
{
@@ -149,8 +151,8 @@ static QList<ITestConfiguration *> testConfigurationsFor(
if (!project || rootNode->type() != TestTreeItem::Root)
return {};
QHash<Utils::FilePath, QuickTestConfiguration *> configurationForProFiles;
rootNode->forSelectedChildren([&predicate, &configurationForProFiles](Utils::TreeItem *it) {
QHash<FilePath, QuickTestConfiguration *> configurationForProFiles;
rootNode->forSelectedChildren([&predicate, &configurationForProFiles](TreeItem *it) {
auto treeItem = static_cast<TestTreeItem *>(it);
if (treeItem->type() == TestTreeItem::Root || treeItem->type() == TestTreeItem::GroupNode)
return true;
@@ -208,12 +210,12 @@ QList<ITestConfiguration *> QuickTestTreeItem::getAllTestConfigurations() const
if (!project || type() != Root)
return result;
QHash<Utils::FilePath, Tests> testsForProfile;
QHash<FilePath, Tests> testsForProfile;
forFirstLevelChildItems([&testsForProfile](TestTreeItem *child) {
// unnamed Quick Tests must be handled separately
if (child->name().isEmpty()) {
child->forFirstLevelChildItems([&testsForProfile](TestTreeItem *grandChild) {
const Utils::FilePath &proFile = grandChild->proFile();
const FilePath &proFile = grandChild->proFile();
++(testsForProfile[proFile].testCount);
testsForProfile[proFile].internalTargets = internalTargets(grandChild->proFile());
});
@@ -255,7 +257,7 @@ QList<ITestConfiguration *> QuickTestTreeItem::getFailedTestConfigurations() con
}
QList<ITestConfiguration *> QuickTestTreeItem::getTestConfigurationsForFile(
const Utils::FilePath &fileName) const
const FilePath &fileName) const
{
return testConfigurationsFor(this, [&fileName](TestTreeItem *it) {
return it->filePath() == fileName;
@@ -271,7 +273,7 @@ TestTreeItem *QuickTestTreeItem::find(const TestParseResult *result)
if (result->name.isEmpty())
return unnamedQuickTests();
if (result->framework->grouping()) {
const Utils::FilePath path = result->fileName.absolutePath();
const FilePath path = result->fileName.absolutePath();
TestTreeItem *group = findFirstLevelChildItem([path](TestTreeItem *group) {
return group->filePath() == path;
});
@@ -354,7 +356,7 @@ bool QuickTestTreeItem::removeOnSweepIfEmpty() const
TestTreeItem *QuickTestTreeItem::createParentGroupNode() const
{
const Utils::FilePath &absPath = filePath().absolutePath();
const FilePath &absPath = filePath().absolutePath();
return new QuickTestTreeItem(framework(), absPath.baseName(), absPath, TestTreeItem::GroupNode);
}
@@ -363,7 +365,7 @@ bool QuickTestTreeItem::isGroupable() const
return type() == TestCase && !name().isEmpty() && !filePath().isEmpty();
}
QSet<QString> internalTargets(const Utils::FilePath &proFile)
QSet<QString> internalTargets(const FilePath &proFile)
{
QSet<QString> result;
const auto cppMM = CppEditor::CppModelManager::instance();
@@ -379,11 +381,11 @@ QSet<QString> internalTargets(const Utils::FilePath &proFile)
return result;
}
void QuickTestTreeItem::markForRemovalRecursively(const Utils::FilePath &filePath)
void QuickTestTreeItem::markForRemovalRecursively(const FilePath &filePath)
{
TestTreeItem::markForRemovalRecursively(filePath);
auto parser = static_cast<QuickTestParser *>(framework()->testParser());
const Utils::FilePath proFile = parser->projectFileForMainCppFile(filePath);
const FilePath proFile = parser->projectFileForMainCppFile(filePath);
if (!proFile.isEmpty()) {
TestTreeItem *root = framework()->rootNode();
root->forAllChildItems([proFile](TestTreeItem *it) {
@@ -393,7 +395,7 @@ void QuickTestTreeItem::markForRemovalRecursively(const Utils::FilePath &filePat
}
}
TestTreeItem *QuickTestTreeItem::findChildByFileNameAndType(const Utils::FilePath &filePath,
TestTreeItem *QuickTestTreeItem::findChildByFileNameAndType(const FilePath &filePath,
const QString &name,
TestTreeItem::Type tType)
@@ -404,7 +406,7 @@ TestTreeItem *QuickTestTreeItem::findChildByFileNameAndType(const Utils::FilePat
}
TestTreeItem *QuickTestTreeItem::findChildByNameFileAndLine(const QString &name,
const Utils::FilePath &filePath,
const FilePath &filePath,
int line)
{
return findFirstLevelChildItem([name, filePath, line](const TestTreeItem *other) {