[libcxx-commits] [PATCH] D98642: [libcxx] [test] Account for differences in a trailing slash in weakly_canonical

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 15 10:50:50 PDT 2021


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

This seems to be a "documented" quirk in libc++'s implementation of
weakly_canonical (in a fixme comment in the weakly_canonical test).
Together with a difference between windows and posix regarding whether
paths can go through nonexistent dirs, this results in a difference in
a trailing slash. Just document this as expected.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98642

Files:
  libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.exists/exists.pass.cpp
  libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.relative/relative.pass.cpp
  libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.weakly_canonical/weakly_canonical.pass.cpp


Index: libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.weakly_canonical/weakly_canonical.pass.cpp
===================================================================
--- libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.weakly_canonical/weakly_canonical.pass.cpp
+++ libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.weakly_canonical/weakly_canonical.pass.cpp
@@ -50,7 +50,14 @@
       {static_env.SymlinkToDir / "dir2/./", static_env.Dir / "dir2"},
       {static_env.SymlinkToDir / "dir2/DNE/./", static_env.Dir / "dir2/DNE/"},
       {static_env.SymlinkToDir / "dir2", static_env.Dir2},
+#ifdef _WIN32
+      // On windows, this path is considered to exist (even though it
+      // passes through a nonexistent directory), and thus is returned
+      // without a trailing slash, see the fixme above.
+      {static_env.SymlinkToDir / "dir2/../dir2/DNE/..", static_env.Dir2},
+#else
       {static_env.SymlinkToDir / "dir2/../dir2/DNE/..", static_env.Dir2 / ""},
+#endif
       {static_env.SymlinkToDir / "dir2/dir3/../DNE/DNE2", static_env.Dir2 / "DNE/DNE2"},
       {static_env.Dir / "../dir1", static_env.Dir},
       {static_env.Dir / "./.", static_env.Dir},
Index: libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.relative/relative.pass.cpp
===================================================================
--- libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.relative/relative.pass.cpp
+++ libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.relative/relative.pass.cpp
@@ -95,7 +95,18 @@
   static_test_env static_env;
   fs::path p(static_env.SymlinkToDir / "dir2/../dir2/DNE/..");
   const fs::path output = fs::weakly_canonical(p);
+  // weakly_canonical has a quirk - if the path is considered to exist,
+  // it's returned without a trailing slash, otherwise it's returned with
+  // one (see a FIXME comment in
+  // fs.op.weakly_canonical/weakly_canonical.pass.cpp). On windows, a path
+  // like existent/nonexistentsubdir/.. is considered to exist, on posix
+  // it's considered to not exist. Therefore, the result here differs in
+  // the trailing slash.
+#ifdef _WIN32
+  TEST_CHECK(output == fs::path::string_type(static_env.Dir2));
+#else
   TEST_CHECK(output == fs::path::string_type(static_env.Dir2 / ""));
+#endif
 }
 
 TEST_CASE(test_signature_10) {
Index: libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.exists/exists.pass.cpp
===================================================================
--- libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.exists/exists.pass.cpp
+++ libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.exists/exists.pass.cpp
@@ -66,6 +66,17 @@
     const path p = static_env.DNE;
     TEST_CHECK(exists(p) == false);
 
+    TEST_CHECK(exists(static_env.Dir) == true);
+    TEST_CHECK(exists(static_env.Dir / "dne") == false);
+    // Whether <dir>/dne/.. is considered to exist or not is not necessarily
+    // something we need to define, but the platform specific behaviour
+    // does affect a few other tests, so clarify the root cause here.
+#ifdef _WIN32
+    TEST_CHECK(exists(static_env.Dir / "dne" / "..") == true);
+#else
+    TEST_CHECK(exists(static_env.Dir / "dne" / "..") == false);
+#endif
+
     std::error_code ec = GetTestEC();
     TEST_CHECK(exists(p, ec) == false);
     TEST_CHECK(!ec);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98642.330728.patch
Type: text/x-patch
Size: 3352 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210315/ad3636ee/attachment-0001.bin>


More information about the libcxx-commits mailing list