[RISCV] Fix the cost of `llvm.vector.reduce.and` (#119160)
[llvm-project.git] / libcxx / test / std / input.output / filesystems / fs.op.funcs / fs.op.remove_all / remove_all.pass.cpp
blob5513c18f00585ee069ddbc73e6e8ddc73acbe7bf
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 // uintmax_t remove_all(const path& p);
17 // uintmax_t remove_all(const path& p, error_code& ec) noexcept;
19 #include <filesystem>
21 #include "test_macros.h"
22 #include "filesystem_test_helper.h"
23 namespace fs = std::filesystem;
24 using namespace fs;
26 static void test_signatures()
28 const path p; ((void)p);
29 std::error_code ec; ((void)ec);
30 ASSERT_SAME_TYPE(decltype(fs::remove_all(p)), std::uintmax_t);
31 ASSERT_SAME_TYPE(decltype(fs::remove_all(p, ec)), std::uintmax_t);
33 ASSERT_NOT_NOEXCEPT(fs::remove_all(p));
34 ASSERT_NOT_NOEXCEPT(fs::remove_all(p, ec));
37 static void test_error_reporting()
39 scoped_test_env env;
40 // Windows doesn't support setting perms::none to trigger failures
41 // reading directories.
42 #ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE
43 auto checkThrow = [](path const& f, const std::error_code& ec)
45 #ifndef TEST_HAS_NO_EXCEPTIONS
46 try {
47 fs::remove_all(f);
48 return false;
49 } catch (filesystem_error const& err) {
50 return err.path1() == f
51 && err.path2() == ""
52 && err.code() == ec;
54 #else
55 ((void)f); ((void)ec);
56 return true;
57 #endif
59 const path non_empty_dir = env.create_dir("dir");
60 env.create_file(non_empty_dir / "file1", 42);
61 const path bad_perms_dir = env.create_dir("bad_dir");
62 const path file_in_bad_dir = env.create_file(bad_perms_dir / "file", 42);
63 permissions(bad_perms_dir, perms::none);
64 const path bad_perms_file = env.create_file("file2", 42);
65 permissions(bad_perms_file, perms::none);
67 const path testCases[] = {
68 file_in_bad_dir
70 const auto BadRet = static_cast<std::uintmax_t>(-1);
71 for (auto& p : testCases) {
72 std::error_code ec;
74 assert(fs::remove_all(p, ec) == BadRet);
75 assert(ec);
76 assert(checkThrow(p, ec));
78 #endif
80 // PR#35780
81 const path testCasesNonexistant[] = {
82 "",
83 env.make_env_path("dne")
85 for (auto &p : testCasesNonexistant) {
86 std::error_code ec;
88 assert(fs::remove_all(p, ec) == 0);
89 assert(!ec);
93 static void basic_remove_all_test()
95 scoped_test_env env;
96 const path dne = env.make_env_path("dne");
97 const path link = env.create_symlink(dne, "link");
98 const path nested_link = env.make_env_path("nested_link");
99 create_symlink(link, nested_link);
100 const path testCases[] = {
101 env.create_file("file", 42),
102 env.create_dir("empty_dir"),
103 nested_link,
104 link
106 for (auto& p : testCases) {
107 std::error_code ec = std::make_error_code(std::errc::address_in_use);
108 assert(remove(p, ec));
109 assert(!ec);
110 assert(!exists(symlink_status(p)));
114 static void symlink_to_dir()
116 scoped_test_env env;
117 const path dir = env.create_dir("dir");
118 const path file = env.create_file(dir / "file", 42);
119 const path link = env.create_directory_symlink(dir, "sym");
122 std::error_code ec = std::make_error_code(std::errc::address_in_use);
123 assert(remove_all(link, ec) == 1);
124 assert(!ec);
125 assert(!exists(symlink_status(link)));
126 assert(exists(dir));
127 assert(exists(file));
132 static void nested_dir()
134 scoped_test_env env;
135 const path dir = env.create_dir("dir");
136 const path dir1 = env.create_dir(dir / "dir1");
137 const path out_of_dir_file = env.create_file("file1", 42);
138 const path all_files[] = {
139 dir, dir1,
140 env.create_file(dir / "file1", 42),
141 env.create_symlink(out_of_dir_file, dir / "sym1"),
142 env.create_file(dir1 / "file2", 42),
143 env.create_directory_symlink(dir, dir1 / "sym2")
145 const std::size_t expected_count = sizeof(all_files) / sizeof(all_files[0]);
147 std::error_code ec = std::make_error_code(std::errc::address_in_use);
148 assert(remove_all(dir, ec) == expected_count);
149 assert(!ec);
150 for (auto const& p : all_files) {
151 assert(!exists(symlink_status(p)));
153 assert(exists(out_of_dir_file));
156 int main(int, char**) {
157 test_signatures();
158 test_error_reporting();
159 basic_remove_all_test();
160 symlink_to_dir();
161 nested_dir();
163 return 0;