public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: testsuite: fs rename to self may fail
@ 2022-06-22  6:24 Alexandre Oliva
  2022-06-22  6:33 ` Sebastian Huber
  0 siblings, 1 reply; 10+ messages in thread
From: Alexandre Oliva @ 2022-06-22  6:24 UTC (permalink / raw)
  To: gcc-patches, libstdc++


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>

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-06-23 12:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-22  6:24 [PATCH] libstdc++: testsuite: fs rename to self may fail Alexandre Oliva
2022-06-22  6:33 ` Sebastian Huber
2022-06-22  7:01   ` Alexandre Oliva
2022-06-22 10:41     ` Jonathan Wakely
2022-06-23  3:59       ` Alexandre Oliva
2022-06-23  6:26       ` Alexandre Oliva
2022-06-23  9:25         ` Jonathan Wakely
2022-06-23 11:21           ` Alexandre Oliva
2022-06-23 11:38             ` Jonathan Wakely
2022-06-23 12:41               ` Alexandre Oliva

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).