Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / input.output / filesystems / fs.op.funcs / fs.op.current_path / current_path.pass.cpp
blob0962ce0c592dc527a40481858430ee3255661807
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 // UNSUPPORTED: c++03
10 // UNSUPPORTED: no-filesystem
11 // UNSUPPORTED: availability-filesystem-missing
13 // <filesystem>
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>
22 #include <cassert>
24 #include "test_macros.h"
25 #include "filesystem_test_helper.h"
27 using namespace fs;
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()
41 std::error_code ec;
42 const path p = current_path(ec);
43 assert(!ec);
44 assert(p.is_absolute());
45 assert(is_directory(p));
47 const path p2 = current_path();
48 assert(p2 == p);
51 static void current_path_after_change_test()
53 static_test_env static_env;
54 CWDGuard guard;
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;
63 CWDGuard guard;
64 const path p = static_env.File;
65 std::error_code ec;
66 const path old_p = current_path();
67 current_path(p, ec);
68 assert(ec);
69 assert(old_p == current_path());
72 static void set_to_non_absolute_path()
74 static_test_env static_env;
75 CWDGuard guard;
76 const path base = static_env.Dir;
77 current_path(base);
78 const path p = static_env.Dir2.filename();
79 std::error_code ec;
80 current_path(p, ec);
81 assert(!ec);
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()
89 const path p = "";
90 std::error_code ec;
91 const path old_p = current_path();
92 current_path(p, ec);
93 assert(ec);
94 assert(old_p == current_path());
97 int main(int, char**) {
98 current_path_signature_test();
99 current_path_test();
100 current_path_after_change_test();
101 current_path_is_file_test();
102 set_to_non_absolute_path();
103 set_to_empty();
105 return 0;