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 | // UNSUPPORTED: c++03, c++11, c++14 |
10 | // UNSUPPORTED: no-filesystem |
11 | // UNSUPPORTED: availability-filesystem-missing |
12 | |
13 | // <filesystem> |
14 | |
15 | // path absolute(const path& p, const path& base=current_path()); |
16 | |
17 | #include <filesystem> |
18 | #include <type_traits> |
19 | #include <cassert> |
20 | |
21 | #include "test_macros.h" |
22 | #include "filesystem_test_helper.h" |
23 | #include "../../class.path/path_helper.h" |
24 | namespace fs = std::filesystem; |
25 | using namespace fs; |
26 | |
27 | static void absolute_signature_test() |
28 | { |
29 | const path p; ((void)p); |
30 | std::error_code ec; |
31 | ASSERT_NOT_NOEXCEPT(absolute(p: p)); |
32 | ASSERT_NOT_NOEXCEPT(absolute(p: p, ec&: ec)); |
33 | } |
34 | |
35 | |
36 | static void basic_test() |
37 | { |
38 | const fs::path cwd = fs::current_path(); |
39 | const struct { |
40 | std::string input; |
41 | fs::path expect; |
42 | } TestCases [] = { |
43 | {.input: "" , .expect: cwd / "" }, |
44 | {.input: "foo" , .expect: cwd / "foo" }, |
45 | {.input: "foo/" , .expect: cwd / "foo/" }, |
46 | {.input: "/already_absolute" , .expect: cwd.root_name() / "/already_absolute" } |
47 | }; |
48 | for (auto& TC : TestCases) { |
49 | std::error_code ec = GetTestEC(); |
50 | const path ret = absolute(p: TC.input, ec&: ec); |
51 | assert(!ec); |
52 | assert(ret.is_absolute()); |
53 | assert(PathEqIgnoreSep(ret, TC.expect)); |
54 | LIBCPP_ASSERT(PathEq(LHS: ret, RHS: TC.expect)); |
55 | } |
56 | } |
57 | |
58 | int main(int, char**) { |
59 | absolute_signature_test(); |
60 | basic_test(); |
61 | |
62 | return 0; |
63 | } |
64 | |