From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 963D5385AC38; Tue, 1 Feb 2022 21:58:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 963D5385AC38 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-6982] libstdc++: Add more tests for filesystem directory iterators X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: ec09a5335f0ade7071f6157dfd97dbb3de3e4f97 X-Git-Newrev: 2dc2f417288d4f0839b4bc01388e676ee343f941 Message-Id: <20220201215854.963D5385AC38@sourceware.org> Date: Tue, 1 Feb 2022 21:58:54 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2022 21:58:54 -0000 https://gcc.gnu.org/g:2dc2f417288d4f0839b4bc01388e676ee343f941 commit r12-6982-g2dc2f417288d4f0839b4bc01388e676ee343f941 Author: Jonathan Wakely Date: Tue Feb 1 14:02:56 2022 +0000 libstdc++: Add more tests for filesystem directory iterators The PR 97731 test was added to verify a fix to the Filesystem TS code, but we should also have the same test to avoid similar regressions in the C++17 std::filesystem code. Also add tests for directory_options::follow_directory_symlink libstdc++-v3/ChangeLog: * testsuite/27_io/filesystem/iterators/97731.cc: New test. * testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc: Check follow_directory_symlink option. * testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc: Likewise. Diff: --- .../testsuite/27_io/filesystem/iterators/97731.cc | 48 ++++++++++++++++++++++ .../iterators/recursive_directory_iterator.cc | 19 +++++++++ .../iterators/recursive_directory_iterator.cc | 21 +++++++++- 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/testsuite/27_io/filesystem/iterators/97731.cc b/libstdc++-v3/testsuite/27_io/filesystem/iterators/97731.cc new file mode 100644 index 00000000000..9021e6edf41 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/97731.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include +#include +#include + +bool used_custom_readdir = false; + +extern "C" void* readdir(void*) +{ + used_custom_readdir = true; + errno = EIO; + return nullptr; +} + +void +test01() +{ + using std::filesystem::recursive_directory_iterator; + std::error_code ec; + recursive_directory_iterator it(".", ec); + if (used_custom_readdir) + VERIFY( ec.value() == EIO ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc b/libstdc++-v3/testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc index b0ccdfe3d73..e67e2cf38f7 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc @@ -184,6 +184,24 @@ test05() remove_all(p, ec); } +void +test06() +{ +#if !(defined __MINGW32__ || defined __MINGW64__) + auto p = __gnu_test::nonexistent_path(); + create_directories(p/"d1/d2"); + create_directory_symlink("d1", p/"link"); + fs::recursive_directory_iterator it(p), endit; + VERIFY( std::distance(it, endit) == 3 ); // d1 and d2 and link + + it = fs::recursive_directory_iterator(p, fs::directory_options::follow_directory_symlink); + VERIFY( std::distance(it, endit) == 4 ); // d1 and d1/d2 and link and link/d2 + + std::error_code ec; + remove_all(p, ec); +#endif +} + int main() { @@ -192,4 +210,5 @@ main() test03(); test04(); test05(); + test06(); } diff --git a/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc b/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc index 455dbf28c8c..a201415921c 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc @@ -174,7 +174,7 @@ test05() { auto p = __gnu_test::nonexistent_path(); create_directory(p); - create_directory_symlink(p, p / "l"); + create_directory(p / "x"); fs::recursive_directory_iterator it(p), endit; VERIFY( begin(it) == it ); static_assert( noexcept(begin(it)), "begin is noexcept" ); @@ -185,6 +185,24 @@ test05() remove_all(p, ec); } +void +test06() +{ +#if !(defined __MINGW32__ || defined __MINGW64__) + auto p = __gnu_test::nonexistent_path(); + create_directories(p/"d1/d2"); + create_directory_symlink("d1", p/"link"); + fs::recursive_directory_iterator it(p), endit; + VERIFY( std::distance(it, endit) == 3 ); // d1 and d2 and link + + it = fs::recursive_directory_iterator(p, fs::directory_options::follow_directory_symlink); + VERIFY( std::distance(it, endit) == 4 ); // d1 and d1/d2 and link and link/d2 + + std::error_code ec; + remove_all(p, ec); +#endif +} + int main() { @@ -193,4 +211,5 @@ main() test03(); test04(); test05(); + test06(); }