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 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: no-filesystem
11 // UNSUPPORTED: availability-filesystem-missing
15 // path current_path();
16 // path current_path(error_code& ec);
17 // void current_path(path const&);
18 // void current_path(path const&, std::error_code& ec) noexcept;
20 #include "filesystem_include.h"
21 #include <type_traits>
24 #include "test_macros.h"
25 #include "filesystem_test_helper.h"
29 static void current_path_signature_test()
31 const path p
; ((void)p
);
32 std::error_code ec
; ((void)ec
);
33 ASSERT_NOT_NOEXCEPT(current_path());
34 ASSERT_NOT_NOEXCEPT(current_path(ec
));
35 ASSERT_NOT_NOEXCEPT(current_path(p
));
36 ASSERT_NOEXCEPT(current_path(p
, ec
));
39 static void current_path_test()
42 const path p
= current_path(ec
);
44 assert(p
.is_absolute());
45 assert(is_directory(p
));
47 const path p2
= current_path();
51 static void current_path_after_change_test()
53 static_test_env static_env
;
55 const path new_path
= static_env
.Dir
;
56 current_path(new_path
);
57 assert(current_path() == new_path
);
60 static void current_path_is_file_test()
62 static_test_env static_env
;
64 const path p
= static_env
.File
;
66 const path old_p
= current_path();
69 assert(old_p
== current_path());
72 static void set_to_non_absolute_path()
74 static_test_env static_env
;
76 const path base
= static_env
.Dir
;
78 const path p
= static_env
.Dir2
.filename();
82 const path new_cwd
= current_path();
83 assert(new_cwd
== static_env
.Dir2
);
84 assert(new_cwd
.is_absolute());
87 static void set_to_empty()
91 const path old_p
= current_path();
94 assert(old_p
== current_path());
97 int main(int, char**) {
98 current_path_signature_test();
100 current_path_after_change_test();
101 current_path_is_file_test();
102 set_to_non_absolute_path();