From eeb517d3e7fd3717f4fa7cc8a1e6d4499013fee3 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 25 Oct 2017 13:42:53 +0100 Subject: [PATCH] Fix filesystem::path::lexically_normal algorithm * src/filesystem/std-path.cc (path::lexically_normal): Add missing step to algorithm, for removing dot-dot elements after root-directory. * testsuite/27_io/filesystem/operations/canonical.cc: Use compare_paths for more exhaustive checks. * testsuite/27_io/filesystem/operations/proximate.cc: Likewise. * testsuite/27_io/filesystem/path/append/path.cc: Likewise. * testsuite/27_io/filesystem/path/concat/path.cc: Likewise. * testsuite/27_io/filesystem/path/concat/strings.cc: Fix comment. * testsuite/27_io/filesystem/path/construct/locale.cc: Likewise. * testsuite/27_io/filesystem/path/decompose/root_directory.cc: Likewise. * testsuite/27_io/filesystem/path/generation/normal.cc: Use compare_paths for more exhaustive checks. Add extra testcases. * testsuite/27_io/filesystem/path/generation/proximate.cc: Use compare_paths for more exhaustive checks. * testsuite/27_io/filesystem/path/generation/relative.cc: Likewise. * testsuite/27_io/filesystem/path/generic/generic_string.cc: Remove unused header. * testsuite/27_io/filesystem/path/modifiers/make_preferred.cc: Fix comment. * testsuite/27_io/filesystem/path/modifiers/remove_filename.cc: Use compare_paths for more exhaustive checks. * testsuite/27_io/filesystem/path/modifiers/replace_extension.cc: Likewise. * testsuite/27_io/filesystem/path/modifiers/replace_filename.cc: Likewise. * testsuite/util/testsuite_fs.h (compare_paths): Also compare native strings. From-SVN: r254075 --- libstdc++-v3/ChangeLog | 29 ++++++ libstdc++-v3/src/filesystem/std-path.cc | 4 +- .../27_io/filesystem/operations/canonical.cc | 27 +++--- .../27_io/filesystem/operations/proximate.cc | 26 +++--- .../27_io/filesystem/path/append/path.cc | 21 ++--- .../27_io/filesystem/path/concat/path.cc | 12 ++- .../27_io/filesystem/path/concat/strings.cc | 2 +- .../27_io/filesystem/path/construct/locale.cc | 4 +- .../path/decompose/root_directory.cc | 2 +- .../filesystem/path/generation/normal.cc | 90 +++++++++++++++++-- .../filesystem/path/generation/proximate.cc | 20 +++-- .../filesystem/path/generation/relative.cc | 20 +++-- .../filesystem/path/generic/generic_string.cc | 1 - .../path/modifiers/make_preferred.cc | 2 +- .../path/modifiers/remove_filename.cc | 16 ++-- .../path/modifiers/replace_extension.cc | 11 +-- .../path/modifiers/replace_filename.cc | 12 +-- libstdc++-v3/testsuite/util/testsuite_fs.h | 1 + 18 files changed, 201 insertions(+), 99 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index dadec85c093..5a694c74675 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,34 @@ 2017-10-25 Jonathan Wakely + * src/filesystem/std-path.cc (path::lexically_normal): Add missing + step to algorithm, for removing dot-dot elements after root-directory. + * testsuite/27_io/filesystem/operations/canonical.cc: Use + compare_paths for more exhaustive checks. + * testsuite/27_io/filesystem/operations/proximate.cc: Likewise. + * testsuite/27_io/filesystem/path/append/path.cc: Likewise. + * testsuite/27_io/filesystem/path/concat/path.cc: Likewise. + * testsuite/27_io/filesystem/path/concat/strings.cc: Fix comment. + * testsuite/27_io/filesystem/path/construct/locale.cc: Likewise. + * testsuite/27_io/filesystem/path/decompose/root_directory.cc: + Likewise. + * testsuite/27_io/filesystem/path/generation/normal.cc: Use + compare_paths for more exhaustive checks. Add extra testcases. + * testsuite/27_io/filesystem/path/generation/proximate.cc: Use + compare_paths for more exhaustive checks. + * testsuite/27_io/filesystem/path/generation/relative.cc: Likewise. + * testsuite/27_io/filesystem/path/generic/generic_string.cc: Remove + unused header. + * testsuite/27_io/filesystem/path/modifiers/make_preferred.cc: Fix + comment. + * testsuite/27_io/filesystem/path/modifiers/remove_filename.cc: Use + compare_paths for more exhaustive checks. + * testsuite/27_io/filesystem/path/modifiers/replace_extension.cc: + Likewise. + * testsuite/27_io/filesystem/path/modifiers/replace_filename.cc: + Likewise. + * testsuite/util/testsuite_fs.h (compare_paths): Also compare native + strings. + PR libstdc++/82706 * testsuite/27_io/filesystem/operations/permissions.cc: Fix test. diff --git a/libstdc++-v3/src/filesystem/std-path.cc b/libstdc++-v3/src/filesystem/std-path.cc index b5dd36d6ad1..1e2a8fad584 100644 --- a/libstdc++-v3/src/filesystem/std-path.cc +++ b/libstdc++-v3/src/filesystem/std-path.cc @@ -365,6 +365,8 @@ path::lexically_normal() const - As long as any appear, remove a non-dot-dot filename immediately followed by a directory-separator and a dot-dot filename, along with any immediately following directory-separator. + - If there is a root-directory, remove all dot-dot filenames and any + directory-separators immediately following them. - If the last filename is dot-dot, remove any trailing directory-separator. - If the path is empty, add a dot. */ @@ -388,7 +390,7 @@ path::lexically_normal() const { if (ret.has_filename() && !is_dotdot(ret.filename())) ret.remove_filename(); - else + else if (ret.has_filename() || !ret.has_root_directory()) ret /= p; } else if (is_dot(p)) diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/canonical.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/canonical.cc index 646c37c4c3c..47305a8f527 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/operations/canonical.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/canonical.cc @@ -24,6 +24,7 @@ #include namespace fs = std::filesystem; +using __gnu_test::compare_paths; void test01() @@ -36,42 +37,42 @@ test01() create_directory(p); auto p2 = canonical( p, ec ); - VERIFY( p2 == fs::current_path()/p ); + compare_paths( p2, fs::current_path()/p ); VERIFY( !ec ); ec = bad_ec; p2 = canonical( fs::current_path() / "." / (p.native() + "////././."), ec ); - VERIFY( p2 == fs::current_path()/p ); + compare_paths( p2, fs::current_path()/p ); VERIFY( !ec ); ec = bad_ec; p = fs::current_path(); p2 = canonical( p, ec ); - VERIFY( p2 == p ); + compare_paths( p2, p ); VERIFY( !ec ); ec = bad_ec; p = "/"; p = canonical( p, ec ); - VERIFY( p == "/" ); + compare_paths( p, "/" ); VERIFY( !ec ); ec = bad_ec; p = "/."; p = canonical( p, ec ); - VERIFY( p == "/" ); + compare_paths( p, "/" ); VERIFY( !ec ); ec = bad_ec; p = "/.."; p = canonical( p, ec ); - VERIFY( p == "/" ); + compare_paths( p, "/" ); VERIFY( !ec ); ec = bad_ec; p = "/../.././."; p = canonical( p, ec ); - VERIFY( p == "/" ); + compare_paths( p, "/" ); VERIFY( !ec ); } @@ -115,17 +116,17 @@ test03() auto barc = canonical(bar); auto p1 = fs::canonical(dir/"foo//.///..//./"); - VERIFY( p1 == dirc ); + compare_paths( p1, dirc ); auto p2 = fs::canonical(dir/"foo//./baz///..//./"); - VERIFY( p2 == dirc ); + compare_paths( p2, dirc ); auto p3 = fs::canonical(dir/"foo//./baz////./"); - VERIFY( p3 == barc ); + compare_paths( p3, barc ); auto p4 = fs::canonical(dir/"foo//./baz///..//./bar"); - VERIFY( p4 == barc ); + compare_paths( p4, barc ); auto p5 = fs::canonical(dir/"foo//./baz///..//./bar/"); - VERIFY( p5 == p4 ); + compare_paths( p5, p4 ); auto p6 = fs::canonical(dir/"foo//./baz///..//./bar/."); - VERIFY( p6 == p4 ); + compare_paths( p6, p4 ); remove_all(dir); } diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/proximate.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/proximate.cc index 02da2507d46..99b6568abeb 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/operations/proximate.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/proximate.cc @@ -21,18 +21,20 @@ #include #include +#include using std::filesystem::proximate; +using __gnu_test::compare_paths; void test01() { - VERIFY( proximate("/a/d", "/a/b/c") == "../../d" ); - VERIFY( proximate("/a/b/c", "/a/d") == "../b/c" ); - VERIFY( proximate("a/b/c", "a") == "b/c" ); - VERIFY( proximate("a/b/c", "a/b/c/x/y") == "../.." ); - VERIFY( proximate("a/b/c", "a/b/c") == "." ); - VERIFY( proximate("a/b", "c/d") == "../../a/b" ); + 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/b/c", "a/b/c"), "." ); + compare_paths( proximate("a/b", "c/d"), "../../a/b" ); } void @@ -40,22 +42,22 @@ test02() { const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); std::error_code ec = bad_ec; - VERIFY( proximate("/a/d", "/a/b/c", ec) == "../../d" ); + compare_paths( proximate("/a/d", "/a/b/c", ec), "../../d" ); VERIFY( !ec ); ec = bad_ec; - VERIFY( proximate("/a/b/c", "/a/d", ec) == "../b/c" ); + compare_paths( proximate("/a/b/c", "/a/d", ec), "../b/c" ); VERIFY( !ec ); ec = bad_ec; - VERIFY( proximate("a/b/c", "a", ec) == "b/c" ); + compare_paths( proximate("a/b/c", "a", ec), "b/c" ); VERIFY( !ec ); ec = bad_ec; - VERIFY( proximate("a/b/c", "a/b/c/x/y", ec) == "../.." ); + compare_paths( proximate("a/b/c", "a/b/c/x/y", ec), "../.." ); VERIFY( !ec ); ec = bad_ec; - VERIFY( proximate("a/b/c", "a/b/c", ec) == "." ); + compare_paths( proximate("a/b/c", "a/b/c", ec), "." ); VERIFY( !ec ); ec = bad_ec; - VERIFY( proximate("a/b", "c/d", ec) == "../../a/b" ); + compare_paths( proximate("a/b", "c/d", ec), "../../a/b" ); VERIFY( !ec ); } diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc index 64c638ed1e3..0942d6fdf7e 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc @@ -19,13 +19,14 @@ // with this library; see the file COPYING3. If not see // . -// 8.4.3 path appends [path.append] +// 30.10.7.4.3 path appends [fs.path.append] #include #include #include using std::filesystem::path; +using __gnu_test::compare_paths; void test01() @@ -34,16 +35,16 @@ test01() path pp = p; pp /= p; - VERIFY( pp.native() == p.native() ); + compare_paths( pp, p ); path q("baz"); path qq = q; qq /= q; - VERIFY( qq.native() == "baz/baz" ); + compare_paths( qq, "baz/baz" ); q /= p; - VERIFY( q.native() == p.native() ); + compare_paths( q, p ); path r = ""; r /= path(); @@ -54,11 +55,11 @@ test01() path s = "dir/"; s /= path("/file"); - VERIFY( s.native() == "/file" ); + compare_paths( s, "/file" ); s = "dir/"; s /= path("file"); - VERIFY( s.native() == "dir/file" ); + compare_paths( s, "dir/file" ); } void @@ -67,16 +68,16 @@ test02() // C++17 [fs.path.append] p4 path p = path("//host") / "foo"; - VERIFY( p == "//host/foo" ); + compare_paths( p, "//host/foo" ); path pp = path("//host/") / "foo"; - VERIFY( pp == "//host/foo" ); + compare_paths( pp, "//host/foo" ); path q = path("foo") / ""; - VERIFY( q == "foo/" ); + compare_paths( q, "foo/" ); path qq = path("foo") / "/bar"; - VERIFY( qq == "/bar" ); + compare_paths( qq, "/bar" ); } int diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/concat/path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/concat/path.cc index 46cf09abe16..1a987c1966b 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/concat/path.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/concat/path.cc @@ -19,13 +19,14 @@ // with this library; see the file COPYING3. If not see // . -// 8.4.4 path concatenation [path.concat] +// 30.10.7.4.4 path concatenation [fs.path.concat] #include #include #include using std::filesystem::path; +using __gnu_test::compare_paths; void test01() @@ -34,19 +35,16 @@ test01() path pp = p; pp += p; - VERIFY( pp.native() == "/foo/bar/foo/bar" ); - VERIFY( std::distance(pp.begin(), pp.end()) == 5 ); + compare_paths( pp, "/foo/bar/foo/bar" ); path q("foo/bar"); path qq = q; qq += q; - VERIFY( qq.native() == "foo/barfoo/bar" ); - VERIFY( std::distance(qq.begin(), qq.end()) == 3 ); + compare_paths( qq, "foo/barfoo/bar" ); q += p; - VERIFY( q.native() == "foo/bar/foo/bar" ); - VERIFY( std::distance(q.begin(), q.end()) == 4 ); + compare_paths( q, "foo/bar/foo/bar" ); } void diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/concat/strings.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/concat/strings.cc index 3eb4d1a3cb1..8d298f8a57d 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/concat/strings.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/concat/strings.cc @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// 8.4.4 path concatenation [path.concat] +// 30.10.7.4.4 path concatenation [fs.path.concat] #include #include diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/locale.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/locale.cc index e313412386d..8bbff810652 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/locale.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/locale.cc @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// 8.4.1 path constructors [path.construct] +// 30.10.7.4.1 path constructors [fs.path.construct] #include #include @@ -30,7 +30,7 @@ void test01() { path p("/foo/bar", std::locale::classic()); - VERIFY( p.string() == "/foo/bar" ); + VERIFY( p.native() == "/foo/bar" ); } int diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc index 8220c589efc..8cd1976a946 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// 8.4.9 path decomposition [path.decompose] +// 30.10.7.4.9 path decomposition [fs.path.decompose] #include #include diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/normal.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/normal.cc index 2e4ec5bc98e..789ce186f82 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/normal.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/normal.cc @@ -20,28 +20,99 @@ // { dg-require-filesystem-ts "" } #include +#include #include using std::filesystem::path; +using __gnu_test::compare_paths; void test01() { // C++17 [fs.path.gen] p2 - VERIFY( path("foo/./bar/..").lexically_normal() == "foo/" ); - VERIFY( path("foo/.///bar/../").lexically_normal() == "foo/" ); + compare_paths( path("foo/./bar/..").lexically_normal(), "foo/" ); + compare_paths( path("foo/.///bar/../").lexically_normal(), "foo/" ); } void test02() { - VERIFY( path("foo/../bar").lexically_normal() == "bar" ); - VERIFY( path("../foo/../bar").lexically_normal() == "../bar" ); - VERIFY( path("foo/../").lexically_normal() == "." ); - VERIFY( path("../../").lexically_normal() == "../.." ); - VERIFY( path("../").lexically_normal() == ".." ); - VERIFY( path("./").lexically_normal() == "." ); - VERIFY( path().lexically_normal() == "" ); + compare_paths( path("foo/../bar").lexically_normal(), "bar" ); + compare_paths( path("../foo/../bar").lexically_normal(), "../bar" ); + compare_paths( path("foo/../").lexically_normal(), "." ); + compare_paths( path("../../").lexically_normal(), "../.." ); + compare_paths( path("../").lexically_normal(), ".." ); + compare_paths( path("./").lexically_normal(), "." ); + compare_paths( path().lexically_normal(), "" ); + + compare_paths( path("/..").lexically_normal(), "/" ); +} + +void +test03() +{ + struct + { + const char* input; + const char* normalized; + } testcases[] = { + {"" , "" }, + {"." , "." }, + {".." , ".." }, + {"/" , "/" }, + {"//" , "//" }, + + {"/foo" , "/foo" }, + {"/foo/" , "/foo/" }, + {"/foo/." , "/foo/" }, + {"/foo/bar/.." , "/foo/" }, + {"/foo/.." , "/" }, + + {"/." , "/" }, + {"/./" , "/" }, + {"/./." , "/" }, + {"/././" , "/" }, + {"/././." , "/" }, + + {"./" , "." }, + {"./." , "." }, + {"././" , "." }, + {"././." , "." }, + {"./././" , "." }, + {"./././." , "." }, + + {"foo/.." , "." }, + {"foo/../" , "." }, + {"foo/../.." , ".." }, + + // with root name (OS-dependent): +#if defined(_WIN32) && !defined(__CYGWIN__) + {"C:bar/.." , "C:." }, +#else + {"C:bar/.." , "." }, +#endif + {"C:/bar/.." , "C:/" }, + {"C:" , "C:" }, +#ifdef __CYGWIN__ + {"//host/bar/.." , "//host/" }, + {"//host" , "//host" }, +#else + {"//host/bar/.." , "/host/" }, + {"//host" , "/host" }, +#endif + + // a few others: + {"foo/../foo/.." , "." }, + {"foo/../foo/../.." , ".." }, + {"../foo/../foo/.." , ".." }, + {"../.f/../f" , "../f" }, + {"../f/../.f" , "../.f" }, + {".././../." , "../.." }, + {".././.././" , "../.." }, + {"/.." , "/" }, + }; + for (auto& test : testcases) + compare_paths( path(test.input).lexically_normal(), test.normalized ); } int @@ -49,4 +120,5 @@ main() { test01(); test02(); + test03(); } diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/proximate.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/proximate.cc index 7a25f7b417d..ee77e16d1f8 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/proximate.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/proximate.cc @@ -21,28 +21,30 @@ #include #include +#include using std::filesystem::path; +using __gnu_test::compare_paths; void test01() { // C++17 [fs.path.gen] p5 - VERIFY( path("/a/d").lexically_proximate("/a/b/c") == "../../d" ); - VERIFY( path("/a/b/c").lexically_proximate("/a/d") == "../b/c" ); - VERIFY( path("a/b/c").lexically_proximate("a") == "b/c" ); - VERIFY( path("a/b/c").lexically_proximate("a/b/c/x/y") == "../.." ); - VERIFY( path("a/b/c").lexically_proximate("a/b/c") == "." ); - VERIFY( path("a/b").lexically_proximate("c/d") == "../../a/b" ); + compare_paths( path("/a/d").lexically_proximate("/a/b/c"), "../../d" ); + compare_paths( path("/a/b/c").lexically_proximate("/a/d"), "../b/c" ); + compare_paths( path("a/b/c").lexically_proximate("a"), "b/c" ); + compare_paths( path("a/b/c").lexically_proximate("a/b/c/x/y"), "../.." ); + compare_paths( path("a/b/c").lexically_proximate("a/b/c"), "." ); + compare_paths( path("a/b").lexically_proximate("c/d"), "../../a/b" ); } void test02() { path p = "a/b/c"; - VERIFY( p.lexically_proximate(p) == "." ); - VERIFY( p.lexically_proximate("a/../a/b/../b/c/../c/.") == "../../b/c" ); - VERIFY( p.lexically_proximate("../../../") == p ); + compare_paths( p.lexically_proximate(p), "." ); + compare_paths( p.lexically_proximate("a/../a/b/../b/c/../c/."), "../../b/c" ); + compare_paths( p.lexically_proximate("../../../"), p ); } int diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc index 64770fb1fe5..3e78344a618 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc @@ -21,28 +21,30 @@ #include #include +#include using std::filesystem::path; +using __gnu_test::compare_paths; void test01() { // C++17 [fs.path.gen] p5 - VERIFY( path("/a/d").lexically_relative("/a/b/c") == "../../d" ); - VERIFY( path("/a/b/c").lexically_relative("/a/d") == "../b/c" ); - VERIFY( path("a/b/c").lexically_relative("a") == "b/c" ); - VERIFY( path("a/b/c").lexically_relative("a/b/c/x/y") == "../.." ); - VERIFY( path("a/b/c").lexically_relative("a/b/c") == "." ); - VERIFY( path("a/b").lexically_relative("c/d") == "../../a/b" ); + compare_paths( path("/a/d").lexically_relative("/a/b/c"), "../../d" ); + compare_paths( path("/a/b/c").lexically_relative("/a/d"), "../b/c" ); + compare_paths( path("a/b/c").lexically_relative("a"), "b/c" ); + compare_paths( path("a/b/c").lexically_relative("a/b/c/x/y"), "../.." ); + compare_paths( path("a/b/c").lexically_relative("a/b/c"), "." ); + compare_paths( path("a/b").lexically_relative("c/d"), "../../a/b" ); } void test02() { path p = "a/b/c"; - VERIFY( p.lexically_relative(p) == "." ); - VERIFY( p.lexically_relative("a/../a/b/../b/c/../c/.") == "../../b/c" ); - VERIFY( p.lexically_relative("../../../") == "" ); + compare_paths( p.lexically_relative(p), "." ); + compare_paths( p.lexically_relative("a/../a/b/../b/c/../c/."), "../../b/c" ); + compare_paths( p.lexically_relative("../../../"), "" ); } int diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generic/generic_string.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/generic/generic_string.cc index d25d5056c60..78224339b42 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/generic/generic_string.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generic/generic_string.cc @@ -22,7 +22,6 @@ // C++17 30.10.7.4.7 path generic format observers [fs.path.generic.obs] #include -#include #include using std::filesystem::path; diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/make_preferred.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/make_preferred.cc index 1df10093777..6e306a41c2b 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/make_preferred.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/make_preferred.cc @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// 8.4.5 path modifiers [path.modifiers] +// 30.10.7.4.5 path modifiers [fs.path.modifiers] #include #include diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/remove_filename.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/remove_filename.cc index 02e1b05cd41..cb764cd1585 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/remove_filename.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/remove_filename.cc @@ -26,21 +26,18 @@ #include using std::filesystem::path; +using __gnu_test::compare_paths; void test01() { // C++17 [fs.path.modifiers] p8 - VERIFY( path("foo/bar").remove_filename() == "foo/" ); - VERIFY( path("foo/").remove_filename() == "foo/" ); - VERIFY( path("/foo").remove_filename() == "/" ); - VERIFY( path("/").remove_filename() == "/" ); + compare_paths( path("foo/bar").remove_filename(), "foo/" ); + compare_paths( path("foo/").remove_filename() , "foo/" ); + compare_paths( path("/foo").remove_filename() , "/" ); + compare_paths( path("/").remove_filename() , "/" ); } -#undef VERIFY -#define VERIFY(X) do { if (!(X)) { __builtin_puts("FAIL: " #X); } } while(false) -#define DUMP(X, Y) do { if (!(X == Y)) { __builtin_printf("%s %s\n", X.c_str(), Y.c_str()); } } while(false) - void test02() { @@ -49,8 +46,7 @@ test02() path p2(p); p2.remove_filename(); p2 /= p.filename(); - VERIFY( p2 == p ); - DUMP( p2 , p ); + compare_paths( p2, p ); } } diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_extension.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_extension.cc index cf7ca094c0f..fca189ce040 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_extension.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_extension.cc @@ -19,20 +19,21 @@ // with this library; see the file COPYING3. If not see // . -// 8.4.5 path modifiers [path.modifiers] +// 30.10.7.4.5 path modifiers [fs.path.modifiers] #include #include #include using std::filesystem::path; +using __gnu_test::compare_paths; void test01() { - VERIFY( path("/foo.txt").replace_extension("cpp") == "/foo.cpp" ); - VERIFY( path("/foo.txt").replace_extension(".cpp") == "/foo.cpp" ); - VERIFY( path("/").replace_extension("bar") == "/.bar" ); + compare_paths( path("/foo.txt").replace_extension("cpp"), "/foo.cpp" ); + compare_paths( path("/foo.txt").replace_extension(".cpp"), "/foo.cpp" ); + compare_paths( path("/").replace_extension("bar"), "/.bar" ); } void @@ -41,7 +42,7 @@ test02() for (const path& p : __gnu_test::test_paths) { path p2 = p; - VERIFY(p2.replace_extension(p2.extension()) == p); + compare_paths( p2.replace_extension(p2.extension()), p ); } } diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_filename.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_filename.cc index 6d3b9b70d07..d5c36565aca 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_filename.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_filename.cc @@ -26,19 +26,16 @@ #include using std::filesystem::path; +using __gnu_test::compare_paths; void test01() { // C++17 [fs.path.modifiers] p11 - VERIFY( path("/foo").replace_filename("bar") == "/bar" ); - VERIFY( path("/").replace_filename("bar") == "/bar" ); + compare_paths( path("/foo").replace_filename("bar"), "/bar" ); + compare_paths( path("/").replace_filename("bar") , "/bar" ); } -#undef VERIFY -#define VERIFY(X) do { if (!(X)) { __builtin_puts("FAIL: " #X); } } while(false) -#define DUMP(X, Y) do { if (!(X == Y)) { __builtin_printf("%s %s\n", X.c_str(), Y.c_str()); } } while(false) - void test02() { @@ -46,8 +43,7 @@ test02() { path p2(p); p2.replace_filename(p.filename()); - VERIFY( p2 == p ); - DUMP( p2 , p ); + compare_paths( p2, p ); } } diff --git a/libstdc++-v3/testsuite/util/testsuite_fs.h b/libstdc++-v3/testsuite/util/testsuite_fs.h index e0db46ca156..47f56090b47 100644 --- a/libstdc++-v3/testsuite/util/testsuite_fs.h +++ b/libstdc++-v3/testsuite/util/testsuite_fs.h @@ -47,6 +47,7 @@ namespace __gnu_test compare_paths(const test_fs::path& p1, const test_fs::path& p2) { + PATH_CHK( p1, p2, native ); PATH_CHK( p1, p2, string ); PATH_CHK( p1, p2, empty ); PATH_CHK( p1, p2, has_root_path ); -- 2.30.2