]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix filesystem::path tests that fail on Windows
authorJonathan Wakely <jwakely@redhat.com>
Thu, 20 Dec 2018 18:12:11 +0000 (18:12 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 20 Dec 2018 18:12:11 +0000 (18:12 +0000)
* 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.

From-SVN: r267308

libstdc++-v3/ChangeLog
libstdc++-v3/testsuite/27_io/filesystem/operations/proximate.cc
libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc
libstdc++-v3/testsuite/27_io/filesystem/path/compare/lwg2936.cc

index 3215b97bc7b98928aa5ec71d8ba6630e08d69c4b..60e7e74a42df1408fee2c9b4e8fd34b026d990ea 100644 (file)
@@ -1,5 +1,10 @@
 2018-12-20  Jonathan Wakely  <jwakely@redhat.com>
 
+       * 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.
+
        * testsuite/27_io/filesystem/directory_entry/lwg3171.cc: New test
        (missed from previous commit).
 
index 457cd2d0641441305a7c68b237a7832d1d680bdd..980161c9ead3aea256ae0a692c78b3c5900f6172 100644 (file)
 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 );
 }
 
index 21ae6be3d977a3823609031a9c88f77cfd3f9f8a..578d1350178c02e188704aa3fe91614ca1381c44 100644 (file)
@@ -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()
index 8a11043f1430d5cfc4ea92979b68b4debfeaf513..a62f01c3fb6cf94ea1d9e6cc3ec96b2971d9cf85 100644 (file)
@@ -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);
+#else
   check("c:/a/b", "c:a/b", -1);
+#endif
 
   // These are root names on Cygwin (just relative paths elsewhere)
   check("", "//c", -1);
@@ -68,6 +72,7 @@ test01()
   check("//c", "//c/", -1);
   check("//d", "//c/", +1);
 
+  check("a", "/", -1);
   check("/a", "/b", -1);
   check("a", "/b", -1);
   check("/b", "b", +1);