[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

GitOrigin-RevId: f9ddb81d79b2c6d0cf7e509f04f70f5c0c0560b3
diff --git a/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/refresh.pass.cpp b/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/refresh.pass.cpp
index b0ec44a..8a98f3c 100644
--- a/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/refresh.pass.cpp
+++ b/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 @@
   }
 }
 
+#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_CHECK(!ent.exists());
   }
 }
+#endif
 
 void remove_if_exists(const fs::path& p) {
   std::error_code ec;
@@ -128,8 +130,10 @@
 
     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_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_CHECK_NO_THROW(ent_sym2);
   }
 }
+#endif
 
 TEST_CASE(refresh_doesnt_throw_on_dne_but_reports_it) {
   using namespace fs;
@@ -271,6 +281,9 @@
   }
 }
 
+#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 @@
   }
 #undef CHECK_ACCESS
 }
+#endif
 
 TEST_SUITE_END()
diff --git a/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/replace_filename.pass.cpp b/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/replace_filename.pass.cpp
index 13fe777..564e0e2 100644
--- a/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/replace_filename.pass.cpp
+++ b/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
-
 // <filesystem>
 
 // class directory_entry
@@ -125,6 +123,9 @@
   }
 }
 
+#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_CHECK(ErrorIs(ec, std::errc::permission_denied));
   }
 }
+#endif
 
 TEST_SUITE_END()
diff --git a/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp b/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp
index a57586f..02aea88 100644
--- a/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp
+++ b/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 @@
   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 @@
                              "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_CHECK(!ec);
     TEST_CHECK_NO_THROW(ent.file_size());
   }
+#endif
 }
 
 TEST_SUITE_END()
diff --git a/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_type_obs.pass.cpp b/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_type_obs.pass.cpp
index fbf1bec..541a6d9 100644
--- a/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_type_obs.pass.cpp
+++ b/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
-
 // <filesystem>
 
 // class directory_entry
@@ -207,6 +205,9 @@
   }
 }
 
+#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_CHECK(CheckEC(sym_status_ec));
   }
 }
+#endif
 
 TEST_SUITE_END()
diff --git a/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/hard_link_count.pass.cpp b/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/hard_link_count.pass.cpp
index bce2fce..92953f7 100644
--- a/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/hard_link_count.pass.cpp
+++ b/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 @@
   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 @@
                              "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_CHECK(!ec);
     TEST_CHECK_NO_THROW(ent.hard_link_count());
   }
+#endif
 }
 
 TEST_SUITE_END()
diff --git a/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/last_write_time.pass.cpp b/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/last_write_time.pass.cpp
index a812164..ea37812 100644
--- a/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/last_write_time.pass.cpp
+++ b/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 @@
   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 @@
                              "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_CHECK(!ec);
     TEST_CHECK_NO_THROW(ent.last_write_time());
   }
+#endif
 }
 
 TEST_SUITE_END()
diff --git a/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp b/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp
index f2fde11..4b8390e 100644
--- a/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp
+++ b/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
-
 // <filesystem>
 
 // class recursive_directory_iterator
@@ -142,6 +140,9 @@
     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 @@
       }
     }
 }
+#endif
 
 
 TEST_SUITE_END()
diff --git a/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directory/create_directory_with_attributes.pass.cpp b/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directory/create_directory_with_attributes.pass.cpp
index 353ecf8..a6eaddd 100644
--- a/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directory/create_directory_with_attributes.pass.cpp
+++ b/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_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 @@
     auto st = status(dir);
     TEST_CHECK(st.permissions() == perms::none);
 }
+#endif
 
 TEST_CASE(create_directory_multi_level)
 {
diff --git a/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp b/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
index 5c5a1e4..7893a0c 100644
--- a/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
+++ b/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
@@ -573,6 +573,9 @@
     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 @@
                              "last_write_time");
     TEST_CHECK_THROW_RESULT(filesystem_error, Checker, last_write_time(file));
 }
+#endif
 
 TEST_SUITE_END()
diff --git a/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove/remove.pass.cpp b/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove/remove.pass.cpp
index 017da8f..950ed73 100644
--- a/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove/remove.pass.cpp
+++ b/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
-
 // <filesystem>
 
 // bool remove(const path& p);
@@ -62,7 +60,13 @@
     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/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove_all/remove_all.pass.cpp b/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove_all/remove_all.pass.cpp
index c94726f..f99d2ae 100644
--- a/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove_all/remove_all.pass.cpp
+++ b/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
-
 // <filesystem>
 
 // uintmax_t remove_all(const path& p);
@@ -38,6 +36,10 @@
 
 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 @@
         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_CHECK(ec);
         TEST_CHECK(checkThrow(p, ec));
     }
+#endif
 
     // PR#35780
     const path testCasesNonexistant[] = {
diff --git a/test/std/input.output/filesystems/fs.op.funcs/fs.op.status/status.pass.cpp b/test/std/input.output/filesystems/fs.op.funcs/fs.op.status/status.pass.cpp
index 881ea16..3fa9f58 100644
--- a/test/std/input.output/filesystems/fs.op.funcs/fs.op.status/status.pass.cpp
+++ b/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
-
 // <filesystem>
 
 // file_status status(const path& p);
@@ -56,6 +54,12 @@
     }
 }
 
+// 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 @@
 #endif
     }
 }
+#endif
 
 TEST_CASE(status_file_types_test)
 {
diff --git a/test/std/input.output/filesystems/fs.op.funcs/fs.op.symlink_status/symlink_status.pass.cpp b/test/std/input.output/filesystems/fs.op.funcs/fs.op.symlink_status/symlink_status.pass.cpp
index 3976e69..a1d8ba6 100644
--- a/test/std/input.output/filesystems/fs.op.funcs/fs.op.symlink_status/symlink_status.pass.cpp
+++ b/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
-
 // <filesystem>
 
 // file_status symlink_status(const path& p);
@@ -55,6 +53,12 @@
     }
 }
 
+// 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_CHECK(st.permissions() != perms::unknown);
     }
 }
+#endif
 
 
 TEST_CASE(symlink_status_file_types_test)
diff --git a/test/support/test_macros.h b/test/support/test_macros.h
index f4d3ab6..82a8511 100644
--- a/test/support/test_macros.h
+++ b/test/support/test_macros.h
@@ -378,6 +378,10 @@
 #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