]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | // Copyright (C) 2018-2022 Free Software Foundation, Inc. |
994844d3 JW |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
994844d3 JW |
18 | // { dg-do run { target c++17 } } |
19 | // { dg-require-filesystem-ts "" } | |
20 | ||
21 | #include <filesystem> | |
22 | #include <testsuite_hooks.h> | |
23 | #include <testsuite_fs.h> | |
24 | ||
25 | namespace fs = std::filesystem; | |
26 | ||
27 | void | |
28 | test01() | |
29 | { | |
30 | std::error_code ec; | |
31 | const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); | |
32 | bool n; | |
33 | ||
34 | n = fs::remove("", ec); | |
35 | VERIFY( !ec ); // This seems odd, but is what the standard requires. | |
36 | VERIFY( !n ); | |
37 | ||
38 | auto p = __gnu_test::nonexistent_path(); | |
39 | ec = bad_ec; | |
40 | n = remove(p, ec); | |
41 | VERIFY( !ec ); | |
42 | VERIFY( !n ); | |
43 | ||
edfe833a JW |
44 | #if defined(__MINGW32__) || defined(__MINGW64__) |
45 | // No symlink support | |
46 | #else | |
994844d3 JW |
47 | auto link = __gnu_test::nonexistent_path(); |
48 | create_symlink(p, link); // dangling symlink | |
49 | ec = bad_ec; | |
50 | n = remove(link, ec); | |
51 | VERIFY( !ec ); | |
52 | VERIFY( n ); | |
53 | VERIFY( !exists(symlink_status(link)) ); | |
54 | ||
55 | __gnu_test::scoped_file f(p); | |
56 | create_symlink(p, link); | |
57 | ec = bad_ec; | |
58 | n = remove(link, ec); | |
59 | VERIFY( !ec ); | |
60 | VERIFY( n ); | |
61 | VERIFY( !exists(symlink_status(link)) ); // The symlink is removed, but | |
62 | VERIFY( exists(p) ); // its target is not. | |
63 | ||
64 | ec = bad_ec; | |
65 | n = remove(p, ec); | |
66 | VERIFY( !ec ); | |
67 | VERIFY( n ); | |
68 | VERIFY( !exists(symlink_status(p)) ); | |
edfe833a | 69 | #endif |
994844d3 JW |
70 | |
71 | const auto dir = __gnu_test::nonexistent_path(); | |
72 | create_directories(dir/"a/b"); | |
73 | ec.clear(); | |
74 | n = remove(dir/"a", ec); | |
75 | VERIFY( ec ); | |
76 | VERIFY( !n ); | |
77 | VERIFY( exists(dir/"a/b") ); | |
78 | ||
29b2fd37 | 79 | if (__gnu_test::permissions_are_testable()) |
994844d3 | 80 | { |
29b2fd37 JW |
81 | permissions(dir, fs::perms::none, ec); |
82 | if (!ec) | |
83 | { | |
84 | ec.clear(); | |
85 | n = remove(dir/"a/b", ec); | |
86 | VERIFY( ec ); | |
87 | VERIFY( !n ); | |
88 | permissions(dir, fs::perms::owner_all, ec); | |
89 | } | |
994844d3 JW |
90 | } |
91 | ||
92 | ec = bad_ec; | |
93 | n = remove(dir/"a/b", ec); | |
94 | VERIFY( !ec ); | |
95 | VERIFY( n ); | |
96 | VERIFY( !exists(dir/"a/b") ); | |
97 | ||
98 | remove(dir/"a", ec); | |
99 | remove(dir, ec); | |
100 | } | |
101 | ||
102 | int | |
103 | main() | |
104 | { | |
105 | test01(); | |
106 | } |