public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-11049] libstdc++: Add more tests for filesystem directory iterators
@ 2023-10-04 11:29 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-10-04 11:29 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:9eed5712110b63a0021358cbf195d32c5b372638
commit r11-11049-g9eed5712110b63a0021358cbf195d32c5b372638
Author: Jonathan Wakely <jwakely@redhat.com>
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.
(cherry picked from commit 2dc2f417288d4f0839b4bc01388e676ee343f941)
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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do run { target c++17 } }
+// { dg-require-filesystem-ts "" }
+
+#include <filesystem>
+#include <cerrno>
+#include <testsuite_hooks.h>
+
+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 29a9f480649..014d030eb4f 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 a9a81c8c4cb..e3b00945285 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();
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-10-04 11:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-04 11:29 [gcc r11-11049] libstdc++: Add more tests for filesystem directory iterators Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).