[RISCV] Fix the cost of `llvm.vector.reduce.and` (#119160)
[llvm-project.git] / libcxx / test / std / input.output / filesystems / fs.op.funcs / fs.op.current_path / current_path.pass.cpp
blob57df465bac18c38dae8c6dd3ab20cb31cff31ef6
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 // REQUIRES: can-create-symlinks
10 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: no-filesystem
12 // UNSUPPORTED: availability-filesystem-missing
14 // <filesystem>
16 // path current_path();
17 // path current_path(error_code& ec);
18 // void current_path(path const&);
19 // void current_path(path const&, std::error_code& ec) noexcept;
21 #include <filesystem>
22 #include <type_traits>
23 #include <cassert>
25 #include "test_macros.h"
26 #include "filesystem_test_helper.h"
27 namespace fs = std::filesystem;
28 using namespace fs;
30 static void current_path_signature_test()
32 const path p; ((void)p);
33 std::error_code ec; ((void)ec);
34 ASSERT_NOT_NOEXCEPT(current_path());
35 ASSERT_NOT_NOEXCEPT(current_path(ec));
36 ASSERT_NOT_NOEXCEPT(current_path(p));
37 ASSERT_NOEXCEPT(current_path(p, ec));
40 static void current_path_test()
42 std::error_code ec;
43 const path p = current_path(ec);
44 assert(!ec);
45 assert(p.is_absolute());
46 assert(is_directory(p));
48 const path p2 = current_path();
49 assert(p2 == p);
52 static void current_path_after_change_test()
54 static_test_env static_env;
55 CWDGuard guard;
56 const path new_path = static_env.Dir;
57 current_path(new_path);
58 assert(current_path() == new_path);
61 static void current_path_is_file_test()
63 static_test_env static_env;
64 CWDGuard guard;
65 const path p = static_env.File;
66 std::error_code ec;
67 const path old_p = current_path();
68 current_path(p, ec);
69 assert(ec);
70 assert(old_p == current_path());
73 static void set_to_non_absolute_path()
75 static_test_env static_env;
76 CWDGuard guard;
77 const path base = static_env.Dir;
78 current_path(base);
79 const path p = static_env.Dir2.filename();
80 std::error_code ec;
81 current_path(p, ec);
82 assert(!ec);
83 const path new_cwd = current_path();
84 assert(new_cwd == static_env.Dir2);
85 assert(new_cwd.is_absolute());
88 static void set_to_empty()
90 const path p = "";
91 std::error_code ec;
92 const path old_p = current_path();
93 current_path(p, ec);
94 assert(ec);
95 assert(old_p == current_path());
98 int main(int, char**) {
99 current_path_signature_test();
100 current_path_test();
101 current_path_after_change_test();
102 current_path_is_file_test();
103 set_to_non_absolute_path();
104 set_to_empty();
106 return 0;