[libcxx] [test] Fix lexically_normal and lexically_relative_and_proximate for windows

Convert the expected result path to preferred separators, add exceptions
to the test results where needed (due to some cases being interpreted
as a root name).

Differential Revision: https://reviews.llvm.org/D98106
This commit is contained in:
Martin Storsjö 2020-10-15 13:58:32 +03:00
parent 2ad1f5eb1a
commit d601edf0b0
2 changed files with 20 additions and 4 deletions

View File

@ -54,10 +54,17 @@ int main(int, char**) {
{"/a/b/./", "/a/b/"},
{"/a/b/c/../d", "/a/b/d"},
{"/a/b/c/../d/", "/a/b/d/"},
#ifdef _WIN32
{"//a/", "//a/"},
{"//a/b/", "//a/b/"},
{"//a/b/.", "//a/b/"},
{"//a/..", "//a/"},
#else
{"//a/", "/a/"},
{"//a/b/", "/a/b/"},
{"//a/b/.", "/a/b/"},
{"//a/..", "/"},
#endif
///===---------------------------------------------------------------===//
/// Tests specifically for the clauses under [fs.path.generic]p6
///===---------------------------------------------------------------===//
@ -125,13 +132,15 @@ int main(int, char**) {
++ID;
fs::path p(TC.input);
const fs::path output = p.lexically_normal();
if (!PathEq(output, TC.expect)) {
fs::path expect(TC.expect);
expect.make_preferred();
if (!PathEq(output, expect)) {
Failed = true;
std::fprintf(stderr, "TEST CASE #%d FAILED:\n"
" Input: '%s'\n"
" Expected: '%s'\n"
" Output: '%s'\n",
ID, TC.input.c_str(), TC.expect.c_str(), output.string().c_str());
ID, TC.input.c_str(), expect.string().c_str(), output.string().c_str());
}
}
return Failed;

View File

@ -36,8 +36,13 @@ int main(int, char**) {
{"a", "/", ""},
{"//net", "a", ""},
{"a", "//net", ""},
#ifdef _WIN32
{"//net/", "//net", ""},
{"//net", "//net/", ""},
#else
{"//net/", "//net", "."},
{"//net", "//net/", "."},
#endif
{"//base", "a", ""},
{"a", "a", "."},
{"a/b", "a/b", "."},
@ -59,6 +64,8 @@ int main(int, char**) {
++ID;
const fs::path p(TC.input);
const fs::path output = p.lexically_relative(TC.base);
fs::path expect(TC.expect);
expect.make_preferred();
auto ReportErr = [&](const char* Testing, fs::path const& Output,
fs::path const& Expected) {
Failed = true;
@ -71,8 +78,8 @@ int main(int, char**) {
ID, Testing, TC.input.c_str(), TC.base.c_str(),
Expected.string().c_str(), Output.string().c_str());
};
if (!PathEq(output, TC.expect))
ReportErr("path::lexically_relative", output, TC.expect);
if (!PathEq(output, expect))
ReportErr("path::lexically_relative", output, expect);
const fs::path proximate_output = p.lexically_proximate(TC.base);
// [path.gen] lexically_proximate
// Returns: If the value of lexically_relative(base) is not an empty path,