[libcxx-commits] [PATCH] D98443: [libcxx] [test] Use GetWindowsInaccessibleDir() in a couple more tests

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 11 11:45:05 PST 2021


mstorsjo created this revision.
mstorsjo requested review of this revision.
Herald added a project: libc++.
Herald added a reviewer: libc++.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98443

Files:
  libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/assign.pass.cpp
  libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/ctor.pass.cpp
  libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp


Index: libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp
===================================================================
--- libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp
+++ libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp
@@ -47,9 +47,18 @@
     scoped_test_env env;
     const path dne = env.make_env_path("dne");
     const path file = env.create_file("file", 42);
+#ifdef _WIN32
+    // Windows doesn't support setting perms::none to trigger failures
+    // reading directories; test using a special inaccessible directory
+    // instead.
+    const path dir = GetWindowsInaccessibleDir();
+    TEST_REQUIRE(!dir.empty());
+    const path nested_dir = dir / "inaccessible_dir";
+#else
     const path dir_perms = env.create_dir("bad_perms_dir");
     const path nested_dir = env.create_dir("bad_perms_dir/nested");
     permissions(dir_perms, perms::none);
+#endif
     LIBCPP_ONLY(const std::errc expect_errc = std::errc::not_a_directory);
     struct TestCase {
       std::string name;
@@ -93,7 +102,11 @@
         PutEnv(TC.name, nested_dir);
         ec = GetTestEC();
         ret = temp_directory_path(ec);
+#ifdef _WIN32
+        TEST_CHECK(ErrorIs(ec, std::errc::not_a_directory));
+#else
         TEST_CHECK(ErrorIs(ec, std::errc::permission_denied));
+#endif
         TEST_CHECK(ret == "");
 
         // Set the env variable to point to a non-existent dir
Index: libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/ctor.pass.cpp
===================================================================
--- libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/ctor.pass.cpp
+++ libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/ctor.pass.cpp
@@ -133,12 +133,21 @@
 TEST_CASE(access_denied_to_file_test_case)
 {
     using namespace fs;
+#ifdef _WIN32
+    // Windows doesn't support setting perms::none to trigger failures
+    // reading directories; test using a special inaccessible directory
+    // instead.
+    const path testDir = GetWindowsInaccessibleDir();
+    TEST_REQUIRE(!testDir.empty());
+    path const testFile = testDir / "inaccessible_file";
+#else
     scoped_test_env env;
     path const testFile = env.make_env_path("file1");
     env.create_file(testFile, 42);
 
     // Change the permissions so we can no longer iterate
     permissions(testFile, perms::none);
+#endif
 
     // Check that the construction fails when skip_permissions_denied is
     // not given.
Index: libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/assign.pass.cpp
===================================================================
--- libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/assign.pass.cpp
+++ libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/assign.pass.cpp
@@ -100,6 +100,18 @@
 TEST_CASE(test_assign_propagates_error) {
   using namespace fs;
   scoped_test_env env;
+#ifdef _WIN32
+  const path dir = GetWindowsInaccessibleDir();
+  TEST_REQUIRE(!dir.empty());
+  const path file = dir / "inaccessible_file";
+  const path sym_out_of_dir = env.create_symlink(file, "sym");
+  {
+    directory_entry ent;
+    std::error_code ec = GetTestEC();
+    ent.assign(file, ec);
+    TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));
+  }
+#else
   const path dir = env.create_dir("dir");
   const path file = env.create_file("dir/file", 42);
   const path sym_out_of_dir = env.create_symlink("dir/file", "sym");
@@ -120,6 +132,7 @@
     ent.assign(sym_in_dir, ec);
     TEST_CHECK(ErrorIs(ec, std::errc::permission_denied));
   }
+#endif
   {
     directory_entry ent;
     std::error_code ec = GetTestEC();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98443.330041.patch
Type: text/x-patch
Size: 3893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210311/ad81fcf3/attachment.bin>


More information about the libcxx-commits mailing list