]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/filesystem/operations/remove_all.cc
1 // Copyright (C) 2016-2020 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-options "-std=gnu++17" }
19 // { dg-do run { target c++17 } }
20 // { dg-require-filesystem-ts "" }
23 #include <testsuite_hooks.h>
24 #include <testsuite_fs.h>
26 namespace fs
= std::filesystem
;
32 const std::error_code bad_ec
= make_error_code(std::errc::invalid_argument
);
35 n
= fs::remove_all("", ec
);
36 VERIFY( !ec
); // This seems odd, but is what the standard requires.
39 auto p
= __gnu_test::nonexistent_path();
41 n
= remove_all(p
, ec
);
45 #if defined(__MINGW32__) || defined(__MINGW64__)
48 auto link
= __gnu_test::nonexistent_path();
49 create_symlink(p
, link
); // dangling symlink
51 n
= remove_all(link
, ec
);
54 VERIFY( !exists(symlink_status(link
)) ); // DR 2721
56 __gnu_test::scoped_file
f(p
);
57 create_symlink(p
, link
);
59 n
= remove_all(link
, ec
);
62 VERIFY( !exists(symlink_status(link
)) ); // The symlink is removed, but
63 VERIFY( exists(p
) ); // its target is not.
66 const auto dir
= __gnu_test::nonexistent_path();
67 create_directories(dir
/"a/b/c");
69 n
= remove_all(dir
/"a", ec
);
72 VERIFY( exists(dir
) );
73 VERIFY( !exists(dir
/"a") );
75 create_directories(dir
/"a/b/c");
76 __gnu_test::scoped_file
a1(dir
/"a/1");
77 __gnu_test::scoped_file
a2(dir
/"a/2");
78 __gnu_test::scoped_file
b1(dir
/"a/b/1");
79 __gnu_test::scoped_file
b2(dir
/"a/b/2");
81 n
= remove_all(dir
, ec
);
84 VERIFY( !exists(dir
) );
95 const auto dir
= __gnu_test::nonexistent_path();
96 create_directories(dir
/"a/b/c");
97 std::uintmax_t n
= remove_all(dir
/"a");
99 VERIFY( exists(dir
) );
100 VERIFY( !exists(dir
/"a") );
102 n
= remove_all(dir
/"a");
104 VERIFY( exists(dir
) );
108 VERIFY( !exists(dir
) );
114 // PR libstdc++/88881 symlink_status confused by trailing slash on Windows
115 const std::error_code bad_ec
= make_error_code(std::errc::invalid_argument
);
117 std::error_code ec
= bad_ec
;
118 const auto p
= __gnu_test::nonexistent_path() / ""; // with trailing slash
120 create_directories(p
);
121 removed
= remove_all(p
, ec
);
123 VERIFY( removed
== 1 );
124 VERIFY( !exists(p
) );
125 create_directories(p
);
126 removed
= remove_all(p
);
127 VERIFY( removed
== 1 );
128 VERIFY( !exists(p
) );
130 const auto p_subs
= p
/"foo/bar";
132 create_directories(p_subs
);
133 removed
= remove_all(p
, ec
);
135 VERIFY( removed
== 3 );
136 VERIFY( !exists(p
) );
137 create_directories(p_subs
);
139 VERIFY( removed
== 3 );
140 VERIFY( !exists(p
) );