lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master b64436f 19/33: Improve modify_directory() doc


From: Greg Chicares
Subject: [lmi-commits] [lmi] master b64436f 19/33: Improve modify_directory() documentation and tests
Date: Mon, 3 May 2021 08:15:53 -0400 (EDT)

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

    Improve modify_directory() documentation and tests
---
 path_utility.cpp      | 19 +++++++++++--------
 path_utility_test.cpp | 18 ++++++++++++++++++
 2 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/path_utility.cpp b/path_utility.cpp
index acc9fb3..a954def 100644
--- a/path_utility.cpp
+++ b/path_utility.cpp
@@ -36,17 +36,20 @@
 
 /// Change '/path/to/file' to '/some/other/place/file'.
 ///
-/// Motivation: It was anomalous that boost did this:
+/// Motivation: lmi must provide this function because the standard
+/// library doesn't.
+///
+/// Given
 ///   fs::path file("/bin/sh";
 ///   fs::path dir ("/usr/bin");
-///   dir / file; // boost returned "/usr/bin/bin/sh"
-/// even on posix, where
-///   true == file.is_complete() // boost
-/// It is at least weird that std::filesystem does this:
-///   dir / file; // C++20 std::filesystem returns "/bin/sh"
-/// BOOST !! Rewrite the next two lines:
+/// what should 'dir / file' yield? Oddly, boost returned:
+///   /usr/bin/bin/sh
 /// even on posix, where
-///   true == file.is_absolute() // std::filesystem
+///   true == file.is_complete() // old boost function name
+/// It is odd, in a different way, that std::filesystem returns:
+///   /bin/sh
+/// both on posix (where true == file.is_absolute()), and also on
+/// msw (where, without a 'root-name', it isn't "absolute").
 ///
 /// Arguably the arguments should be given in the opposite order:
 ///   modify_directory("sh", "/usr/bin") // present order
diff --git a/path_utility_test.cpp b/path_utility_test.cpp
index 4d48606..beb1d80 100644
--- a/path_utility_test.cpp
+++ b/path_utility_test.cpp
@@ -58,6 +58,24 @@ void test_modify_directory()
     // Motivating case:
     LMI_TEST_EQUAL("/usr/bin/sh"  , modify_directory("/bin/sh", 
"/usr/bin").string());
 
+    // First argument: "/bin/sh"
+
+    fs::path old_path ("/bin/sh");
+    fs::path newdir   ("/usr/bin");
+    fs::path expected ("/usr/bin/sh");
+
+    fs::path f = fs::absolute(old_path);
+    fs::path d = fs::absolute(newdir);
+    fs::path x = fs::absolute(expected);
+
+    // this result is expected...
+    LMI_TEST_EQUAL(x, modify_directory(f, d).string());
+    // ...but these are surprising:
+    LMI_TEST_EQUAL(f, (d / f).string());
+    LMI_TEST_EQUAL(old_path, (newdir / old_path).string());
+
+    // First argument: just "sh"
+
     fs::path const file("sh");
     fs::path const dir0("/bin");
     fs::path const dir1("/usr/bin/");



reply via email to

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