• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
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.hpp"
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.hpp"
26 #include "rapid-cxx-test.hpp"
27 #include "filesystem_test_helper.hpp"
28 
29 
30 TEST_SUITE(filesystem_proximate_path_test_suite)
31 
TEST_CASE(test_signature_0)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 
TEST_CASE(test_signature_1)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 
TEST_CASE(test_signature_2)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 
TEST_CASE(test_signature_3)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 
TEST_CASE(test_signature_4)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 
TEST_CASE(test_signature_5)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 
TEST_CASE(test_signature_6)68 TEST_CASE(test_signature_6) {
69   // FIXME? If the trailing separator occurs in a part of the path that exists,
70   // it is ommitted. 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 
TEST_CASE(test_signature_7)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 
TEST_CASE(test_signature_8)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 
TEST_CASE(test_signature_9)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 
TEST_CASE(test_signature_10)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 
TEST_CASE(test_signature_11)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 
TEST_CASE(test_signature_12)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 
TEST_CASE(test_signature_13)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