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
10 
11 // <filesystem>
12 
13 // path absolute(const path& p, const path& base=current_path());
14 
15 #include "filesystem_include.h"
16 #include <type_traits>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 #include "rapid-cxx-test.h"
21 #include "filesystem_test_helper.h"
22 
23 using namespace fs;
24 
25 TEST_SUITE(filesystem_absolute_path_test_suite)
26 
TEST_CASE(absolute_signature_test)27 TEST_CASE(absolute_signature_test)
28 {
29     const path p; ((void)p);
30     std::error_code ec;
31     ASSERT_NOT_NOEXCEPT(absolute(p));
32     ASSERT_NOT_NOEXCEPT(absolute(p, ec));
33 }
34 
35 
TEST_CASE(basic_test)36 TEST_CASE(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         {"", cwd / ""},
44         {"foo", cwd / "foo"},
45         {"foo/", cwd / "foo/"},
46         {"/already_absolute", cwd.root_name() / "/already_absolute"}
47     };
48     for (auto& TC : TestCases) {
49         std::error_code ec = GetTestEC();
50         const path ret = absolute(TC.input, ec);
51         TEST_CHECK(!ec);
52         TEST_CHECK(ret.is_absolute());
53         TEST_CHECK(PathEqIgnoreSep(ret, TC.expect));
54         LIBCPP_ONLY(TEST_CHECK(PathEq(ret, TC.expect)));
55     }
56 }
57 
58 TEST_SUITE_END()
59