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_fs.h>
23 #include <testsuite_hooks.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 auto testdir
= create_dir();
38 __gnu_test::scoped_file
file1(testdir
.path
/"file1");
39 __gnu_test::scoped_file
file2(testdir
.path
/"file2");
41 fs::directory_iterator
it(testdir
.path
);
42 VERIFY( it
->is_regular_file() );
44 VERIFY( it
->is_regular_file() );
46 VERIFY( it
== fs::directory_iterator
{} );
52 auto testdir
= create_dir();
53 const auto sub1
= create_dir(testdir
.path
/"sub1");
54 __gnu_test::scoped_file
file1(sub1
.path
/ "file");
55 const auto sub2
= create_dir(testdir
.path
/"sub2");
56 __gnu_test::scoped_file
file2(sub2
.path
/ "file");
58 fs::recursive_directory_iterator
it(testdir
.path
);
59 VERIFY( it
->is_directory() );
61 VERIFY( it
->is_regular_file() );
63 VERIFY( it
->is_directory() );
65 VERIFY( it
->is_regular_file() );
67 VERIFY( it
== fs::recursive_directory_iterator
{} );