[libcxx-commits] [libcxx] 68de58c - [libcxx] [test] Fix filesystem permission tests for windows
Martin Storsjö via libcxx-commits
libcxx-commits at lists.llvm.org
Tue May 11 10:46:09 PDT 2021
Author: Martin Storsjö
Date: 2021-05-11T20:43:24+03:00
New Revision: 68de58cd649cb3a3e94a1c9552ebf2a18bb9d040
URL: https://github.com/llvm/llvm-project/commit/68de58cd649cb3a3e94a1c9552ebf2a18bb9d040
DIFF: https://github.com/llvm/llvm-project/commit/68de58cd649cb3a3e94a1c9552ebf2a18bb9d040.diff
LOG: [libcxx] [test] Fix filesystem permission tests for windows
On Windows, the permission bits are mapped down to essentially only
two possible states; readonly or readwrite. Normalize the checked
permission bitmask to match what the implementation will return.
Differential Revision: https://reviews.llvm.org/D101728
Added:
Modified:
libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp
libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.permissions/permissions.pass.cpp
libcxx/test/support/filesystem_test_helper.h
Removed:
################################################################################
diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp
index 913d5333ece0d..4e40906a8d848 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp
@@ -8,8 +8,6 @@
// UNSUPPORTED: c++03
-// XFAIL: LIBCXX-WINDOWS-FIXME
-
// The string reported on errors changed, which makes those tests fail when run
// against already-released libc++'s.
// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.15
@@ -114,7 +112,7 @@ TEST_CASE(test_attributes_get_copied) {
TEST_REQUIRE(fs::copy_file(file, dest, ec) == true);
TEST_CHECK(!ec);
auto new_st = status(dest);
- TEST_CHECK(new_st.permissions() == new_perms);
+ TEST_CHECK(new_st.permissions() == NormalizeExpectedPerms(new_perms));
}
TEST_CASE(copy_dir_test) {
diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.permissions/permissions.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.permissions/permissions.pass.cpp
index aa2e0920bc48e..14a288f3e3338 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.permissions/permissions.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.permissions/permissions.pass.cpp
@@ -8,8 +8,6 @@
// UNSUPPORTED: c++03
-// XFAIL: LIBCXX-WINDOWS-FIXME
-
// <filesystem>
// void permissions(const path& p, perms prms,
@@ -128,18 +126,22 @@ TEST_CASE(basic_permissions_test)
permissions(TC.p, TC.set_perms, TC.opts, ec);
TEST_CHECK(!ec);
auto pp = status(TC.p).permissions();
- TEST_CHECK(pp == TC.expected);
+ TEST_CHECK(pp == NormalizeExpectedPerms(TC.expected));
}
if (TC.opts == perm_options::replace) {
std::error_code ec = GetTestEC();
permissions(TC.p, TC.set_perms, ec);
TEST_CHECK(!ec);
auto pp = status(TC.p).permissions();
- TEST_CHECK(pp == TC.expected);
+ TEST_CHECK(pp == NormalizeExpectedPerms(TC.expected));
}
}
}
+#ifndef _WIN32
+// This test isn't currently meaningful on Windows; the Windows file
+// permissions visible via std::filesystem doesn't show any
diff erence
+// between owner/group/others.
TEST_CASE(test_no_resolve_symlink_on_symlink)
{
scoped_test_env env;
@@ -182,5 +184,6 @@ TEST_CASE(test_no_resolve_symlink_on_symlink)
TEST_CHECK(symlink_status(sym).permissions() == expected_link_perms);
}
}
+#endif
TEST_SUITE_END()
diff --git a/libcxx/test/support/filesystem_test_helper.h b/libcxx/test/support/filesystem_test_helper.h
index 1e102f3f53100..611daed85affe 100644
--- a/libcxx/test/support/filesystem_test_helper.h
+++ b/libcxx/test/support/filesystem_test_helper.h
@@ -600,6 +600,23 @@ inline bool PathEqIgnoreSep(fs::path LHS, fs::path RHS) {
return LHS.native() == RHS.native();
}
+inline fs::perms NormalizeExpectedPerms(fs::perms P) {
+#ifdef _WIN32
+ // On Windows, fs::perms only maps down to one bit stored in the filesystem,
+ // a boolean readonly flag.
+ // Normalize permissions to the format it gets returned; all fs entries are
+ // read+exec for all users; writable ones also have the write bit set for
+ // all users.
+ P |= fs::perms::owner_read | fs::perms::group_read | fs::perms::others_read;
+ P |= fs::perms::owner_exec | fs::perms::group_exec | fs::perms::others_exec;
+ fs::perms Write =
+ fs::perms::owner_write | fs::perms::group_write | fs::perms::others_write;
+ if ((P & Write) != fs::perms::none)
+ P |= Write;
+#endif
+ return P;
+}
+
struct ExceptionChecker {
std::errc expected_err;
fs::path expected_path1;
More information about the libcxx-commits
mailing list