From 3cbbb77335f057ed6a65e83847f2b768b11fd382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Fri, 8 Sep 2023 17:33:37 +0200 Subject: [PATCH] fixed #11926 (Treat MacOS filesystem as case insensitive) / TestPath: added more tests (#5412) --- lib/path.cpp | 6 ++++-- releasenotes.txt | 3 ++- test/testpath.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/lib/path.cpp b/lib/path.cpp index 500542e73..078c6997d 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -46,9 +46,11 @@ /** Is the filesystem case insensitive? */ -static bool caseInsensitiveFilesystem() +static constexpr bool caseInsensitiveFilesystem() { -#ifdef _WIN32 +#if defined(_WIN32) || (defined(__APPLE__) && defined(__MACH__)) + // Windows is case insensitive + // MacOS is case insensitive by default (also supports case sensitivity) return true; #else // TODO: Non-windows filesystems might be case insensitive diff --git a/releasenotes.txt b/releasenotes.txt index 4d75b6445..b5ff62b87 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -25,4 +25,5 @@ Deprecations: Other: - "USE_QT6=On" will no longer fallback to Qt5 when Qt6 is not found. - When the execution of an addon fails with an exitcode it will now result in an 'internalError' instead of being silently ignored. -- "Win32" configurations have been removed from the bundled Visual Studio solution and projects. You might still be able to build 32-bit binaries using CMake but that is untested and unmaintained. \ No newline at end of file +- "Win32" configurations have been removed from the bundled Visual Studio solution and projects. You might still be able to build 32-bit binaries using CMake but that is untested and unmaintained. +- The MacOS filesystem is now treated as case insensitive. \ No newline at end of file diff --git a/test/testpath.cpp b/test/testpath.cpp index ebd79a8a6..2150f5ee7 100644 --- a/test/testpath.cpp +++ b/test/testpath.cpp @@ -42,6 +42,8 @@ private: TEST_CASE(join); TEST_CASE(isDirectory); TEST_CASE(isFile); + TEST_CASE(sameFileName); + TEST_CASE(getFilenameExtension); } void removeQuotationMarks() const { @@ -123,7 +125,7 @@ private: ASSERT(Path::isC("C:\\foo\\index.c")); // In unix .C is considered C++ -#ifdef _WIN32 +#if defined(_WIN32) || (defined(__APPLE__) && defined(__MACH__)) ASSERT_EQUALS(true, Path::isC("C:\\foo\\index.C")); #else ASSERT_EQUALS(false, Path::isC("C:\\foo\\index.C")); @@ -134,7 +136,7 @@ private: ASSERT(Path::isCPP("index.c")==false); // In unix .C is considered C++ -#ifdef _WIN32 +#if defined(_WIN32) || (defined(__APPLE__) && defined(__MACH__)) ASSERT_EQUALS(false, Path::isCPP("index.C")); #else ASSERT_EQUALS(true, Path::isCPP("index.C")); @@ -176,6 +178,53 @@ private: ASSERT_EQUALS(true, Path::isFile("testpath/testpath.txt")); ASSERT_EQUALS(true, Path::isFile("testpath2.txt")); } + + void sameFileName() const { + ASSERT(Path::sameFileName("test", "test")); + + // case sensitivity cases +#if defined(_WIN32) || (defined(__APPLE__) && defined(__MACH__)) + ASSERT(Path::sameFileName("test", "Test")); + ASSERT(Path::sameFileName("test", "TesT")); + ASSERT(Path::sameFileName("test.h", "test.H")); + ASSERT(Path::sameFileName("test.hh", "test.Hh")); + ASSERT(Path::sameFileName("test.hh", "test.hH")); +#else + ASSERT(!Path::sameFileName("test", "Test")); + ASSERT(!Path::sameFileName("test", "TesT")); + ASSERT(!Path::sameFileName("test.h", "test.H")); + ASSERT(!Path::sameFileName("test.hh", "test.Hh")); + ASSERT(!Path::sameFileName("test.hh", "test.hH")); +#endif + } + + void getFilenameExtension() const { + ASSERT_EQUALS("", Path::getFilenameExtension("test")); + ASSERT_EQUALS("", Path::getFilenameExtension("Test")); + ASSERT_EQUALS(".h", Path::getFilenameExtension("test.h")); + ASSERT_EQUALS(".h", Path::getFilenameExtension("Test.h")); + ASSERT_EQUALS("", Path::getFilenameExtension("test", true)); + ASSERT_EQUALS("", Path::getFilenameExtension("Test", true)); + ASSERT_EQUALS(".h", Path::getFilenameExtension("test.h", true)); + ASSERT_EQUALS(".h", Path::getFilenameExtension("Test.h", true)); + + // case sensitivity cases +#if defined(_WIN32) || (defined(__APPLE__) && defined(__MACH__)) + ASSERT_EQUALS(".h", Path::getFilenameExtension("test.H")); + ASSERT_EQUALS(".hh", Path::getFilenameExtension("test.Hh")); + ASSERT_EQUALS(".hh", Path::getFilenameExtension("test.hH")); + ASSERT_EQUALS(".h", Path::getFilenameExtension("test.H", true)); + ASSERT_EQUALS(".hh", Path::getFilenameExtension("test.Hh", true)); + ASSERT_EQUALS(".hh", Path::getFilenameExtension("test.hH", true)); +#else + ASSERT_EQUALS(".H", Path::getFilenameExtension("test.H")); + ASSERT_EQUALS(".Hh", Path::getFilenameExtension("test.Hh")); + ASSERT_EQUALS(".hH", Path::getFilenameExtension("test.hH")); + ASSERT_EQUALS(".h", Path::getFilenameExtension("test.H", true)); + ASSERT_EQUALS(".hh", Path::getFilenameExtension("test.Hh", true)); + ASSERT_EQUALS(".hh", Path::getFilenameExtension("test.hH", true)); +#endif + } }; REGISTER_TEST(TestPath)