[libcxx-commits] [libcxx] 3784bdf - [libcxx] [test] Fix string type handling in a few fairly trivial class.path tests

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Fri Oct 16 11:04:52 PDT 2020


Author: Martin Storsjö
Date: 2020-10-16T21:04:23+03:00
New Revision: 3784bdf2176f38cc30134fab776efb43506c0c54

URL: https://github.com/llvm/llvm-project/commit/3784bdf2176f38cc30134fab776efb43506c0c54
DIFF: https://github.com/llvm/llvm-project/commit/3784bdf2176f38cc30134fab776efb43506c0c54.diff

LOG: [libcxx] [test] Fix string type handling in a few fairly trivial class.path tests

Use string() for convenience for testing where possible, but keep using
native() for move tests where we want to check that no allocations are
made, constructing a reference fs::path::string_type instead.

Use the right value_type in a few places.

Make the synop test check for the right types and for the expected
preferred separator.

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

Added: 
    

Modified: 
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/copy.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/move.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/copy.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/move.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/source.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/c_str.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/native.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/operator_string.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.io.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.nonmember/swap.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/synop.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/copy.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/copy.pass.cpp
index 04f30e13fbf8..a7182557d3f7 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/copy.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/copy.pass.cpp
@@ -29,8 +29,8 @@ int main(int, char**) {
   const path p(s);
   path p2;
   path& pref = (p2 = p);
-  assert(p.native() == s);
-  assert(p2.native() == s);
+  assert(p.string() == s);
+  assert(p2.string() == s);
   assert(&pref == &p2);
 
   return 0;

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/move.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/move.pass.cpp
index b31dab32c508..82f5248e9f31 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/move.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/move.pass.cpp
@@ -29,13 +29,14 @@ int main(int, char**) {
   const std::string s("we really really really really really really really "
                       "really really long string so that we allocate");
   assert(globalMemCounter.checkOutstandingNewEq(1));
+  const fs::path::string_type ps(s.begin(), s.end());
   path p(s);
   {
     DisableAllocationGuard g;
     path p2;
     path& pref = (p2 = std::move(p));
-    assert(p2.native() == s);
-    assert(p.native() != s); // Testing moved from state
+    assert(p2.native() == ps);
+    assert(p.native() != ps); // Testing moved from state
     assert(&pref == &p2);
   }
 

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/copy.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/copy.pass.cpp
index d78b3bf35de6..31d00ffd2cd3 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/copy.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/copy.pass.cpp
@@ -28,8 +28,8 @@ int main(int, char**) {
   const std::string s("foo");
   const path p(s);
   path p2(p);
-  assert(p.native() == s);
-  assert(p2.native() == s);
+  assert(p.string() == s);
+  assert(p2.string() == s);
 
   return 0;
 }

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/move.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/move.pass.cpp
index ae0183144f05..a0418d8661a4 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/move.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/move.pass.cpp
@@ -29,12 +29,13 @@ int main(int, char**) {
   const std::string s("we really really really really really really really "
                       "really really long string so that we allocate");
   assert(globalMemCounter.checkOutstandingNewEq(1));
+  const fs::path::string_type ps(s.begin(), s.end());
   path p(s);
   {
     DisableAllocationGuard g;
     path p2(std::move(p));
-    assert(p2.native() == s);
-    assert(p.native() != s); // Testing moved from state
+    assert(p2.native() == ps);
+    assert(p.native() != ps); // Testing moved from state
   }
 
   return 0;

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/source.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/source.pass.cpp
index 443aed75665b..ee4d2fe15262 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/source.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/source.pass.cpp
@@ -31,7 +31,7 @@
 template <class CharT, class ...Args>
 void RunTestCaseImpl(MultiStringType const& MS, Args... args) {
   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;

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/c_str.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/c_str.pass.cpp
index 36d931ad117d..0d17436e09c9 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/c_str.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/c_str.pass.cpp
@@ -28,6 +28,7 @@ int main(int, char**)
   using namespace fs;
   const char* const value = "hello world";
   const std::string str_value = value;
+  const fs::path::string_type pathstr_value(str_value.begin(), str_value.end());
   { // Check signature
     path p(value);
     ASSERT_SAME_TYPE(path::value_type const*, decltype(p.c_str()));
@@ -35,7 +36,7 @@ int main(int, char**)
   }
   {
     path p(value);
-    assert(p.c_str() == str_value);
+    assert(p.c_str() == pathstr_value);
     assert(p.native().c_str() == p.c_str());
   }
 

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/native.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/native.pass.cpp
index 74394e7e4305..2d41fc171c88 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/native.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/native.pass.cpp
@@ -26,6 +26,8 @@ int main(int, char**)
 {
   using namespace fs;
   const char* const value = "hello world";
+  std::string value_str(value);
+  fs::path::string_type pathstr_value(value_str.begin(), value_str.end());
   { // Check signature
     path p(value);
     ASSERT_SAME_TYPE(path::string_type const&, decltype(p.native()));
@@ -33,7 +35,7 @@ int main(int, char**)
   }
   { // native() is tested elsewhere
     path p(value);
-    assert(p.native() == value);
+    assert(p.native() == pathstr_value);
   }
 
   return 0;

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/operator_string.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/operator_string.pass.cpp
index a5b27b1622f8..70a36f2cb254 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/operator_string.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/operator_string.pass.cpp
@@ -28,6 +28,8 @@ int main(int, char**)
   using namespace fs;
   using string_type = path::string_type;
   const char* const value = "hello world";
+  std::string value_str(value);
+  fs::path::string_type pathstr_value(value_str.begin(), value_str.end());
   { // Check signature
     path p(value);
     static_assert(std::is_convertible<path, string_type>::value, "");
@@ -37,10 +39,10 @@ int main(int, char**)
   }
   {
     path p(value);
-    assert(p.native() == value);
+    assert(p.native() == pathstr_value);
     string_type s = p;
-    assert(s == value);
-    assert(p == value);
+    assert(s == pathstr_value);
+    assert(p == pathstr_value);
   }
 
   return 0;

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.io.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.io.pass.cpp
index 7b0a83afd7b6..982a7a97fe04 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.io.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.io.pass.cpp
@@ -53,7 +53,7 @@ void doIOTest() {
   { // test input
     path p_in;
     auto& ret = ss >> p_in;
-    assert(p_in.native() == (const char*)InStr);
+    assert(p_in.native() == (const path::value_type*)InStr);
     assert(&ret == &ss);
   }
 }

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/swap.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/swap.pass.cpp
index 27317e248c09..4e175ba0cf3c 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/swap.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/swap.pass.cpp
@@ -29,6 +29,8 @@ int main(int, char**)
   const char* value2 = "_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG";
   path p1(value1);
   path p2(value2);
+  fs::path::string_type ps1 = p1.native();
+  fs::path::string_type ps2 = p2.native();
   {
     using namespace std; using namespace fs;
     ASSERT_NOEXCEPT(swap(p1, p2));
@@ -39,11 +41,11 @@ int main(int, char**)
     using namespace std;
     using namespace fs;
     swap(p1, p2);
-    assert(p1.native() == value2);
-    assert(p2.native() == value1);
+    assert(p1.native() == ps2);
+    assert(p2.native() == ps1);
     swap(p1, p2);
-    assert(p1.native() == value1);
-    assert(p2.native() == value2);
+    assert(p1.native() == ps1);
+    assert(p2.native() == ps2);
   }
 
   return 0;

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/synop.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/synop.pass.cpp
index 1b6280a62d8b..e9e0a990165a 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/synop.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/synop.pass.cpp
@@ -25,13 +25,21 @@
 
 int main(int, char**) {
   using namespace fs;
+#ifdef _WIN32
+  ASSERT_SAME_TYPE(path::value_type, wchar_t);
+#else
   ASSERT_SAME_TYPE(path::value_type, char);
+#endif
   ASSERT_SAME_TYPE(path::string_type, std::basic_string<path::value_type>);
   {
     ASSERT_SAME_TYPE(const path::value_type, decltype(path::preferred_separator));
+#ifdef _WIN32
+    static_assert(path::preferred_separator == '\\', "");
+#else
     static_assert(path::preferred_separator == '/', "");
+#endif
     // Make preferred_separator ODR used by taking its address.
-    const char* dummy = &path::preferred_separator;
+    const path::value_type* dummy = &path::preferred_separator;
     ((void)dummy);
   }
 


        


More information about the libcxx-commits mailing list