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 //===----------------------------------------------------------------------===//
8 
9 // FILE_DEPENDENCIES: ../../Inputs/static_test_env
10 // UNSUPPORTED: c++98, c++03
11 
12 // <filesystem>
13 
14 // path proximate(const path& p, error_code &ec)
15 // path proximate(const path& p, const path& base = current_path())
16 // path proximate(const path& p, const path& base, error_code& ec);
17 
18 #include "filesystem_include.h"
19 #include <string>
20 #include <type_traits>
21 #include <cassert>
22 
23 #include "test_macros.h"
24 #include "test_iterators.h"
25 #include "count_new.h"
26 #include "rapid-cxx-test.h"
27 #include "filesystem_test_helper.h"
28 
29 
30 TEST_SUITE(filesystem_proximate_path_test_suite)
31 
32 TEST_CASE(test_signature_0) {
33   fs::path p("");
34   const fs::path output = fs::weakly_canonical(p);
35   TEST_CHECK(output == std::string(fs::current_path()));
36 }
37 
38 TEST_CASE(test_signature_1) {
39   fs::path p(".");
40   const fs::path output = fs::weakly_canonical(p);
41   TEST_CHECK(output == std::string(fs::current_path()));
42 }
43 
44 TEST_CASE(test_signature_2) {
45   fs::path p(StaticEnv::File);
46   const fs::path output = fs::weakly_canonical(p);
47   TEST_CHECK(output == std::string(StaticEnv::File));
48 }
49 
50 TEST_CASE(test_signature_3) {
51   fs::path p(StaticEnv::Dir);
52   const fs::path output = fs::weakly_canonical(p);
53   TEST_CHECK(output == std::string(StaticEnv::Dir));
54 }
55 
56 TEST_CASE(test_signature_4) {
57   fs::path p(StaticEnv::SymlinkToDir);
58   const fs::path output = fs::weakly_canonical(p);
59   TEST_CHECK(output == std::string(StaticEnv::Dir));
60 }
61 
62 TEST_CASE(test_signature_5) {
63   fs::path p(StaticEnv::SymlinkToDir / "dir2/.");
64   const fs::path output = fs::weakly_canonical(p);
65   TEST_CHECK(output == std::string(StaticEnv::Dir / "dir2"));
66 }
67 
68 TEST_CASE(test_signature_6) {
69   // FIXME? If the trailing separator occurs in a part of the path that exists,
70   // it is omitted. Otherwise it is added to the end of the result.
71   fs::path p(StaticEnv::SymlinkToDir / "dir2/./");
72   const fs::path output = fs::weakly_canonical(p);
73   TEST_CHECK(output == std::string(StaticEnv::Dir / "dir2"));
74 }
75 
76 TEST_CASE(test_signature_7) {
77   fs::path p(StaticEnv::SymlinkToDir / "dir2/DNE/./");
78   const fs::path output = fs::weakly_canonical(p);
79   TEST_CHECK(output == std::string(StaticEnv::Dir / "dir2/DNE/"));
80 }
81 
82 TEST_CASE(test_signature_8) {
83   fs::path p(StaticEnv::SymlinkToDir / "dir2");
84   const fs::path output = fs::weakly_canonical(p);
85   TEST_CHECK(output == std::string(StaticEnv::Dir2));
86 }
87 
88 TEST_CASE(test_signature_9) {
89   fs::path p(StaticEnv::SymlinkToDir / "dir2/../dir2/DNE/..");
90   const fs::path output = fs::weakly_canonical(p);
91   TEST_CHECK(output == std::string(StaticEnv::Dir2 / ""));
92 }
93 
94 TEST_CASE(test_signature_10) {
95   fs::path p(StaticEnv::SymlinkToDir / "dir2/dir3/../DNE/DNE2");
96   const fs::path output = fs::weakly_canonical(p);
97   TEST_CHECK(output == std::string(StaticEnv::Dir2 / "DNE/DNE2"));
98 }
99 
100 TEST_CASE(test_signature_11) {
101   fs::path p(StaticEnv::Dir / "../dir1");
102   const fs::path output = fs::weakly_canonical(p);
103   TEST_CHECK(output == std::string(StaticEnv::Dir));
104 }
105 
106 TEST_CASE(test_signature_12) {
107   fs::path p(StaticEnv::Dir / "./.");
108   const fs::path output = fs::weakly_canonical(p);
109   TEST_CHECK(output == std::string(StaticEnv::Dir));
110 }
111 
112 TEST_CASE(test_signature_13) {
113   fs::path p(StaticEnv::Dir / "DNE/../foo");
114   const fs::path output = fs::weakly_canonical(p);
115   TEST_CHECK(output == std::string(StaticEnv::Dir / "foo"));
116 }
117 
118 TEST_SUITE_END()
119