From f9ddb81d79b2c6d0cf7e509f04f70f5c0c0560b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 26 Feb 2021 12:56:41 +0200 Subject: [PATCH] [libcxx] [test] Ifdef out tests that rely on perms::none on directories for triggering errors On Windows, one can't use perms::none on a directory to trigger failures to read the directory entries. These remaining tests can't use GetWindowsInaccessibleDir() sensibly, e.g. for tests that rely on toggling accessibility back and forth during the test, or where the semantics of the dir provided by GetWindowsInaccessibleDir() doesn't allow for running the ifdeffed tests meaningfully. Differential Revision: https://reviews.llvm.org/D97538 --- .../directory_entry.mods/refresh.pass.cpp | 18 ++++++++++++++++-- .../replace_filename.pass.cpp | 6 ++++-- .../directory_entry.obs/file_size.pass.cpp | 8 ++++++-- .../directory_entry.obs/file_type_obs.pass.cpp | 6 ++++-- .../hard_link_count.pass.cpp | 8 ++++++-- .../last_write_time.pass.cpp | 8 ++++++-- .../rec.dir.itr.members/increment.pass.cpp | 6 ++++-- .../create_directory_with_attributes.pass.cpp | 5 +++-- .../last_write_time.pass.cpp | 4 ++++ .../fs.op.funcs/fs.op.remove/remove.pass.cpp | 8 ++++++-- .../fs.op.remove_all/remove_all.pass.cpp | 8 +++++--- .../fs.op.funcs/fs.op.status/status.pass.cpp | 9 +++++++-- .../symlink_status.pass.cpp | 9 +++++++-- libcxx/test/support/test_macros.h | 4 ++++ 14 files changed, 82 insertions(+), 25 deletions(-) diff --git a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/refresh.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/refresh.pass.cpp index b0ec44ace6ac..8a98f3cb7193 100644 --- a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/refresh.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/refresh.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: with_system_cxx_lib=macosx10.15 @@ -66,6 +64,9 @@ TEST_CASE(test_refresh_ec_method) { } } +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE +// Windows doesn't support setting perms::none to trigger failures +// reading directories. TEST_CASE(refresh_on_file_dne) { using namespace fs; scoped_test_env env; @@ -100,6 +101,7 @@ TEST_CASE(refresh_on_file_dne) { TEST_CHECK(!ent.exists()); } } +#endif void remove_if_exists(const fs::path& p) { std::error_code ec; @@ -128,8 +130,10 @@ TEST_CASE(refresh_on_bad_symlink) { LIBCPP_ONLY(permissions(dir, perms::none)); TEST_CHECK(ent.is_symlink()); +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE TEST_CHECK(!ent.is_regular_file()); TEST_CHECK(!ent.exists()); +#endif } permissions(dir, old_perms); env.create_file("dir/file", 101); @@ -147,10 +151,15 @@ TEST_CASE(refresh_on_bad_symlink) { TEST_CHECK(!ec); // we don't report bad symlinks as an error. LIBCPP_ONLY(permissions(dir, perms::none)); +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE TEST_CHECK(!ent.exists()); +#endif } } +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE +// Windows doesn't support setting perms::none to trigger failures +// reading directories. TEST_CASE(refresh_cannot_resolve) { using namespace fs; scoped_test_env env; @@ -224,6 +233,7 @@ TEST_CASE(refresh_cannot_resolve) { TEST_CHECK_NO_THROW(ent_sym2); } } +#endif TEST_CASE(refresh_doesnt_throw_on_dne_but_reports_it) { using namespace fs; @@ -271,6 +281,9 @@ TEST_CASE(refresh_doesnt_throw_on_dne_but_reports_it) { } } +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE +// Windows doesn't support setting perms::none to trigger failures +// reading directories. TEST_CASE(access_cache_after_refresh_fails) { using namespace fs; scoped_test_env env; @@ -342,5 +355,6 @@ TEST_CASE(access_cache_after_refresh_fails) { } #undef CHECK_ACCESS } +#endif TEST_SUITE_END() diff --git a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/replace_filename.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/replace_filename.pass.cpp index 13fe77787ccd..564e0e21ad6c 100644 --- a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/replace_filename.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/replace_filename.pass.cpp @@ -8,8 +8,6 @@ // UNSUPPORTED: c++03 -// XFAIL: LIBCXX-WINDOWS-FIXME - // // class directory_entry @@ -125,6 +123,9 @@ TEST_CASE(test_replace_filename_calls_refresh) { } } +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE +// Windows doesn't support setting perms::none to trigger failures +// reading directories. TEST_CASE(test_replace_filename_propagates_error) { using namespace fs; scoped_test_env env; @@ -167,5 +168,6 @@ TEST_CASE(test_replace_filename_propagates_error) { TEST_CHECK(ErrorIs(ec, std::errc::permission_denied)); } } +#endif TEST_SUITE_END() diff --git a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp index a57586ff6609..02aea88ca2ae 100644 --- a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.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: with_system_cxx_lib=macosx10.15 @@ -126,7 +124,9 @@ TEST_CASE(error_reporting) { const path sym_out_of_dir = env.create_symlink("dir/file", "sym"); const path sym_in_dir = env.create_symlink("file2", "dir/sym2"); +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE const perms old_perms = status(dir).permissions(); +#endif // test a file which doesn't exist { @@ -169,6 +169,9 @@ TEST_CASE(error_reporting) { "directory_entry::file_size"); TEST_CHECK_THROW_RESULT(filesystem_error, Checker, ent.file_size()); } + // Windows doesn't support setting perms::none to trigger failures + // reading directories. +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE // test a file w/o appropriate permissions. { directory_entry ent; @@ -245,6 +248,7 @@ TEST_CASE(error_reporting) { TEST_CHECK(!ec); TEST_CHECK_NO_THROW(ent.file_size()); } +#endif } TEST_SUITE_END() diff --git a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_type_obs.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_type_obs.pass.cpp index fbf1bec73e11..541a6d9c9ffb 100644 --- a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_type_obs.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_type_obs.pass.cpp @@ -8,8 +8,6 @@ // UNSUPPORTED: c++03 -// XFAIL: LIBCXX-WINDOWS-FIXME - // // class directory_entry @@ -207,6 +205,9 @@ TEST_CASE(test_with_ec_dne) { } } +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE +// Windows doesn't support setting perms::none to trigger failures +// reading directories. TEST_CASE(test_with_ec_cannot_resolve) { using namespace fs; using fs::directory_entry; @@ -269,5 +270,6 @@ TEST_CASE(test_with_ec_cannot_resolve) { TEST_CHECK(CheckEC(sym_status_ec)); } } +#endif TEST_SUITE_END() diff --git a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/hard_link_count.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/hard_link_count.pass.cpp index bce2fce917c4..92953f70b6e7 100644 --- a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/hard_link_count.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/hard_link_count.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: with_system_cxx_lib=macosx10.15 @@ -129,7 +127,9 @@ TEST_CASE(error_reporting) { const path sym_out_of_dir = env.create_symlink("dir/file", "sym"); const path sym_in_dir = env.create_symlink("file2", "dir/sym2"); +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE const perms old_perms = status(dir).permissions(); +#endif // test a file which doesn't exist { @@ -173,6 +173,9 @@ TEST_CASE(error_reporting) { "directory_entry::hard_link_count"); TEST_CHECK_THROW_RESULT(filesystem_error, Checker, ent.hard_link_count()); } + // Windows doesn't support setting perms::none to trigger failures + // reading directories. +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE // test a file w/o appropriate permissions. { directory_entry ent; @@ -250,6 +253,7 @@ TEST_CASE(error_reporting) { TEST_CHECK(!ec); TEST_CHECK_NO_THROW(ent.hard_link_count()); } +#endif } TEST_SUITE_END() diff --git a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/last_write_time.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/last_write_time.pass.cpp index a81216491d34..ea37812ca989 100644 --- a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/last_write_time.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/last_write_time.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: with_system_cxx_lib=macosx10.15 @@ -98,7 +96,9 @@ TEST_CASE(error_reporting) { const path sym_out_of_dir = env.create_symlink("dir/file", "sym"); const path sym_in_dir = env.create_symlink("file2", "dir/sym2"); +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE const perms old_perms = status(dir).permissions(); +#endif // test a file which doesn't exist { @@ -141,6 +141,9 @@ TEST_CASE(error_reporting) { "directory_entry::last_write_time"); TEST_CHECK_THROW_RESULT(filesystem_error, Checker, ent.last_write_time()); } + // Windows doesn't support setting perms::none to trigger failures + // reading directories. +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE // test a file w/o appropriate permissions. { directory_entry ent; @@ -218,6 +221,7 @@ TEST_CASE(error_reporting) { TEST_CHECK(!ec); TEST_CHECK_NO_THROW(ent.last_write_time()); } +#endif } TEST_SUITE_END() diff --git a/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp b/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp index f2fde11ddb16..4b8390e2a125 100644 --- a/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp @@ -8,8 +8,6 @@ // UNSUPPORTED: c++03 -// XFAIL: LIBCXX-WINDOWS-FIXME - // // class recursive_directory_iterator @@ -142,6 +140,9 @@ TEST_CASE(test_follow_symlinks) TEST_CHECK(it == endIt); } +// Windows doesn't support setting perms::none to trigger failures +// reading directories. +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE TEST_CASE(access_denied_on_recursion_test_case) { using namespace fs; @@ -492,6 +493,7 @@ TEST_CASE(test_PR35078_with_symlink_file) } } } +#endif TEST_SUITE_END() diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directory/create_directory_with_attributes.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directory/create_directory_with_attributes.pass.cpp index 353ecf873f46..a6eaddda38cd 100644 --- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directory/create_directory_with_attributes.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directory/create_directory_with_attributes.pass.cpp @@ -8,8 +8,6 @@ // UNSUPPORTED: c++03 -// XFAIL: LIBCXX-WINDOWS-FIXME - // This test requires the dylib support introduced in D92769. // XFAIL: with_system_cxx_lib=macosx10.15 @@ -60,6 +58,8 @@ TEST_CASE(create_existing_directory) TEST_CHECK(fs::create_directory(dir, dir2) == false); } +// Windows doesn't have the concept of perms::none on directories. +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE TEST_CASE(create_directory_one_level) { scoped_test_env env; @@ -79,6 +79,7 @@ TEST_CASE(create_directory_one_level) auto st = status(dir); TEST_CHECK(st.permissions() == perms::none); } +#endif TEST_CASE(create_directory_multi_level) { diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp index 5c5a1e4dafe6..7893a0c79a20 100644 --- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp @@ -573,6 +573,9 @@ TEST_CASE(test_value_on_failure) TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory)); } +// Windows doesn't support setting perms::none to trigger failures +// reading directories. +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE TEST_CASE(test_exists_fails) { scoped_test_env env; @@ -588,5 +591,6 @@ TEST_CASE(test_exists_fails) "last_write_time"); TEST_CHECK_THROW_RESULT(filesystem_error, Checker, last_write_time(file)); } +#endif TEST_SUITE_END() diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove/remove.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove/remove.pass.cpp index 017da8f8c611..950ed732307b 100644 --- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove/remove.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove/remove.pass.cpp @@ -8,8 +8,6 @@ // UNSUPPORTED: c++03 -// XFAIL: LIBCXX-WINDOWS-FIXME - // // bool remove(const path& p); @@ -62,7 +60,13 @@ TEST_CASE(test_error_reporting) permissions(bad_perms_dir, perms::none); const path testCases[] = { non_empty_dir, +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE + // Windows doesn't support setting perms::none on a directory to + // stop it from being accessed. And a fictional file under + // GetWindowsInaccessibleDir() doesn't cause fs::remove() to report + // errors, it just returns false cleanly. file_in_bad_dir, +#endif }; for (auto& p : testCases) { std::error_code ec; diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove_all/remove_all.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove_all/remove_all.pass.cpp index c94726fff555..f99d2ae6f87f 100644 --- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove_all/remove_all.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove_all/remove_all.pass.cpp @@ -8,8 +8,6 @@ // UNSUPPORTED: c++03 -// XFAIL: LIBCXX-WINDOWS-FIXME - // // uintmax_t remove_all(const path& p); @@ -38,6 +36,10 @@ TEST_CASE(test_signatures) TEST_CASE(test_error_reporting) { + scoped_test_env env; + // Windows doesn't support setting perms::none to trigger failures + // reading directories. +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE auto checkThrow = [](path const& f, const std::error_code& ec) { #ifndef TEST_HAS_NO_EXCEPTIONS @@ -54,7 +56,6 @@ TEST_CASE(test_error_reporting) return true; #endif }; - scoped_test_env env; const path non_empty_dir = env.create_dir("dir"); env.create_file(non_empty_dir / "file1", 42); const path bad_perms_dir = env.create_dir("bad_dir"); @@ -74,6 +75,7 @@ TEST_CASE(test_error_reporting) TEST_CHECK(ec); TEST_CHECK(checkThrow(p, ec)); } +#endif // PR#35780 const path testCasesNonexistant[] = { diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.status/status.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.status/status.pass.cpp index 881ea162e505..3fa9f58b77b9 100644 --- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.status/status.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.status/status.pass.cpp @@ -8,8 +8,6 @@ // UNSUPPORTED: c++03 -// XFAIL: LIBCXX-WINDOWS-FIXME - // // file_status status(const path& p); @@ -56,6 +54,12 @@ TEST_CASE(test_status_not_found) } } +// Windows doesn't support setting perms::none to trigger failures +// reading directories. Imaginary files under GetWindowsInaccessibleDir() +// produce no_such_file_or_directory, not the error codes this test checks +// for. Finally, status() for a too long file name doesn't return errors +// on windows. +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE TEST_CASE(test_status_cannot_resolve) { scoped_test_env env; @@ -98,6 +102,7 @@ TEST_CASE(test_status_cannot_resolve) #endif } } +#endif TEST_CASE(status_file_types_test) { diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.symlink_status/symlink_status.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.symlink_status/symlink_status.pass.cpp index 3976e69d2c5d..a1d8ba6e09fc 100644 --- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.symlink_status/symlink_status.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.symlink_status/symlink_status.pass.cpp @@ -8,8 +8,6 @@ // UNSUPPORTED: c++03 -// XFAIL: LIBCXX-WINDOWS-FIXME - // // file_status symlink_status(const path& p); @@ -55,6 +53,12 @@ TEST_CASE(test_symlink_status_not_found) } } +// Windows doesn't support setting perms::none to trigger failures +// reading directories. Imaginary files under GetWindowsInaccessibleDir() +// produce no_such_file_or_directory, not the error codes this test checks +// for. Finally, status() for a too long file name doesn't return errors +// on windows. +#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE TEST_CASE(test_symlink_status_cannot_resolve) { scoped_test_env env; @@ -105,6 +109,7 @@ TEST_CASE(test_symlink_status_cannot_resolve) TEST_CHECK(st.permissions() != perms::unknown); } } +#endif TEST_CASE(symlink_status_file_types_test) diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h index f4d3ab60807c..82a8511ecf59 100644 --- a/libcxx/test/support/test_macros.h +++ b/libcxx/test/support/test_macros.h @@ -378,6 +378,10 @@ inline void DoNotOptimize(Tp const& value) { #define TEST_NOT_WIN32(...) __VA_ARGS__ #endif +#ifdef _WIN32 +#define TEST_WIN_NO_FILESYSTEM_PERMS_NONE +#endif + #if defined(__GNUC__) #pragma GCC diagnostic pop #endif