From fa37dc67546db83520620ec00edb5e2a35bb40bb Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Tue, 28 Aug 2018 18:40:24 +0100 Subject: [PATCH] Add more tests to verify std::filesystem behaviour --- src/tests/api/internals/main.cpp | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/tests/api/internals/main.cpp b/src/tests/api/internals/main.cpp index 60ea14cc..5074ba32 100644 --- a/src/tests/api/internals/main.cpp +++ b/src/tests/api/internals/main.cpp @@ -151,6 +151,66 @@ TEST(Filesystem, shouldBeAbleToWriteToAndReadFromAUtf8Path) { std::filesystem::remove(path); } +TEST(Filesystem, equalityShouldBeCaseSensitive) { + auto upper = std::filesystem::path("LICENSE"); + auto lower = std::filesystem::path("license"); + + EXPECT_NE(lower, upper); +} + +#ifdef _WIN32 +TEST(Filesystem, equivalentShouldRequireThatBothPathsExist) { + auto upper = std::filesystem::path("LICENSE"); + auto lower = std::filesystem::path("license2"); + + EXPECT_THROW(std::filesystem::equivalent(lower, upper), std::filesystem::filesystem_error); +} +#else +TEST(Filesystem, equivalentShouldNotRequireThatBothPathsExist) { + auto upper = std::filesystem::path("LICENSE"); + auto lower = std::filesystem::path("license2"); + + EXPECT_FALSE(std::filesystem::equivalent(lower, upper)); +} +#endif + +TEST(Filesystem, canonicalShouldRequireThatThePathExists) { + EXPECT_THROW(std::filesystem::canonical("license2"), std::filesystem::filesystem_error); +} + +#ifdef _WIN32 +TEST(Filesystem, equivalentShouldBeCaseInsensitive) { + auto upper = std::filesystem::path("LICENSE"); + auto lower = std::filesystem::path("license"); + + EXPECT_TRUE(std::filesystem::equivalent(lower, upper)); +} + +TEST(Filesystem, canonicalShouldFoldCase) { + auto upper = std::filesystem::canonical("LICENSE"); + auto lower = std::filesystem::canonical("license"); + + EXPECT_EQ(lower, upper); +} +#else +TEST(Filesystem, equivalentShouldBeCaseSensitive) { + auto upper = std::filesystem::path("LICENSE"); + auto lower = std::filesystem::path("license"); + + EXPECT_FALSE(std::filesystem::equivalent(lower, upper)); +} + +TEST(Filesystem, canonicalShouldNotFoldCase) { + std::ofstream out("license"); + out.close(); + + auto upper = std::filesystem::canonical("LICENSE"); + auto lower = std::filesystem::canonical("license"); + + EXPECT_NE(lower, upper); +} +#endif + int main(int argc, char **argv) { // Set the locale to get encoding conversions working correctly. std::locale::global(boost::locale::generator().generate(""));