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.
Details
- Reviewers
curdeius • Quuxplusone Mordante - Group Reviewers
Restricted Project - Commits
- rG68de58cd649c: [libcxx] [test] Fix filesystem permission tests for windows
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libcxx/test/support/filesystem_test_helper.h | ||
---|---|---|
621 | I guess it can be argued that we should normalize both operands, as it's not evident to the callers about which parameter is which. But by only normalizing the expectation, we keep the test a bit stronger. But I can be convinced otherwise too. |
LGTM % comment.
libcxx/test/support/filesystem_test_helper.h | ||
---|---|---|
621 | If you're only normalizing one side, I'd name the function PermsNormalizeExpected (since you could perhaps have chosen to implement a PermsNormalizeActual instead). However, it's also a function with only one caller, so I'd actually inline it. I'd say inline bool PermsEq(fs::perms Actual, fs::perms Expected) { #ifdef _WIN32 // On Windows, fs::perms maps down to one bit stored in the filesystem, // a boolean readonly flag. // Normalize the expected permissions to the format that is returned: // all files are read+exec for all users; writable files are writable for all users. Expected |= fs::perms::owner_read | fs::perms::group_read | fs::perms::others_read; Expected |= fs::perms::owner_exec | fs::perms::group_exec | fs::perms::others_exec; if (Expected & (fs::perms::owner_write | fs::perms::group_write | fs::perms::others_write)) Expected |= fs::perms::owner_write | fs::perms::group_write | fs::perms::others_write; #endif return Actual == Expected; } |
libcxx/test/support/filesystem_test_helper.h | ||
---|---|---|
621 | Sure, I can inline it.
Hmm, so no change wrt that as we'd inline it? Should we name the comparison function in a way to highlight this too, e.g. PermsEqNormalizeExpected (which is a mouthful...)? The tricky thing is that it's not clear to the callers which argument is which. |
libcxx/test/support/filesystem_test_helper.h | ||
---|---|---|
621 | Meh. It has only a few callers, so IMHO the approach I presented for PermsEq is fine. TEST_CHECK(pp == NormalizeExpectedPerms(TC.expected)); at the call-sites. |
libcxx/test/support/filesystem_test_helper.h | ||
---|---|---|
621 | Ah, that's probably even clearer, I'll update to that form in a moment. |
Removed the unnecessary PermsEq, renamed the normalize function to NormalizeExpectedPerms.
LGTM, one small question.
libcxx/test/support/filesystem_test_helper.h | ||
---|---|---|
614 | Is it specified which of the 3 write flags Windows sets when a file isn't read-only? Or should it set all 3 of them? |
libcxx/test/support/filesystem_test_helper.h | ||
---|---|---|
614 | I'm not sure if there's a spec somewhere; MSVC's STL sets all three in sync, and libc++ does the same. As we check whether our normalized expected flags are equal to what the implementation sets, this test will show if an implementation returns something else. |
Is it specified which of the 3 write flags Windows sets when a file isn't read-only? Or should it set all 3 of them?