From 9605577ed8e3bf6a0f11c17e6960ea90022f9367 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 7 Sep 2023 12:12:49 +0200 Subject: [PATCH] fixed #11926 (Treat MacOS filesystem as case insensitive) / TestPath: added more tests --- lib/path.cpp | 6 ++++-- releasenotes.txt | 3 ++- test/testpath.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/lib/path.cpp b/lib/path.cpp index 500542e73430..078c6997d3b3 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 4d75b6445976..b5ff62b87995 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 ebd79a8a604d..3806a0571330 100644 --- a/test/testpath.cpp +++ b/test/testpath.cpp @@ -42,6 +42,8 @@ class TestPath : public TestFixture { TEST_CASE(join); TEST_CASE(isDirectory); TEST_CASE(isFile); + TEST_CASE(sameFileName); + TEST_CASE(getFilenameExtension); } void removeQuotationMarks() const { @@ -176,6 +178,53 @@ class TestPath : public TestFixture { 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)