1 // Copyright (C) 2016-2021 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 fs::recursive_directory_iterator dir
;
33 dir
.pop(ec
); // This is undefined, but our implementation
34 VERIFY( ec
); // checks and returns an error.
35 VERIFY( dir
== end(dir
) );
42 catch (const fs::filesystem_error
& ex
)
52 const std::error_code bad_ec
= make_error_code(std::errc::invalid_argument
);
54 const auto p
= __gnu_test::nonexistent_path();
55 create_directories(p
/ "d1/d2/d3");
56 for (int i
= 0; i
< 3; ++i
)
58 fs::recursive_directory_iterator
dir(p
);
59 VERIFY( dir
!= end(dir
) );
61 VERIFY( dir
!= end(dir
) );
62 VERIFY( dir
.depth() == i
);
66 VERIFY( dir
== end(dir
) );
68 dir
= fs::recursive_directory_iterator(p
);
70 VERIFY( dir
!= end(dir
) );
71 VERIFY( dir
.depth() == i
);
73 VERIFY( dir
== end(dir
) );
81 const std::error_code bad_ec
= make_error_code(std::errc::invalid_argument
);
83 const auto p
= __gnu_test::nonexistent_path();
84 create_directories(p
/ "d1/d2/d3");
85 create_directories(p
/ "d1/d2/e3");
86 create_directories(p
/ "d1/e2/d3");
87 for (int i
= 0; i
< 3; ++i
)
89 fs::recursive_directory_iterator
dir(p
);
91 VERIFY( dir
!= end(dir
) );
92 int expected_depth
= i
;
93 VERIFY( dir
.depth() == expected_depth
);
98 VERIFY( dir
.depth() == (expected_depth
- 1) );
100 dir
= fs::recursive_directory_iterator(p
);
101 std::advance(dir
, i
);
102 VERIFY( dir
!= end(dir
) );
103 VERIFY( dir
.depth() == i
);
106 VERIFY( dir
.depth() == (i
-1) );