| 1 |
// Copyright (C) 2019-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 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) |
| 7 |
// any later version. |
| 8 |
|
| 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. |
| 13 |
|
| 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/>. |
| 17 |
|
| 18 |
// { dg-do run { target c++17 } } |
| 19 |
// { dg-require-filesystem-ts "" } |
| 20 |
|
| 21 |
#include <filesystem> |
| 22 |
#include <testsuite_fs.h> |
| 23 |
#include <testsuite_hooks.h> |
| 24 |
|
| 25 |
namespace fs = std::filesystem; |
| 26 |
|
| 27 |
__gnu_test::scoped_file |
| 28 |
create_dir(fs::path dir = __gnu_test::nonexistent_path()) |
| 29 |
{ |
| 30 |
fs::create_directory(dir); |
| 31 |
return { dir, __gnu_test::scoped_file::adopt_file }; |
| 32 |
} |
| 33 |
|
| 34 |
void |
| 35 |
test01() |
| 36 |
{ |
| 37 |
auto testdir = create_dir(); |
| 38 |
__gnu_test::scoped_file file1(testdir.path/"file1"); |
| 39 |
__gnu_test::scoped_file file2(testdir.path/"file2"); |
| 40 |
|
| 41 |
fs::directory_iterator it(testdir.path); |
| 42 |
VERIFY( it->is_regular_file() ); |
| 43 |
++it; |
| 44 |
VERIFY( it->is_regular_file() ); |
| 45 |
++it; |
| 46 |
VERIFY( it == fs::directory_iterator{} ); |
| 47 |
} |
| 48 |
|
| 49 |
void |
| 50 |
test02() |
| 51 |
{ |
| 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"); |
| 57 |
|
| 58 |
fs::recursive_directory_iterator it(testdir.path); |
| 59 |
VERIFY( it->is_directory() ); |
| 60 |
++it; |
| 61 |
VERIFY( it->is_regular_file() ); |
| 62 |
++it; |
| 63 |
VERIFY( it->is_directory() ); |
| 64 |
++it; |
| 65 |
VERIFY( it->is_regular_file() ); |
| 66 |
++it; |
| 67 |
VERIFY( it == fs::recursive_directory_iterator{} ); |
| 68 |
} |
| 69 |
|
| 70 |
int |
| 71 |
main() |
| 72 |
{ |
| 73 |
test01(); |
| 74 |
test02(); |
| 75 |
} |