From c50891611aaab863b239dc1081c1a6201b8d43e9 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 11 Oct 2022 15:50:42 +0200 Subject: [PATCH] FilePath: Fix absoluteFilePath to behave like absolutePath Change-Id: Ibb2cba32c40ec9febab5f20c78156481525c8904 Reviewed-by: hjk --- src/libs/utils/filepath.cpp | 4 +- tests/auto/utils/fileutils/tst_fileutils.cpp | 46 ++++++++++++++------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 80035ac504f..8110cd9d34c 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -785,9 +785,9 @@ FilePath FilePath::absolutePath() const FilePath FilePath::absoluteFilePath() const { if (isAbsolutePath()) - return *this; + return cleanPath(); if (!needsDevice() && isEmpty()) - return *this; + return cleanPath(); return FilePath::currentWorkingPath().resolvePath(*this); } diff --git a/tests/auto/utils/fileutils/tst_fileutils.cpp b/tests/auto/utils/fileutils/tst_fileutils.cpp index 0522b320575..0248fb44891 100644 --- a/tests/auto/utils/fileutils/tst_fileutils.cpp +++ b/tests/auto/utils/fileutils/tst_fileutils.cpp @@ -46,8 +46,8 @@ private slots: void relativePath_data(); void relativePath(); - void absoluteFilePath_data(); - void absoluteFilePath(); + void absolute_data(); + void absolute(); void fromToString_data(); void fromToString(); @@ -379,26 +379,46 @@ void tst_fileutils::schemeAndHostLength() QCOMPARE(actual, result); } -void tst_fileutils::absoluteFilePath_data() +void tst_fileutils::absolute_data() { QTest::addColumn("path"); - QTest::addColumn("result"); + QTest::addColumn("absoluteFilePath"); + QTest::addColumn("absolutePath"); - QTest::newRow("absolute1") << FilePath::fromString("/") << FilePath::fromString("/"); - QTest::newRow("absolute2") << FilePath::fromString("C:/a/b") << FilePath::fromString("C:/a/b"); - QTest::newRow("absolute3") << FilePath::fromString("/a/b") << FilePath::fromString("/a/b"); - QTest::newRow("default-constructed") << FilePath() << FilePath(); + QTest::newRow("absolute1") << FilePath::fromString("/") + << FilePath::fromString("/") + << FilePath::fromString("/"); + QTest::newRow("absolute2") << FilePath::fromString("C:/a/b") + << FilePath::fromString("C:/a/b") + << FilePath::fromString("C:/a"); + QTest::newRow("absolute3") << FilePath::fromString("/a/b") + << FilePath::fromString("/a/b") + << FilePath::fromString("/a"); + QTest::newRow("absolute4") << FilePath::fromString("/a/b/..") + << FilePath::fromString("/a") + << FilePath::fromString("/"); + QTest::newRow("absolute5") << FilePath::fromString("/a/b/c/../d") + << FilePath::fromString("/a/b/d") + << FilePath::fromString("/a/b"); + QTest::newRow("absolute6") << FilePath::fromString("/a/../b/c/d") + << FilePath::fromString("/b/c/d") + << FilePath::fromString("/b/c"); + QTest::newRow("default-constructed") << FilePath() << FilePath() << FilePath(); QTest::newRow("relative") << FilePath::fromString("a/b") - << FilePath::fromString(QDir::currentPath() + "/a/b"); + << FilePath::fromString(QDir::currentPath() + "/a/b") + << FilePath::fromString(QDir::currentPath() + "/a"); QTest::newRow("qrc") << FilePath::fromString(":/foo/bar.txt") - << FilePath::fromString(":/foo/bar.txt"); + << FilePath::fromString(":/foo/bar.txt") + << FilePath::fromString(":/foo"); } -void tst_fileutils::absoluteFilePath() +void tst_fileutils::absolute() { QFETCH(FilePath, path); - QFETCH(FilePath, result); - QCOMPARE(path.absoluteFilePath(), result); + QFETCH(FilePath, absoluteFilePath); + QFETCH(FilePath, absolutePath); + QCOMPARE(path.absoluteFilePath(), absoluteFilePath); + QCOMPARE(path.absolutePath(), absolutePath); } void tst_fileutils::toString_data()