[PATCH] Fix filesystem::path tests

2019-04-30 Thread Jonathan Wakely

The root_path.cc test had some debugging macros left in accidentally, so
didn't FAIL correctly if an assertion failed.

The string-char8_t.cc tests didn't compile on Windows.

* testsuite/27_io/filesystem/path/decompose/root_path.cc: Remove
macros accidentally left in.
* testsuite/27_io/filesystem/path/native/string-char8_t.cc: Remove
unnecessary -lstdc++fs option. Fix test for mingw.
* testsuite/experimental/filesystem/path/native/string-char8_t.cc:
Fix test for mingw.

Tested x86_64-linux and x86_64-w64-mingw32, committed to trunk.


commit 4c493a0cb94c9f9d7131c7f7c37f2b321fc12559
Author: Jonathan Wakely 
Date:   Tue Apr 30 11:23:02 2019 +0100

Fix filesystem::path tests

The root_path.cc test had some debugging macros left in accidentally, so
didn't FAIL correctly if an assertion failed.

The string-char8_t.cc tests didn't compile on Windows.

* testsuite/27_io/filesystem/path/decompose/root_path.cc: Remove
macros accidentally left in.
* testsuite/27_io/filesystem/path/native/string-char8_t.cc: Remove
unnecessary -lstdc++fs option. Fix test for mingw.
* testsuite/experimental/filesystem/path/native/string-char8_t.cc:
Fix test for mingw.

diff --git 
a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc 
b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc
index 4f4c531819f..d573b4899c0 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc
@@ -35,10 +35,6 @@ test01()
   VERIFY( p2.root_path() == path("/") );
 }
 
-#undef VERIFY
-#define VERIFY(X) do { if (!(X)) { __builtin_puts("FAIL: " #X); } } 
while(false)
-#define DUMP(X, Y, Z) do { if (!(Y == Z)) { __builtin_printf("%s %s %s\n", 
X.c_str(), Y.c_str(), Z.c_str()); } } while(false)
-
 void
 test02()
 {
@@ -48,7 +44,6 @@ test02()
 path rootn = p.root_name();
 path rootd = p.root_directory();
 VERIFY( rootp == (rootn / rootd) );
-DUMP(p,  rootp , (rootn / rootd) );
   }
 }
 
diff --git 
a/libstdc++-v3/testsuite/27_io/filesystem/path/native/string-char8_t.cc 
b/libstdc++-v3/testsuite/27_io/filesystem/path/native/string-char8_t.cc
index f5bb1afca5d..d333787a71e 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/native/string-char8_t.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/native/string-char8_t.cc
@@ -15,7 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-// { dg-options "-std=gnu++17 -lstdc++fs -fchar8_t" }
+// { dg-options "-std=gnu++17 -fchar8_t" }
 // { dg-do run { target c++17 } }
 // { dg-require-filesystem-ts "" }
 
@@ -27,14 +27,15 @@ void
 test01()
 {
   using namespace std::filesystem;
-  const std::string s = "abc";
+  using string_type = std::basic_string;
+  const string_type s{ 'a', 'b', 'c' };
   path p(s);
 
   VERIFY( p.native() == s );
   VERIFY( p.c_str() == s );
-  VERIFY( static_cast(p) == s );
+  VERIFY( static_cast(p) == s );
 
-  std::string s2 = p; // implicit conversion
+  string_type s2 = p; // implicit conversion
   VERIFY( s2 == p.native() );
 }
 
diff --git 
a/libstdc++-v3/testsuite/experimental/filesystem/path/native/string-char8_t.cc 
b/libstdc++-v3/testsuite/experimental/filesystem/path/native/string-char8_t.cc
index a0d8058bdfc..091663f4e82 100644
--- 
a/libstdc++-v3/testsuite/experimental/filesystem/path/native/string-char8_t.cc
+++ 
b/libstdc++-v3/testsuite/experimental/filesystem/path/native/string-char8_t.cc
@@ -27,14 +27,15 @@ void
 test01()
 {
   using namespace std::experimental::filesystem;
-  const std::string s = "abc";
+  using string_type = std::basic_string;
+  const string_type s{ 'a', 'b', 'c' };
   path p(s);
 
   VERIFY( p.native() == s );
   VERIFY( p.c_str() == s );
-  VERIFY( static_cast(p) == s );
+  VERIFY( static_cast(p) == s );
 
-  std::string s2 = p; // implicit conversion
+  string_type s2 = p; // implicit conversion
   VERIFY( s2 == p.native() );
 }
 


[PATCH] Fix filesystem::path tests that fail on Windows

2018-12-20 Thread Jonathan Wakely

* testsuite/27_io/filesystem/operations/proximate.cc: Fix test for
MinGW.
* testsuite/27_io/filesystem/path/append/source.cc: Likewise.
* testsuite/27_io/filesystem/path/compare/lwg2936.cc: Likewise.

Tested x86_64-linux and mingw-w64, committed to trunk.


commit 2ca9c650bb91616a8c24ece0df1fdd812d785a21
Author: Jonathan Wakely 
Date:   Thu Dec 20 17:57:31 2018 +

Fix filesystem::path tests that fail on Windows

* testsuite/27_io/filesystem/operations/proximate.cc: Fix test for
MinGW.
* testsuite/27_io/filesystem/path/append/source.cc: Likewise.
* testsuite/27_io/filesystem/path/compare/lwg2936.cc: Likewise.

diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/proximate.cc 
b/libstdc++-v3/testsuite/27_io/filesystem/operations/proximate.cc
index 457cd2d0641..980161c9ead 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/proximate.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/proximate.cc
@@ -26,15 +26,27 @@
 using std::filesystem::proximate;
 using __gnu_test::compare_paths;
 
+// Normalize directory-separators
+std::string operator""_norm(const char* s, std::size_t n)
+{
+  std::string str(s, n);
+#if defined(__MING32__) || defined(__MINGW64__)
+  for (auto& c : str)
+if (c == '/')
+  c = '\\';
+#endif
+  return str;
+}
+
 void
 test01()
 {
-  compare_paths( proximate("/a/d", "/a/b/c"), "../../d" );
-  compare_paths( proximate("/a/b/c", "/a/d"), "../b/c" );
-  compare_paths( proximate("a/b/c", "a"), "b/c" );
-  compare_paths( proximate("a/b/c", "a/b/c/x/y"), "../.." );
+  compare_paths( proximate("/a/d", "/a/b/c"), "../../d"_norm );
+  compare_paths( proximate("/a/b/c", "/a/d"), "../b/c"_norm );
+  compare_paths( proximate("a/b/c", "a"), "b/c"_norm );
+  compare_paths( proximate("a/b/c", "a/b/c/x/y"), "../.."_norm );
   compare_paths( proximate("a/b/c", "a/b/c"), "." );
-  compare_paths( proximate("a/b", "c/d"), "../../a/b" );
+  compare_paths( proximate("a/b", "c/d"), "../../a/b"_norm );
 }
 
 void
@@ -42,22 +54,22 @@ test02()
 {
   const std::error_code bad_ec = make_error_code(std::errc::invalid_argument);
   std::error_code ec = bad_ec;
-  compare_paths( proximate("/a/d", "/a/b/c", ec), "../../d" );
+  compare_paths( proximate("/a/d", "/a/b/c", ec), "../../d"_norm );
   VERIFY( !ec );
   ec = bad_ec;
-  compare_paths( proximate("/a/b/c", "/a/d", ec), "../b/c" );
+  compare_paths( proximate("/a/b/c", "/a/d", ec), "../b/c"_norm );
   VERIFY( !ec );
   ec = bad_ec;
-  compare_paths( proximate("a/b/c", "a", ec), "b/c" );
+  compare_paths( proximate("a/b/c", "a", ec), "b/c"_norm );
   VERIFY( !ec );
   ec = bad_ec;
-  compare_paths( proximate("a/b/c", "a/b/c/x/y", ec), "../.." );
+  compare_paths( proximate("a/b/c", "a/b/c/x/y", ec), "../.."_norm );
   VERIFY( !ec );
   ec = bad_ec;
   compare_paths( proximate("a/b/c", "a/b/c", ec), "." );
   VERIFY( !ec );
   ec = bad_ec;
-  compare_paths( proximate("a/b", "c/d", ec), "../../a/b" );
+  compare_paths( proximate("a/b", "c/d", ec), "../../a/b"_norm );
   VERIFY( !ec );
 }
 
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc 
b/libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc
index 21ae6be3d97..578d1350178 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc
@@ -120,24 +120,31 @@ test05()
   path p = "0/1/2/3/4/5/6";
   // The string_view aliases the path's internal string:
   s = p.native();
+  path::string_type expected(s);
+  expected += path::preferred_separator;
+  expected += s;
   // Append that string_view, which must work correctly even though the
   // internal string will be reallocated during the operation:
   p /= s;
-  VERIFY( p.string() == "0/1/2/3/4/5/6/0/1/2/3/4/5/6" );
+  compare_paths(p, expected);
 
   // Same again with a trailing slash:
   path p2 = "0/1/2/3/4/5/";
   s = p2.native();
+  expected = s;
+  expected += s;
   p2 /= s;
-  VERIFY( p2.string() == "0/1/2/3/4/5/0/1/2/3/4/5/" );
+  compare_paths(p2, expected);
 
   // And aliasing one of the components of the path:
   path p3 = "0/123456789/a";
   path::iterator second = std::next(p3.begin());
   s = second->native();
+  expected = p3.native() + path::preferred_separator;
+  expected += s;
   p3 /= s;
-  VERIFY( p3.string() == "0/123456789/a/123456789" );
-  }
+  compare_paths(p3, expected);
+}
 
 void
 test06()
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/lwg2936.cc 
b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/lwg2936.cc
index 8a11043f143..a62f01c3fb6 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/lwg2936.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/lwg2936.cc
@@ -60,7 +60,11 @@ test01()
   check("c:", "d:", -1);
   check("c:", "c:/", -1);
   check("d:", "c:/", +1);
+#if defined(__MING32__) || defined(__MINGW64__)
+  check("c:/a/b", "c:a/b", +1);
+#els