1 // Copyright (C) 2019-2024 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-do run { target c++17 } }
19 // { dg-require-filesystem-ts "" }
22 #include <testsuite_hooks.h>
23 #include <testsuite_fs.h>
25 namespace fs
= std::filesystem
;
27 __gnu_test::scoped_file
28 create_dir(fs::path dir
= __gnu_test::nonexistent_path())
30 fs::create_directory(dir
);
31 return { dir
, __gnu_test::scoped_file::adopt_file
};
37 const auto testdir
= create_dir();
38 __gnu_test::scoped_file
file(testdir
.path
/ "file");
40 fs::recursive_directory_iterator
r(testdir
.path
);
41 VERIFY( r
.recursion_pending() );
43 r
.disable_recursion_pending();
44 VERIFY( !r
.recursion_pending() );
50 const auto testdir
= create_dir();
51 __gnu_test::scoped_file
file(testdir
.path
/ "file");
53 fs::recursive_directory_iterator
r(testdir
.path
);
54 VERIFY( r
.recursion_pending() );
56 // recursion pending flag should be copied:
57 VERIFY( r2
.recursion_pending() == r
.recursion_pending() );
59 r
.disable_recursion_pending();
60 VERIFY( !r
.recursion_pending() );
62 // recursion pending flag should be copied:
63 VERIFY( r3
.recursion_pending() == r
.recursion_pending() );
69 std::error_code ec
= make_error_code(std::errc::invalid_argument
);
71 const auto testdir
= create_dir();
72 __gnu_test::scoped_file
file1(testdir
.path
/ "file1");
73 __gnu_test::scoped_file
file2(testdir
.path
/ "file2");
74 __gnu_test::scoped_file
file3(testdir
.path
/ "file3");
75 __gnu_test::scoped_file
file4(testdir
.path
/ "file4");
77 fs::recursive_directory_iterator
r(testdir
.path
);
78 r
.disable_recursion_pending();
79 VERIFY( !r
.recursion_pending() );
81 // recursion pending flag should be true after incrementing:
82 VERIFY( r
.recursion_pending() );
84 r
.disable_recursion_pending();
85 VERIFY( !r
.recursion_pending() );
88 // recursion pending flag should be true after incrementing:
89 VERIFY( r
.recursion_pending() );
91 r
.disable_recursion_pending();
92 VERIFY( !r
.recursion_pending() );
94 // recursion pending flag should be true after post-incrementing:
95 VERIFY( r
.recursion_pending() );
97 VERIFY( ++r
== fs::recursive_directory_iterator() );
103 const auto testdir
= create_dir();
104 const auto sub1
= create_dir(testdir
.path
/"sub1");
105 __gnu_test::scoped_file
file1(sub1
.path
/ "file");
106 const auto sub2
= create_dir(testdir
.path
/"sub2");
107 __gnu_test::scoped_file
file2(sub2
.path
/ "file");
109 fs::recursive_directory_iterator
r(testdir
.path
);
112 // recursion pending flag should be true after popping:
113 VERIFY( r
.recursion_pending() );
115 // and recursion should actually happen:
117 VERIFY( r
.depth() == 1 );
118 VERIFY( r
->is_regular_file() );
119 // recursion pending flag should still be true:
120 VERIFY( r
.recursion_pending() );
122 r
= fs::recursive_directory_iterator(testdir
.path
);
123 r
.disable_recursion_pending();
125 // when recursion is disabled, should not enter subdirectories:
126 VERIFY( r
.depth() == 0 );
127 r
.disable_recursion_pending();
129 VERIFY( r
== fs::recursive_directory_iterator() );