1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // REQUIRES: can-create-symlinks
10 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: no-filesystem
12 // UNSUPPORTED: availability-filesystem-missing
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;
22 #include <type_traits>
25 #include "test_macros.h"
26 #include "filesystem_test_helper.h"
27 namespace fs
= std::filesystem
;
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()
43 const path p
= current_path(ec
);
45 assert(p
.is_absolute());
46 assert(is_directory(p
));
48 const path p2
= current_path();
52 static void current_path_after_change_test()
54 static_test_env static_env
;
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
;
65 const path p
= static_env
.File
;
67 const path old_p
= current_path();
70 assert(old_p
== current_path());
73 static void set_to_non_absolute_path()
75 static_test_env static_env
;
77 const path base
= static_env
.Dir
;
79 const path p
= static_env
.Dir2
.filename();
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()
92 const path old_p
= current_path();
95 assert(old_p
== current_path());
98 int main(int, char**) {
99 current_path_signature_test();
101 current_path_after_change_test();
102 current_path_is_file_test();
103 set_to_non_absolute_path();