lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 8f7ad46 2/3: Resolve a unit-test failure


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 8f7ad46 2/3: Resolve a unit-test failure
Date: Sun, 16 Aug 2020 19:34:52 -0400 (EDT)

branch: master
commit 8f7ad463b58dbf81c2937b7533fdc12a126c1040
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Resolve a unit-test failure
    
    Two unit tests failed, as described in the immediately preceding commit.
    In this commit, the temporary directory created in one of those tests is
    now deleted. Commentary explains why std::filesystem::remove() deletes a
    directory that the msw C runtime's remove() does not. C99 (N1256) says
    [7.19.4.1] "If the file is open, the behavior of the remove function is
    implementation-defined", but this directory doesn't seem to be "open",
    and apparently the msw implementation simply refuses to remove any
    directory.
    
    Incidentally changed a preposition; that didn't deserve its own commit.
---
 path_utility_test.cpp | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/path_utility_test.cpp b/path_utility_test.cpp
index 5907f88..aa10cf0 100644
--- a/path_utility_test.cpp
+++ b/path_utility_test.cpp
@@ -247,13 +247,32 @@ void test_unique_filepath_with_normal_filenames()
 
     keep_open.close();
 
-    // Clean up the files created in this function.
+    // Clean up the files created by this function.
 
     BOOST_TEST(0 == std::remove(path3.string().c_str()));
     BOOST_TEST(0 == std::remove(path2.string().c_str()));
 #endif // defined LMI_MSW
     BOOST_TEST(0 == std::remove(q.c_str()));
     BOOST_TEST(0 == std::remove(p.c_str()));
+
+    // Also remove the temporary directory created by this function.
+    //
+    // These calls to std::remove() fail, at least with 'wine':
+//  BOOST_TEST(0 == std::remove(tmp.c_str()));
+//  BOOST_TEST(0 == std::remove(tmpdir.string().c_str()));
+    // They return nonzero, and do not remove the directory. The
+    // reason is that the msw C library's remove() function doesn't
+    // delete directories; it sets errno to 13, which means EACCESS,
+    // and _doserrno to 5, which might mean EIO. The boost:filesystem
+    // msw implementation calls RemoveDirectoryA() instead of the C
+    // remove() function in this case. The std::filesystem::remove()
+    // specification in C++17 (N4659) [30.10.15.30] says:
+    //   "the file p is removed as if by POSIX remove()".
+    // Therefore, use the filesystem function to remove the directory:
+    fs::remove(tmpdir);
+    // For std::filesystem::remove(), this is a documented
+    // postcondition. It does no harm to validate it here.
+    BOOST_TEST(0 != access(tmpdir.string().c_str(), R_OK));
 }
 
 void test_unique_filepath_with_ludicrous_filenames()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]