Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / input.output / filesystems / fs.op.funcs / fs.op.weakly_canonical / weakly_canonical.pass.cpp
blobb7ceec67d655bca9044c370f8fe686d3a66bab0e
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
10 // UNSUPPORTED: no-filesystem
11 // UNSUPPORTED: availability-filesystem-missing
13 // <filesystem>
15 // path weakly_canonical(const path& p);
16 // path weakly_canonical(const path& p, error_code& ec);
18 #include "filesystem_include.h"
19 #include <string>
21 #include "assert_macros.h"
22 #include "concat_macros.h"
23 #include "test_macros.h"
24 #include "test_iterators.h"
25 #include "count_new.h"
26 #include "filesystem_test_helper.h"
27 #include "../../class.path/path_helper.h"
29 int main(int, char**) {
30 static_test_env static_env;
32 fs::path root = fs::current_path().root_path();
33 // clang-format off
34 struct {
35 fs::path input;
36 fs::path expect;
37 } TestCases[] = {
38 {"", fs::current_path()},
39 {".", fs::current_path()},
40 {"/", root},
41 {"/foo", root / "foo"},
42 {"/.", root},
43 {"/./", root},
44 {"a/b", fs::current_path() / "a/b"},
45 {"a", fs::current_path() / "a"},
46 {"a/b/", fs::current_path() / "a/b/"},
47 {static_env.File, static_env.File},
48 {static_env.Dir, static_env.Dir},
49 {static_env.SymlinkToDir, static_env.Dir},
50 {static_env.SymlinkToDir / "dir2/.", static_env.Dir / "dir2"},
51 // Note: If the trailing separator occurs in a part of the path that exists,
52 // it is omitted. Otherwise it is added to the end of the result.
53 // MS STL and libstdc++ behave similarly.
54 {static_env.SymlinkToDir / "dir2/./", static_env.Dir / "dir2"},
55 {static_env.SymlinkToDir / "dir2/DNE/./", static_env.Dir / "dir2/DNE/"},
56 {static_env.SymlinkToDir / "dir2", static_env.Dir2},
57 #ifdef _WIN32
58 // On Windows, this path is considered to exist (even though it
59 // passes through a nonexistent directory), and thus is returned
60 // without a trailing slash, see the note above.
61 {static_env.SymlinkToDir / "dir2/../dir2/DNE/..", static_env.Dir2},
62 #else
63 {static_env.SymlinkToDir / "dir2/../dir2/DNE/..", static_env.Dir2 / ""},
64 #endif
65 {static_env.SymlinkToDir / "dir2/dir3/../DNE/DNE2", static_env.Dir2 / "DNE/DNE2"},
66 {static_env.Dir / "../dir1", static_env.Dir},
67 {static_env.Dir / "./.", static_env.Dir},
68 {static_env.Dir / "DNE/../foo", static_env.Dir / "foo"}
70 // clang-format on
71 for (auto& TC : TestCases) {
72 fs::path p = TC.input;
73 fs::path expect = TC.expect;
74 expect.make_preferred();
75 const fs::path output = fs::weakly_canonical(p);
77 TEST_REQUIRE(PathEq(output, expect),
78 TEST_WRITE_CONCATENATED(
79 "Input: ", TC.input.string(), "\nExpected: ", expect.string(), "\nOutput: ", output.string()));
81 return 0;