[PATCH] libstdc++: testsuite: fs rename to self may fail
Alexandre Oliva
oliva@adacore.com
Wed Jun 22 06:24:43 GMT 2022
rtems6's rename() implementation errors with EEXIST when the rename-to
filename exists, even when renaming a file to itself or when renaming
a nonexisting file. Adjust expectations.
Regstrapped on x86_64-linux-gnu, also tested with a cross to
aarch64-rtems6. Ok to install?
PS: https://devel.rtems.org/ticket/2169 doesn't seem to suggest plans to
change behavior so as to comply with POSIX.
for libstdc++-v3/ChangeLog
* testsuite/27_io/filesystem/operations/rename.cc (test01):
Accept EEXIST fail on self-rename, on rename of a
nonexisting file, and on rename to existing file. Clean up p1
in case it remains.
* testsuite/experimental/filesystem/operations/rename.cc
(test01): Accept EEXIST fail on self-rename, and on rename to
existing file. Clean up p1 in case it remains.
---
.../27_io/filesystem/operations/rename.cc | 11 ++++++-----
.../experimental/filesystem/operations/rename.cc | 9 +++++----
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/rename.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/rename.cc
index 936e306041290..2fb2068dfd3c5 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/rename.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/rename.cc
@@ -46,14 +46,14 @@ test01()
ec = bad_ec;
std::ofstream{p1}; // create file
- fs::rename(p1, p1, ec); // no-op
- VERIFY( !ec );
+ fs::rename(p1, p1, ec); // no-op, but may fail
+ VERIFY( !ec || ec.value() == EEXIST );
VERIFY( is_regular_file(p1) );
ec.clear();
rename(p2, p1, ec);
VERIFY( ec );
- VERIFY( ec.value() == ENOENT );
+ VERIFY( ec.value() == ENOENT || ec.value() == EEXIST );
VERIFY( is_regular_file(p1) );
ec = bad_ec;
@@ -65,10 +65,11 @@ test01()
ec = bad_ec;
std::ofstream{p1}; // create file
fs::rename(p1, p2, ec);
- VERIFY( !ec );
- VERIFY( !exists(p1) );
+ VERIFY( !ec || ec.value() == EEXIST );
+ VERIFY( !exists(p1) || ec );
VERIFY( is_regular_file(p2) );
+ fs::remove(p1, ec);
fs::remove(p2, ec);
}
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/rename.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/rename.cc
index 520d48ef8d844..d2175652a79a8 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/operations/rename.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/rename.cc
@@ -47,8 +47,8 @@ test01()
ec = bad_ec;
std::ofstream{p1}; // create file
- fs::rename(p1, p1, ec); // no-op
- VERIFY( !ec );
+ fs::rename(p1, p1, ec); // no-op, but may fail
+ VERIFY( !ec || ec.value() == EEXIST );
VERIFY( is_regular_file(p1) );
ec.clear();
@@ -65,10 +65,11 @@ test01()
ec = bad_ec;
std::ofstream{p1}; // create file
fs::rename(p1, p2, ec);
- VERIFY( !ec );
- VERIFY( !exists(p1) );
+ VERIFY( !ec || ec.value() == EEXIST );
+ VERIFY( !exists(p1) || ec );
VERIFY( is_regular_file(p2) );
+ fs::remove(p1, ec);
fs::remove(p2, ec);
}
--
Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/
Free Software Activist GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts. Ask me about <https://stallmansupport.org>
More information about the Libstdc++
mailing list