lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 2537153 26/28: Fix test_path_validation() for


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 2537153 26/28: Fix test_path_validation() for compilers without char8_t support
Date: Wed, 12 May 2021 18:14:46 -0400 (EDT)

branch: master
commit 25371530e45d0ec36cc9959e3a67620e4b34bba9
Author: Vadim Zeitlin <vadim@tt-solutions.com>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Fix test_path_validation() for compilers without char8_t support
    
    This makes the test pass with clang-11 and, more generally, makes it
    more robust by not relying on having the part of the string following
    the first NUL character in the exception error message, as this message
    is constructed using std::runtime_error::what() returning "const char*"
    and so is always terminated by the first NUL in it.
    
    Note that previously the test still passed with the compilers that do
    support char8_t because of the compensating buglet in fs::path, whose
    u8string_as_string() also truncated the string at the first NUL, and did
    it before constructing std::runtime_error(), thus ensuring that the
    string passed to it didn't contain any NULs any longer and so, while the
    part of the path after the first NUL was still lost (even if this was
    difficult to see with a path containing only NULs, as was previously
    used in the test, which is the reason for adding non-NUL characters to
    it too now), the rest of the string could be recovered later.
---
 path_utility_test.cpp | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/path_utility_test.cpp b/path_utility_test.cpp
index 4f4adc6..acfedcf 100644
--- a/path_utility_test.cpp
+++ b/path_utility_test.cpp
@@ -418,11 +418,17 @@ void test_path_validation()
     // next two tests are senseless.
 
     // Neither posix nor msw allows NUL in paths.
-    std::string nulls = {'\0', '\0'};
+    std::string with_nulls = {'x', '\0', 'y', '\0', 'z'};
+
+    // Note that we can't test for the full error message here because it is
+    // truncated at the first NUL, due to using std::runtime_error::what(),
+    // which returns "char*" string terminated by the first NUL occurring in
+    // it, when constructing this message, so just check that it starts with
+    // the expected part.
     LMI_TEST_THROW
-        (validate_filepath(nulls, context)
+        (validate_filepath(with_nulls, context)
         ,std::runtime_error
-        ,"Unit test file '' not found."
+        ,lmi_test::what_regex("^Unit test file 'x")
         );
 
     // Posix doesn't forbid these characters, though msw does.



reply via email to

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