From 5edf4925af7550f93f9e64ce213009a2e2eb0440 Mon Sep 17 00:00:00 2001 From: Andrii Semkiv Date: Thu, 5 Sep 2024 10:14:34 +0200 Subject: [PATCH] Autotest: Replace occurrences of FilePath::toString Use more sensible alternatives instead of FilePath::toString Use FilePath capabilities instead of QDir/QFile. Change-Id: I47d3a2c4c5197074e6bcbeb20383a26d6cda120c Reviewed-by: Christian Stenger --- .../autotest/catch/catchtestparser.cpp | 2 +- src/plugins/autotest/catch/catchtreeitem.cpp | 7 ++++--- src/plugins/autotest/gtest/gtesttreeitem.cpp | 7 ++++--- .../autotest/quick/quicktestparser.cpp | 20 +++++++++---------- .../autotest/quick/quicktesttreeitem.cpp | 2 +- src/plugins/autotest/testconfiguration.cpp | 18 ++++++++++------- src/plugins/autotest/testrunner.cpp | 15 ++++++++------ src/plugins/autotest/testtreeitem.cpp | 9 ++++----- src/plugins/autotest/testtreeitem.h | 2 +- 9 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/plugins/autotest/catch/catchtestparser.cpp b/src/plugins/autotest/catch/catchtestparser.cpp index bc2f4e0644e..314f54e62bb 100644 --- a/src/plugins/autotest/catch/catchtestparser.cpp +++ b/src/plugins/autotest/catch/catchtestparser.cpp @@ -102,7 +102,7 @@ bool CatchTestParser::processDocument(QPromise &promise, if (doc.isNull() || !includesCatchHeader(doc, m_cppSnapshot)) return false; - const QString &filePath = doc->filePath().toString(); + const QString &filePath = doc->filePath().toUserOutput(); const QByteArray &fileContent = getFileContent(fileName); if (!hasCatchNames(doc)) { diff --git a/src/plugins/autotest/catch/catchtreeitem.cpp b/src/plugins/autotest/catch/catchtreeitem.cpp index 9f1d7c8e17c..ae634193d94 100644 --- a/src/plugins/autotest/catch/catchtreeitem.cpp +++ b/src/plugins/autotest/catch/catchtreeitem.cpp @@ -36,9 +36,10 @@ static QString nonRootDisplayName(const CatchTreeItem *it) if (!project) return it->name(); TestTreeItem *parent = it->parentItem(); - int baseDirSize = (parent->type() == TestTreeItem::GroupNode) - ? parent->filePath().toString().size() : project->projectDirectory().toString().size(); - return it->name().mid(baseDirSize + 1); + const FilePath baseDir = (parent->type() == TestTreeItem::GroupNode) + ? parent->filePath() + : project->projectDirectory(); + return it->filePath().relativePathFrom(baseDir).toUserOutput(); } QVariant CatchTreeItem::data(int column, int role) const diff --git a/src/plugins/autotest/gtest/gtesttreeitem.cpp b/src/plugins/autotest/gtest/gtesttreeitem.cpp index 42b10020052..280bdfa9160 100644 --- a/src/plugins/autotest/gtest/gtesttreeitem.cpp +++ b/src/plugins/autotest/gtest/gtesttreeitem.cpp @@ -109,7 +109,7 @@ QVariant GTestTreeItem::data(int column, int role) const case Qt::ToolTipRole: if (type() == GroupNode && GTestFramework::staticGroupMode() == GTest::Constants::GTestFilter) { - const auto tpl = QString("

%1

%2

").arg(filePath().toString()); + const auto tpl = QString("

%1

%2

").arg(filePath().path()); return tpl.arg(Tr::tr("Change GTest filter in use inside the settings.")); } break; @@ -535,9 +535,10 @@ bool GTestTreeItem::isGroupNodeFor(const TestTreeItem *other) const QTC_ASSERT(false, return false); } // FIXME gtest filter is no FilePath - if (GTestFramework::currentGTestFilter() != filePath().toString()) // filter has changed in settings + if (GTestFramework::currentGTestFilter() + != filePath().path()) // filter has changed in settings return false; - bool matches = matchesFilter(filePath().toString(), fullName); + bool matches = matchesFilter(filePath().path(), fullName); return (matches && name() == matchingString()) || (!matches && name() == notMatchingString()); } diff --git a/src/plugins/autotest/quick/quicktestparser.cpp b/src/plugins/autotest/quick/quicktestparser.cpp index 017f9f4c6dd..e67926a262c 100644 --- a/src/plugins/autotest/quick/quicktestparser.cpp +++ b/src/plugins/autotest/quick/quicktestparser.cpp @@ -157,7 +157,7 @@ QString QuickTestParser::quickTestName(const CPlusPlus::Document::Ptr &doc) cons QList QuickTestParser::scanDirectoryForQuickTestQmlFiles(const FilePath &srcDir) { FilePaths dirs({srcDir}); - QStringList dirsStr({srcDir.toString()}); + QStringList dirsStr({srcDir.path()}); ModelManagerInterface *qmlJsMM = QmlJSTools::Internal::ModelManager::instance(); // make sure even files not listed in pro file are available inside the snapshot PathsAndLanguages paths; @@ -165,15 +165,15 @@ QList QuickTestParser::scanDirectoryForQuickTestQmlFiles(const Fi ModelManagerInterface::importScan(ModelManagerInterface::workingCopy(), paths, qmlJsMM, false /*emitDocumentChanges*/, false /*onlyTheLib*/, true /*forceRescan*/ ); - QDirIterator it(srcDir.toString(), - QDir::Dirs | QDir::NoDotAndDotDot, - QDirIterator::Subdirectories); - while (it.hasNext()) { - it.next(); - auto subDir = FilePath::fromFileInfo(it.fileInfo()).canonicalPath(); - dirs.append(subDir); - dirsStr.append(subDir.toString()); - } + srcDir.iterateDirectory( + [&dirs, &dirsStr](const FilePath &p) { + const FilePath &canonicalPath = p.canonicalPath(); + dirs.append(canonicalPath); + dirsStr.append(canonicalPath.path()); + return IterationPolicy::Continue; + }, + FileFilter{{}, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories}); + QMetaObject::invokeMethod( this, [this, dirsStr] { QuickTestParser::doUpdateWatchPaths(dirsStr); }, diff --git a/src/plugins/autotest/quick/quicktesttreeitem.cpp b/src/plugins/autotest/quick/quicktesttreeitem.cpp index 5252f8ea27b..c4adf945872 100644 --- a/src/plugins/autotest/quick/quicktesttreeitem.cpp +++ b/src/plugins/autotest/quick/quicktesttreeitem.cpp @@ -377,7 +377,7 @@ QSet internalTargets(const FilePath &proFile) for (const CppEditor::ProjectPart::ConstPtr &projectPart : projectInfo->projectParts()) { if (projectPart->buildTargetType != ProjectExplorer::BuildTargetType::Executable) continue; - if (projectPart->projectFile != proFile.toString()) + if (projectPart->projectFile != proFile.path()) continue; if (Utils::anyOf(projectPart->projectMacros, [](const ProjectExplorer::Macro ¯o){ return macro.type == ProjectExplorer::MacroType::Define && diff --git a/src/plugins/autotest/testconfiguration.cpp b/src/plugins/autotest/testconfiguration.cpp index 9661d3e580e..8e2a1ecb57a 100644 --- a/src/plugins/autotest/testconfiguration.cpp +++ b/src/plugins/autotest/testconfiguration.cpp @@ -86,7 +86,7 @@ static bool isLocal(Target *target) static FilePath ensureExeEnding(const FilePath &file) { - if (!HostOsInfo::isWindowsHost() || file.isEmpty() || file.toString().toLower().endsWith(".exe")) + if (!HostOsInfo::isWindowsHost() || file.isEmpty() || file.suffix().toLower() == "exe") return file; return file.withExecutableSuffix(); } @@ -122,9 +122,11 @@ void TestConfiguration::completeTestInformation(RunConfiguration *rc, FilePath buildBase; if (auto buildConfig = target->activeBuildConfiguration()) { buildBase = buildConfig->buildDirectory(); - const QString projBase = startupProject->projectDirectory().toString(); - if (m_projectFile.startsWith(projBase)) - m_buildDir = (buildBase / m_projectFile.toString().mid(projBase.length())).absolutePath(); + const FilePath projBase = startupProject->projectDirectory(); + if (m_projectFile.isChildOf(projBase)) { + m_buildDir + = (buildBase.resolvePath(m_projectFile.relativePathFrom(projBase))).absolutePath(); + } } if (runMode == TestRunMode::Debug || runMode == TestRunMode::DebugWithoutDeploy) m_runConfig = new Internal::TestRunConfiguration(rc->target(), this); @@ -188,9 +190,11 @@ void TestConfiguration::completeTestInformation(TestRunMode runMode) FilePath buildBase; if (auto buildConfig = target->activeBuildConfiguration()) { buildBase = buildConfig->buildDirectory(); - const QString projBase = startupProject->projectDirectory().toString(); - if (m_projectFile.startsWith(projBase)) - m_buildDir = (buildBase / m_projectFile.toString().mid(projBase.length())).absolutePath(); + const FilePath projBase = startupProject->projectDirectory(); + if (m_projectFile.isChildOf(projBase)) { + m_buildDir + = (buildBase.resolvePath(m_projectFile.relativePathFrom(projBase))).absolutePath(); + } } // deployment information should get taken into account, but it pretty much seems as if diff --git a/src/plugins/autotest/testrunner.cpp b/src/plugins/autotest/testrunner.cpp index b92d503b4fb..0c1d543cb7d 100644 --- a/src/plugins/autotest/testrunner.cpp +++ b/src/plugins/autotest/testrunner.cpp @@ -527,8 +527,10 @@ void TestRunner::debugTests() const FilePath &commandFilePath = config->executableFilePath(); if (commandFilePath.isEmpty()) { - reportResult(ResultType::MessageFatal, Tr::tr("Could not find command \"%1\". (%2)") - .arg(config->executableFilePath().toString(), config->displayName())); + reportResult( + ResultType::MessageFatal, + Tr::tr("Could not find command \"%1\". (%2)") + .arg(config->executableFilePath().toUserOutput(), config->displayName())); onFinished(); return; } @@ -573,7 +575,7 @@ void TestRunner::debugTests() if (useOutputProcessor) { TestOutputReader *outputreader = config->createOutputReader(nullptr); connect(outputreader, &TestOutputReader::newResult, this, &TestRunner::testResultReady); - outputreader->setId(inferior.command.executable().toString()); + outputreader->setId(inferior.command.executable().toUserOutput()); connect(outputreader, &TestOutputReader::newOutputLineAvailable, TestResultsPane::instance(), &TestResultsPane::addOutputLine); connect(runControl, &RunControl::appendMessage, @@ -786,9 +788,10 @@ void RunConfigurationSelectionDialog::populate() if (auto target = project->activeTarget()) { for (RunConfiguration *rc : target->runConfigurations()) { auto runnable = rc->runnable(); - const QStringList rcDetails = { runnable.command.executable().toString(), - runnable.command.arguments(), - runnable.workingDirectory.toString() }; + const QStringList rcDetails + = {runnable.command.executable().toUserOutput(), + runnable.command.arguments(), + runnable.workingDirectory.toUserOutput()}; m_rcCombo->addItem(rc->displayName(), rcDetails); } } diff --git a/src/plugins/autotest/testtreeitem.cpp b/src/plugins/autotest/testtreeitem.cpp index adfacf7731f..6cf746a89e1 100644 --- a/src/plugins/autotest/testtreeitem.cpp +++ b/src/plugins/autotest/testtreeitem.cpp @@ -50,7 +50,7 @@ QVariant ITestTreeItem::data(int /*column*/, int role) const return Tr::tr("%1 (none)").arg(m_name); return m_name; case Qt::ToolTipRole: - return m_filePath.toString(); + return m_filePath.toUserOutput(); case Qt::DecorationRole: return testTreeIcon(m_type); case Qt::CheckStateRole: @@ -113,14 +113,13 @@ bool ITestTreeItem::lessThan(const ITestTreeItem *other, ITestTreeItem::SortMode return lhs.compare(rhs, Qt::CaseInsensitive) > 0; case Naturally: { if (type() == GroupNode && other->type() == GroupNode) { - return filePath().toString().compare(other->filePath().toString(), - Qt::CaseInsensitive) > 0; + return filePath().path().compare(other->filePath().path(), Qt::CaseInsensitive) > 0; } const Link &leftLink = data(0, LinkRole).value(); const Link &rightLink = other->data(0, LinkRole).value(); - const int comparison = leftLink.targetFilePath.toString().compare( - rightLink.targetFilePath.toString(), Qt::CaseInsensitive); + const int comparison = leftLink.targetFilePath.path() + .compare(rightLink.targetFilePath.path(), Qt::CaseInsensitive); if (comparison == 0) { return leftLink.targetLine == rightLink.targetLine ? leftLink.targetColumn > rightLink.targetColumn diff --git a/src/plugins/autotest/testtreeitem.h b/src/plugins/autotest/testtreeitem.h index bdfb34778e5..ab50ef55af7 100644 --- a/src/plugins/autotest/testtreeitem.h +++ b/src/plugins/autotest/testtreeitem.h @@ -80,7 +80,7 @@ public: ITestBase *testBase() const { return m_testBase; } virtual bool lessThan(const ITestTreeItem *other, SortMode mode) const; - QString cacheName() const { return m_filePath.toString() + ':' + m_name; } + QString cacheName() const { return m_filePath.path() + ':' + m_name; } protected: void setType(Type type) { m_type = type; }