lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master caf6f55 3/3: Guard against unit-test failures


From: Greg Chicares
Subject: [lmi-commits] [lmi] master caf6f55 3/3: Guard against unit-test failures
Date: Sat, 4 May 2019 16:22:20 -0400 (EDT)

branch: master
commit caf6f55067448e3ddf9c30b7be5bb7f09fdcfa15
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Guard against unit-test failures
    
    Began using different throwaway directories for different unit tests
    to prevent one from interfering with another when run in parallel.
---
 authenticity_test.cpp     |  4 +++-
 name_value_pairs_test.cpp |  9 ++++++---
 path_utility_test.cpp     | 25 ++++++++++++++-----------
 3 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/authenticity_test.cpp b/authenticity_test.cpp
index 83316ce..9b3a0fb 100644
--- a/authenticity_test.cpp
+++ b/authenticity_test.cpp
@@ -30,6 +30,7 @@
 #include "system_command.hpp"
 #include "test_tools.hpp"
 
+#include <boost/filesystem/convenience.hpp> // basename()
 #include <boost/filesystem/fstream.hpp>
 #include <boost/filesystem/operations.hpp>
 #include <boost/filesystem/path.hpp>
@@ -282,7 +283,8 @@ void PasskeyTest::TestFromAfar() const
 {
     CheckNominal(__FILE__, __LINE__);
 
-    fs::path const remote_dir_0(fs::complete("/tmp"));
+    std::string const tmp = "/tmp/" + fs::basename(__FILE__);
+    fs::path const remote_dir_0(fs::complete(tmp));
     fs::create_directory(remote_dir_0);
     BOOST_TEST(fs::exists(remote_dir_0) && fs::is_directory(remote_dir_0));
     BOOST_TEST_EQUAL(0, chdir(remote_dir_0.string().c_str()));
diff --git a/name_value_pairs_test.cpp b/name_value_pairs_test.cpp
index 0efa547..3bfc017 100644
--- a/name_value_pairs_test.cpp
+++ b/name_value_pairs_test.cpp
@@ -26,18 +26,21 @@
 #include "miscellany.hpp"
 #include "test_tools.hpp"
 
+#include <boost/filesystem/convenience.hpp> // basename()
 #include <boost/filesystem/operations.hpp>
 #include <boost/filesystem/path.hpp>
 
 #include <cstdio>                       // remove()
 #include <fstream>
+#include <string>
 
 int test_main(int, char*[])
 {
-    fs::path const tmpdir(fs::complete("/tmp"));
+    std::string const tmp = "/tmp/" + fs::basename(__FILE__);
+    fs::path const tmpdir(fs::complete(tmp));
     fs::create_directory(tmpdir);
 
-    std::string filename0("/tmp/eraseme");
+    std::string filename0(tmp + "/eraseme");
 
     {
     std::ofstream os(filename0.c_str(), ios_out_trunc_binary());
@@ -98,7 +101,7 @@ int test_main(int, char*[])
     BOOST_TEST_EQUAL("2.718" , nv_pairs_0.string_numeric_value("v"));
     BOOST_TEST_EQUAL("0"     , nv_pairs_0.string_numeric_value("s"));
 
-    std::string filename1("/tmp/nonexistent_name_value_pairs_test_file");
+    std::string filename1(tmp + "/nonexistent_name_value_pairs_test_file");
     name_value_pairs nv_pairs_1(filename1);
     std::map<std::string, std::string> m1 = nv_pairs_1.map();
     BOOST_TEST_EQUAL(0, m1.size());
diff --git a/path_utility_test.cpp b/path_utility_test.cpp
index 21b4c89..5c6d13f 100644
--- a/path_utility_test.cpp
+++ b/path_utility_test.cpp
@@ -27,6 +27,7 @@
 #include "platform_dependent.hpp"       // access()
 #include "test_tools.hpp"
 
+#include <boost/filesystem/convenience.hpp> // basename()
 #include <boost/filesystem/exception.hpp>
 #include <boost/filesystem/fstream.hpp>
 #include <boost/filesystem/operations.hpp>
@@ -36,6 +37,7 @@
 #include <fstream>
 #include <sstream>
 #include <stdexcept>
+#include <string>
 
 namespace
 {
@@ -136,23 +138,24 @@ void test_serial_file_path()
 
 void test_unique_filepath_with_normal_filenames()
 {
-    fs::path const tmpdir(fs::complete("/tmp"));
+    std::string const tmp = "/tmp/" + fs::basename(__FILE__);
+    fs::path const tmpdir(fs::complete(tmp));
     fs::create_directory(tmpdir);
 
     // These tests would fail if read-only files with the following
     // names already exist.
 
-    char const* p = "/tmp/eraseme.0";
-    char const* q = "/tmp/eraseme.xyzzy";
+    std::string const p = (tmp + "/eraseme.0");
+    std::string const q = (tmp + "/eraseme.xyzzy");
 
     // Don't test the return codes here. These files probably don't
     // exist, in which case C99 7.19.4.1 doesn't clearly prescribe
     // the semantics of std::remove().
-    std::remove(p);
-    std::remove(q);
+    std::remove(p.c_str());
+    std::remove(q.c_str());
 
     write_dummy_file(p);
-    BOOST_TEST_EQUAL(0, access(p, R_OK));
+    BOOST_TEST_EQUAL(0, access(p.c_str(), R_OK));
 
     fs::path path0 = unique_filepath(fs::path(p), ".xyzzy");
     BOOST_TEST_EQUAL(path0.string(), q);
@@ -196,9 +199,9 @@ void test_unique_filepath_with_normal_filenames()
     // Even the timestamp's length is implementation dependent, so a
     // change in implementation may be discovered by a failure here.
 
-    char const* r = "/tmp/eraseme.abc.def";
-    char const* s = "/tmp/eraseme.abc-CCYYMMDDTHHMMSSZ.def";
-//             NOT:  /tmp/eraseme.abc-CCYYMMDDTHHMMSSZ.abc.def
+    std::string const r = (tmp + "/eraseme.abc.def");
+    std::string const s = (tmp + "/eraseme.abc-CCYYMMDDTHHMMSSZ.def");
+//                   NOT:  tmp +  /eraseme.abc-CCYYMMDDTHHMMSSZ.abc.def
 
     fs::path path3 = unique_filepath(fs::path(p), ".abc.def");
     BOOST_TEST_EQUAL(path3.string(), r);
@@ -218,8 +221,8 @@ void test_unique_filepath_with_normal_filenames()
     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));
-    BOOST_TEST(0 == std::remove(p));
+    BOOST_TEST(0 == std::remove(q.c_str()));
+    BOOST_TEST(0 == std::remove(p.c_str()));
 }
 
 void test_unique_filepath_with_ludicrous_filenames()



reply via email to

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