From 57f3186ee2f1e389925516e0e513f99b34755776 Mon Sep 17 00:00:00 2001 From: Steffen Schuemann Date: Sat, 13 Feb 2021 05:08:24 +0100 Subject: [PATCH] refs #97, on posix backend hard links tests are now validated against lstat result to support results from btrfs --- test/filesystem_test.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index 651f45b..e5308a5 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -2019,6 +2019,15 @@ TEST_CASE("30.10.15.14 file_size", "[filesystem][operations][fs.op.file_size]") ec.clear(); } +#ifndef GHC_OS_WINDOWS +static uintmax_t getHardlinkCount(const fs::path& p) +{ + struct stat st = {}; + auto rc = ::lstat(p.c_str(), &st); + return rc == 0 ? st.st_nlink : ~0; +} +#endif + TEST_CASE("30.10.15.15 hard_link_count", "[filesystem][operations][fs.op.hard_link_count]") { #ifndef GHC_OS_WEB @@ -2034,9 +2043,9 @@ TEST_CASE("30.10.15.15 hard_link_count", "[filesystem][operations][fs.op.hard_li // unix/bsd/linux typically implements "."/".." as hardlinks // so an empty dir has 2 (from parent and the ".") and // adding a subdirectory adds one due to its ".." - CHECK(fs::hard_link_count(t.path()) == 2); + CHECK(fs::hard_link_count(t.path()) == getHardlinkCount(t.path())); fs::create_directory("dir"); - CHECK(fs::hard_link_count(t.path()) == 3); + CHECK(fs::hard_link_count(t.path()) == getHardlinkCount(t.path())); #endif generateFile("foo"); CHECK(fs::hard_link_count(t.path() / "foo") == 1);