[libcxx-commits] [libcxx] 81db3c3 - [libcxx] [test] Fix all remaining issues with fs::path::string_type being wstring

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 19 14:07:39 PDT 2020


Author: Martin Storsjö
Date: 2020-10-20T00:07:02+03:00
New Revision: 81db3c31aafec72f1cfec2a9da4381ece7f97a29

URL: https://github.com/llvm/llvm-project/commit/81db3c31aafec72f1cfec2a9da4381ece7f97a29
DIFF: https://github.com/llvm/llvm-project/commit/81db3c31aafec72f1cfec2a9da4381ece7f97a29.diff

LOG: [libcxx] [test] Fix all remaining issues with fs::path::string_type being wstring

Use fs::path as variable type instead of std::string, when the input
potentially is a path, as they can't be implicitly converted back to
string.

Differential Revision: https://reviews.llvm.org/D89674

Added: 
    

Modified: 
    libcxx/test/std/input.output/filesystems/class.path/path.itr/iterator.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/braced_init.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/source.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_normal.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp
    libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp
    libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.absolute/absolute.pass.cpp
    libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
    libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.proximate/proximate.pass.cpp
    libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.space/space.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.weakly_canonical/weakly_canonical.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.itr/iterator.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.itr/iterator.pass.cpp
index db3b54f8766b..f5a1ddd6f5bc 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.itr/iterator.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.itr/iterator.pass.cpp
@@ -49,7 +49,11 @@ void checkIteratorConcepts() {
     ASSERT_SAME_TYPE(It, decltype(it--));
     ASSERT_SAME_TYPE(Traits::reference, decltype(*it));
     ASSERT_SAME_TYPE(Traits::pointer, decltype(it.operator->()));
+#ifdef _WIN32
+    ASSERT_SAME_TYPE(std::wstring const&, decltype(it->native()));
+#else
     ASSERT_SAME_TYPE(std::string const&, decltype(it->native()));
+#endif
     ASSERT_SAME_TYPE(bool, decltype(it == it));
     ASSERT_SAME_TYPE(bool, decltype(it != it));
   }

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/braced_init.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/braced_init.pass.cpp
index 9cece85e33c0..55c0d7a17244 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/braced_init.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/braced_init.pass.cpp
@@ -26,7 +26,11 @@ int main(int, char**) {
   using namespace fs;
   path p("abc");
   p = {};
+#ifdef _WIN32
+  assert(p.native() == L"");
+#else
   assert(p.native() == "");
+#endif
 
   return 0;
 }

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/source.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/source.pass.cpp
index 2ada91354b51..e66df6e302a2 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/source.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/source.pass.cpp
@@ -35,7 +35,7 @@
 template <class CharT>
 void RunTestCase(MultiStringType const& MS) {
   using namespace fs;
-  const char* Expect = MS;
+  const fs::path::value_type* Expect = MS;
   const CharT* TestPath = MS;
   const CharT* TestPathEnd = StrEnd(TestPath);
   const std::size_t Size = TestPathEnd - TestPath;
@@ -211,9 +211,9 @@ void test_sfinae() {
   }
 }
 
-void RunStringMoveTest(const char* Expect) {
+void RunStringMoveTest(const fs::path::value_type* Expect) {
   using namespace fs;
-  std::string ss(Expect);
+  fs::path::string_type ss(Expect);
   path p;
   {
     DisableAllocationGuard g; ((void)g);

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp
index bbc77e5be208..ff3a2d531a26 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp
@@ -55,8 +55,8 @@
 #include "verbose_assert.h"
 
 struct ComparePathExact {
-  bool operator()(std::string const& LHS, std::string const& RHS) const {
-    return LHS == RHS;
+  bool operator()(fs::path const& LHS, std::string const& RHS) const {
+    return LHS.string() == RHS;
   }
 };
 

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_normal.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_normal.pass.cpp
index 2d04964651c3..ce784dd8a98d 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_normal.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_normal.pass.cpp
@@ -131,7 +131,7 @@ int main(int, char**) {
                   "  Input: '%s'\n"
                   "  Expected: '%s'\n"
                   "  Output: '%s'\n",
-        ID, TC.input.c_str(), TC.expect.c_str(), output.native().c_str());
+        ID, TC.input.c_str(), TC.expect.c_str(), output.string().c_str());
     }
   }
   return Failed;

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp
index e2ca99402e3f..4f9e9b83d4f6 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp
@@ -69,7 +69,7 @@ int main(int, char**) {
                   "  Expected: '%s'\n"
                   "  Output: '%s'\n",
         ID, Testing, TC.input.c_str(), TC.base.c_str(),
-        Expected.c_str(), Output.native().c_str());
+        Expected.string().c_str(), Output.string().c_str());
     };
     if (!PathEq(output, TC.expect))
       ReportErr("path::lexically_relative", output, TC.expect);

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 be7b2dc2cb86..60f3c6a7175f 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
@@ -314,7 +314,7 @@ TEST_CASE(test_PR35078)
       ExceptionChecker Checker(std::errc::permission_denied,
                                "recursive_directory_iterator::operator++()",
                                format_string("attempting recursion into \"%s\"",
-                                             nestedDir.native()));
+                                             nestedDir.string().c_str()));
       TEST_CHECK_THROW_RESULT(filesystem_error, Checker, ++it);
     }
 }

diff  --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.absolute/absolute.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.absolute/absolute.pass.cpp
index ecb46320d184..335ba06b64aa 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.absolute/absolute.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.absolute/absolute.pass.cpp
@@ -38,7 +38,7 @@ TEST_CASE(basic_test)
     const fs::path cwd = fs::current_path();
     const struct {
       std::string input;
-      std::string expect;
+      fs::path expect;
     } TestCases [] = {
         {"", cwd / ""},
         {"foo", cwd / "foo"},

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 c24d28b341c9..d3841f5406c8 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
@@ -106,7 +106,7 @@ struct Times {
 
 Times GetTimes(path const& p) {
     StatT st;
-    if (::stat(p.c_str(), &st) == -1) {
+    if (::stat(p.string().c_str(), &st) == -1) {
         std::error_code ec(errno, std::generic_category());
 #ifndef TEST_HAS_NO_EXCEPTIONS
         throw ec;
@@ -123,7 +123,7 @@ TimeSpec LastWriteTime(path const& p) { return GetTimes(p).write; }
 
 Times GetSymlinkTimes(path const& p) {
   StatT st;
-  if (::lstat(p.c_str(), &st) == -1) {
+  if (::lstat(p.string().c_str(), &st) == -1) {
     std::error_code ec(errno, std::generic_category());
 #ifndef TEST_HAS_NO_EXCEPTIONS
         throw ec;
@@ -395,7 +395,7 @@ TEST_CASE(get_last_write_time_dynamic_env_test)
     SleepFor(Sec(2));
 
     // update file and add a file to the directory. Make sure the times increase.
-    std::FILE* of = std::fopen(file.c_str(), "a");
+    std::FILE* of = std::fopen(file.string().c_str(), "a");
     std::fwrite("hello", 1, sizeof("hello"), of);
     std::fclose(of);
     env.create_file("dir/file1", 1);

diff  --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.proximate/proximate.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.proximate/proximate.pass.cpp
index 31c64088cd5c..944092fa4ff0 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.proximate/proximate.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.proximate/proximate.pass.cpp
@@ -60,9 +60,9 @@ TEST_CASE(basic_test) {
   path relative_cwd = cwd.native().substr(1);
   // clang-format off
   struct {
-    std::string input;
-    std::string base;
-    std::string expect;
+    fs::path input;
+    fs::path base;
+    fs::path expect;
   } TestCases[] = {
       {"", "", "."},
       {cwd, "a", ".."},
@@ -104,7 +104,8 @@ TEST_CASE(basic_test) {
                   "  Input: '%s'\n"
                   "  Base: '%s'\n"
                   "  Expected: '%s'\n",
-        ID, TC.input.c_str(), TC.base.c_str(), TC.expect.c_str());
+        ID, TC.input.string().c_str(), TC.base.string().c_str(),
+        TC.expect.string().c_str());
     } else if (!PathEq(output, TC.expect)) {
       TEST_CHECK(PathEq(output, TC.expect));
 
@@ -119,9 +120,10 @@ TEST_CASE(basic_test) {
                   "  Lex Prox: '%s'\n"
                   "  Canon Input: '%s'\n"
                   "  Canon Base: '%s'\n",
-        ID, TC.input.c_str(), TC.base.c_str(), TC.expect.c_str(),
-        output.native().c_str(), lexically_p.native().c_str(),
-        canon_input.c_str(), canon_base.c_str());
+        ID, TC.input.string().c_str(), TC.base.string().c_str(),
+        TC.expect.string().c_str(), output.string().c_str(),
+        lexically_p.string().c_str(), canon_input.string().c_str(),
+        canon_base.string().c_str());
     }
   }
 }

diff  --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.space/space.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.space/space.pass.cpp
index 38ce958da501..f607b44e544d 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.space/space.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.space/space.pass.cpp
@@ -86,7 +86,7 @@ TEST_CASE(basic_space_test)
     // should have the same expected result. Compute this expected result
     // one and check that it looks semi-sane.
     struct statvfs expect;
-    TEST_REQUIRE(::statvfs(static_env.Dir.c_str(), &expect) != -1);
+    TEST_REQUIRE(::statvfs(static_env.Dir.string().c_str(), &expect) != -1);
     TEST_CHECK(expect.f_bavail > 0);
     TEST_CHECK(expect.f_bfree > 0);
     TEST_CHECK(expect.f_bsize > 0);

diff  --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp
index 40481f15e2b1..d9d25c8df138 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp
@@ -25,8 +25,8 @@
 
 using namespace fs;
 
-void PutEnv(std::string var, std::string value) {
-    assert(::setenv(var.c_str(), value.c_str(), /* overwrite */ 1) == 0);
+void PutEnv(std::string var, fs::path value) {
+    assert(::setenv(var.c_str(), value.string().c_str(), /* overwrite */ 1) == 0);
 }
 
 void UnsetEnv(std::string var) {

diff  --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.weakly_canonical/weakly_canonical.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.weakly_canonical/weakly_canonical.pass.cpp
index c2409a4ffdcb..08d963fe6652 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.weakly_canonical/weakly_canonical.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.weakly_canonical/weakly_canonical.pass.cpp
@@ -29,8 +29,8 @@ int main(int, char**) {
 
   // clang-format off
   struct {
-    std::string input;
-    std::string expect;
+    fs::path input;
+    fs::path expect;
   } TestCases[] = {
       {"", fs::current_path()},
       {".", fs::current_path()},
@@ -69,7 +69,8 @@ int main(int, char**) {
                   "  Input: '%s'\n"
                   "  Expected: '%s'\n"
                   "  Output: '%s'\n",
-        ID, TC.input.c_str(), TC.expect.c_str(), output.native().c_str());
+        ID, TC.input.string().c_str(), TC.expect.string().c_str(),
+        output.string().c_str());
     }
   }
   return Failed;


        


More information about the libcxx-commits mailing list