1 // Copyright (C) 2019-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
;
28 __gnu_test::scoped_file
29 create_dir(fs::path dir
= __gnu_test::nonexistent_path())
31 fs::create_directory(dir
);
32 return { dir
, __gnu_test::scoped_file::adopt_file
};
38 const auto testdir
= create_dir();
39 __gnu_test::scoped_file
file(testdir
.path
/ "file");
41 fs::recursive_directory_iterator
r(testdir
.path
);
42 VERIFY( r
.recursion_pending() );
44 r
.disable_recursion_pending();
45 VERIFY( !r
.recursion_pending() );
51 const auto testdir
= create_dir();
52 __gnu_test::scoped_file
file(testdir
.path
/ "file");
54 fs::recursive_directory_iterator
r(testdir
.path
);
55 VERIFY( r
.recursion_pending() );
57 // recursion pending flag should be copied:
58 VERIFY( r2
.recursion_pending() == r
.recursion_pending() );
60 r
.disable_recursion_pending();
61 VERIFY( !r
.recursion_pending() );
63 // recursion pending flag should be copied:
64 VERIFY( r3
.recursion_pending() == r
.recursion_pending() );
70 std::error_code ec
= make_error_code(std::errc::invalid_argument
);
72 const auto testdir
= create_dir();
73 __gnu_test::scoped_file
file1(testdir
.path
/ "file1");
74 __gnu_test::scoped_file
file2(testdir
.path
/ "file2");
75 __gnu_test::scoped_file
file3(testdir
.path
/ "file3");
76 __gnu_test::scoped_file
file4(testdir
.path
/ "file4");
78 fs::recursive_directory_iterator
r(testdir
.path
);
79 r
.disable_recursion_pending();
80 VERIFY( !r
.recursion_pending() );
82 // recursion pending flag should be true after incrementing:
83 VERIFY( r
.recursion_pending() );
85 r
.disable_recursion_pending();
86 VERIFY( !r
.recursion_pending() );
89 // recursion pending flag should be true after incrementing:
90 VERIFY( r
.recursion_pending() );
92 r
.disable_recursion_pending();
93 VERIFY( !r
.recursion_pending() );
95 // recursion pending flag should be true after post-incrementing:
96 VERIFY( r
.recursion_pending() );
98 VERIFY( ++r
== fs::recursive_directory_iterator() );
104 const auto testdir
= create_dir();
105 const auto sub1
= create_dir(testdir
.path
/"sub1");
106 __gnu_test::scoped_file
file1(sub1
.path
/ "file");
107 const auto sub2
= create_dir(testdir
.path
/"sub2");
108 __gnu_test::scoped_file
file2(sub2
.path
/ "file");
110 fs::recursive_directory_iterator
r(testdir
.path
);
113 // recursion pending flag should be true after popping:
114 VERIFY( r
.recursion_pending() );
116 // and recursion should actually happen:
118 VERIFY( r
.depth() == 1 );
119 VERIFY( r
->is_regular_file() );
120 // recursion pending flag should still be true:
121 VERIFY( r
.recursion_pending() );
123 r
= fs::recursive_directory_iterator(testdir
.path
);
124 r
.disable_recursion_pending();
126 // when recursion is disabled, should not enter subdirectories:
127 VERIFY( r
.depth() == 0 );
128 r
.disable_recursion_pending();
130 VERIFY( r
== fs::recursive_directory_iterator() );