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 <christian.stenger@qt.io>
This commit is contained in:
Andrii Semkiv
2024-09-05 10:14:34 +02:00
committed by andrii.semkiv
parent f5dab0c7a5
commit 5edf4925af
9 changed files with 45 additions and 37 deletions

View File

@@ -102,7 +102,7 @@ bool CatchTestParser::processDocument(QPromise<TestParseResultPtr> &promise,
if (doc.isNull() || !includesCatchHeader(doc, m_cppSnapshot)) if (doc.isNull() || !includesCatchHeader(doc, m_cppSnapshot))
return false; return false;
const QString &filePath = doc->filePath().toString(); const QString &filePath = doc->filePath().toUserOutput();
const QByteArray &fileContent = getFileContent(fileName); const QByteArray &fileContent = getFileContent(fileName);
if (!hasCatchNames(doc)) { if (!hasCatchNames(doc)) {

View File

@@ -36,9 +36,10 @@ static QString nonRootDisplayName(const CatchTreeItem *it)
if (!project) if (!project)
return it->name(); return it->name();
TestTreeItem *parent = it->parentItem(); TestTreeItem *parent = it->parentItem();
int baseDirSize = (parent->type() == TestTreeItem::GroupNode) const FilePath baseDir = (parent->type() == TestTreeItem::GroupNode)
? parent->filePath().toString().size() : project->projectDirectory().toString().size(); ? parent->filePath()
return it->name().mid(baseDirSize + 1); : project->projectDirectory();
return it->filePath().relativePathFrom(baseDir).toUserOutput();
} }
QVariant CatchTreeItem::data(int column, int role) const QVariant CatchTreeItem::data(int column, int role) const

View File

@@ -109,7 +109,7 @@ QVariant GTestTreeItem::data(int column, int role) const
case Qt::ToolTipRole: case Qt::ToolTipRole:
if (type() == GroupNode if (type() == GroupNode
&& GTestFramework::staticGroupMode() == GTest::Constants::GTestFilter) { && GTestFramework::staticGroupMode() == GTest::Constants::GTestFilter) {
const auto tpl = QString("<p>%1</p><p>%2</p>").arg(filePath().toString()); const auto tpl = QString("<p>%1</p><p>%2</p>").arg(filePath().path());
return tpl.arg(Tr::tr("Change GTest filter in use inside the settings.")); return tpl.arg(Tr::tr("Change GTest filter in use inside the settings."));
} }
break; break;
@@ -535,9 +535,10 @@ bool GTestTreeItem::isGroupNodeFor(const TestTreeItem *other) const
QTC_ASSERT(false, return false); QTC_ASSERT(false, return false);
} }
// FIXME gtest filter is no FilePath // 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; return false;
bool matches = matchesFilter(filePath().toString(), fullName); bool matches = matchesFilter(filePath().path(), fullName);
return (matches && name() == matchingString()) return (matches && name() == matchingString())
|| (!matches && name() == notMatchingString()); || (!matches && name() == notMatchingString());
} }

View File

@@ -157,7 +157,7 @@ QString QuickTestParser::quickTestName(const CPlusPlus::Document::Ptr &doc) cons
QList<Document::Ptr> QuickTestParser::scanDirectoryForQuickTestQmlFiles(const FilePath &srcDir) QList<Document::Ptr> QuickTestParser::scanDirectoryForQuickTestQmlFiles(const FilePath &srcDir)
{ {
FilePaths dirs({srcDir}); FilePaths dirs({srcDir});
QStringList dirsStr({srcDir.toString()}); QStringList dirsStr({srcDir.path()});
ModelManagerInterface *qmlJsMM = QmlJSTools::Internal::ModelManager::instance(); ModelManagerInterface *qmlJsMM = QmlJSTools::Internal::ModelManager::instance();
// make sure even files not listed in pro file are available inside the snapshot // make sure even files not listed in pro file are available inside the snapshot
PathsAndLanguages paths; PathsAndLanguages paths;
@@ -165,15 +165,15 @@ QList<Document::Ptr> QuickTestParser::scanDirectoryForQuickTestQmlFiles(const Fi
ModelManagerInterface::importScan(ModelManagerInterface::workingCopy(), paths, qmlJsMM, ModelManagerInterface::importScan(ModelManagerInterface::workingCopy(), paths, qmlJsMM,
false /*emitDocumentChanges*/, false /*onlyTheLib*/, true /*forceRescan*/ ); false /*emitDocumentChanges*/, false /*onlyTheLib*/, true /*forceRescan*/ );
QDirIterator it(srcDir.toString(), srcDir.iterateDirectory(
QDir::Dirs | QDir::NoDotAndDotDot, [&dirs, &dirsStr](const FilePath &p) {
QDirIterator::Subdirectories); const FilePath &canonicalPath = p.canonicalPath();
while (it.hasNext()) { dirs.append(canonicalPath);
it.next(); dirsStr.append(canonicalPath.path());
auto subDir = FilePath::fromFileInfo(it.fileInfo()).canonicalPath(); return IterationPolicy::Continue;
dirs.append(subDir); },
dirsStr.append(subDir.toString()); FileFilter{{}, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories});
}
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this, dirsStr] { QuickTestParser::doUpdateWatchPaths(dirsStr); }, [this, dirsStr] { QuickTestParser::doUpdateWatchPaths(dirsStr); },

View File

@@ -377,7 +377,7 @@ QSet<QString> internalTargets(const FilePath &proFile)
for (const CppEditor::ProjectPart::ConstPtr &projectPart : projectInfo->projectParts()) { for (const CppEditor::ProjectPart::ConstPtr &projectPart : projectInfo->projectParts()) {
if (projectPart->buildTargetType != ProjectExplorer::BuildTargetType::Executable) if (projectPart->buildTargetType != ProjectExplorer::BuildTargetType::Executable)
continue; continue;
if (projectPart->projectFile != proFile.toString()) if (projectPart->projectFile != proFile.path())
continue; continue;
if (Utils::anyOf(projectPart->projectMacros, [](const ProjectExplorer::Macro &macro){ if (Utils::anyOf(projectPart->projectMacros, [](const ProjectExplorer::Macro &macro){
return macro.type == ProjectExplorer::MacroType::Define && return macro.type == ProjectExplorer::MacroType::Define &&

View File

@@ -86,7 +86,7 @@ static bool isLocal(Target *target)
static FilePath ensureExeEnding(const FilePath &file) 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;
return file.withExecutableSuffix(); return file.withExecutableSuffix();
} }
@@ -122,9 +122,11 @@ void TestConfiguration::completeTestInformation(RunConfiguration *rc,
FilePath buildBase; FilePath buildBase;
if (auto buildConfig = target->activeBuildConfiguration()) { if (auto buildConfig = target->activeBuildConfiguration()) {
buildBase = buildConfig->buildDirectory(); buildBase = buildConfig->buildDirectory();
const QString projBase = startupProject->projectDirectory().toString(); const FilePath projBase = startupProject->projectDirectory();
if (m_projectFile.startsWith(projBase)) if (m_projectFile.isChildOf(projBase)) {
m_buildDir = (buildBase / m_projectFile.toString().mid(projBase.length())).absolutePath(); m_buildDir
= (buildBase.resolvePath(m_projectFile.relativePathFrom(projBase))).absolutePath();
}
} }
if (runMode == TestRunMode::Debug || runMode == TestRunMode::DebugWithoutDeploy) if (runMode == TestRunMode::Debug || runMode == TestRunMode::DebugWithoutDeploy)
m_runConfig = new Internal::TestRunConfiguration(rc->target(), this); m_runConfig = new Internal::TestRunConfiguration(rc->target(), this);
@@ -188,9 +190,11 @@ void TestConfiguration::completeTestInformation(TestRunMode runMode)
FilePath buildBase; FilePath buildBase;
if (auto buildConfig = target->activeBuildConfiguration()) { if (auto buildConfig = target->activeBuildConfiguration()) {
buildBase = buildConfig->buildDirectory(); buildBase = buildConfig->buildDirectory();
const QString projBase = startupProject->projectDirectory().toString(); const FilePath projBase = startupProject->projectDirectory();
if (m_projectFile.startsWith(projBase)) if (m_projectFile.isChildOf(projBase)) {
m_buildDir = (buildBase / m_projectFile.toString().mid(projBase.length())).absolutePath(); m_buildDir
= (buildBase.resolvePath(m_projectFile.relativePathFrom(projBase))).absolutePath();
}
} }
// deployment information should get taken into account, but it pretty much seems as if // deployment information should get taken into account, but it pretty much seems as if

View File

@@ -527,8 +527,10 @@ void TestRunner::debugTests()
const FilePath &commandFilePath = config->executableFilePath(); const FilePath &commandFilePath = config->executableFilePath();
if (commandFilePath.isEmpty()) { if (commandFilePath.isEmpty()) {
reportResult(ResultType::MessageFatal, Tr::tr("Could not find command \"%1\". (%2)") reportResult(
.arg(config->executableFilePath().toString(), config->displayName())); ResultType::MessageFatal,
Tr::tr("Could not find command \"%1\". (%2)")
.arg(config->executableFilePath().toUserOutput(), config->displayName()));
onFinished(); onFinished();
return; return;
} }
@@ -573,7 +575,7 @@ void TestRunner::debugTests()
if (useOutputProcessor) { if (useOutputProcessor) {
TestOutputReader *outputreader = config->createOutputReader(nullptr); TestOutputReader *outputreader = config->createOutputReader(nullptr);
connect(outputreader, &TestOutputReader::newResult, this, &TestRunner::testResultReady); connect(outputreader, &TestOutputReader::newResult, this, &TestRunner::testResultReady);
outputreader->setId(inferior.command.executable().toString()); outputreader->setId(inferior.command.executable().toUserOutput());
connect(outputreader, &TestOutputReader::newOutputLineAvailable, connect(outputreader, &TestOutputReader::newOutputLineAvailable,
TestResultsPane::instance(), &TestResultsPane::addOutputLine); TestResultsPane::instance(), &TestResultsPane::addOutputLine);
connect(runControl, &RunControl::appendMessage, connect(runControl, &RunControl::appendMessage,
@@ -786,9 +788,10 @@ void RunConfigurationSelectionDialog::populate()
if (auto target = project->activeTarget()) { if (auto target = project->activeTarget()) {
for (RunConfiguration *rc : target->runConfigurations()) { for (RunConfiguration *rc : target->runConfigurations()) {
auto runnable = rc->runnable(); auto runnable = rc->runnable();
const QStringList rcDetails = { runnable.command.executable().toString(), const QStringList rcDetails
= {runnable.command.executable().toUserOutput(),
runnable.command.arguments(), runnable.command.arguments(),
runnable.workingDirectory.toString() }; runnable.workingDirectory.toUserOutput()};
m_rcCombo->addItem(rc->displayName(), rcDetails); m_rcCombo->addItem(rc->displayName(), rcDetails);
} }
} }

View File

@@ -50,7 +50,7 @@ QVariant ITestTreeItem::data(int /*column*/, int role) const
return Tr::tr("%1 (none)").arg(m_name); return Tr::tr("%1 (none)").arg(m_name);
return m_name; return m_name;
case Qt::ToolTipRole: case Qt::ToolTipRole:
return m_filePath.toString(); return m_filePath.toUserOutput();
case Qt::DecorationRole: case Qt::DecorationRole:
return testTreeIcon(m_type); return testTreeIcon(m_type);
case Qt::CheckStateRole: case Qt::CheckStateRole:
@@ -113,14 +113,13 @@ bool ITestTreeItem::lessThan(const ITestTreeItem *other, ITestTreeItem::SortMode
return lhs.compare(rhs, Qt::CaseInsensitive) > 0; return lhs.compare(rhs, Qt::CaseInsensitive) > 0;
case Naturally: { case Naturally: {
if (type() == GroupNode && other->type() == GroupNode) { if (type() == GroupNode && other->type() == GroupNode) {
return filePath().toString().compare(other->filePath().toString(), return filePath().path().compare(other->filePath().path(), Qt::CaseInsensitive) > 0;
Qt::CaseInsensitive) > 0;
} }
const Link &leftLink = data(0, LinkRole).value<Link>(); const Link &leftLink = data(0, LinkRole).value<Link>();
const Link &rightLink = other->data(0, LinkRole).value<Link>(); const Link &rightLink = other->data(0, LinkRole).value<Link>();
const int comparison = leftLink.targetFilePath.toString().compare( const int comparison = leftLink.targetFilePath.path()
rightLink.targetFilePath.toString(), Qt::CaseInsensitive); .compare(rightLink.targetFilePath.path(), Qt::CaseInsensitive);
if (comparison == 0) { if (comparison == 0) {
return leftLink.targetLine == rightLink.targetLine return leftLink.targetLine == rightLink.targetLine
? leftLink.targetColumn > rightLink.targetColumn ? leftLink.targetColumn > rightLink.targetColumn

View File

@@ -80,7 +80,7 @@ public:
ITestBase *testBase() const { return m_testBase; } ITestBase *testBase() const { return m_testBase; }
virtual bool lessThan(const ITestTreeItem *other, SortMode mode) const; 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: protected:
void setType(Type type) { m_type = type; } void setType(Type type) { m_type = type; }