lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 4530512 2/2: Visually distinguish simulated e


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 4530512 2/2: Visually distinguish simulated errors in the unit-test unit test
Date: Tue, 7 Feb 2017 20:43:17 -0500 (EST)

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

    Visually distinguish simulated errors in the unit-test unit test
---
 test_main.cpp       | 17 ++++++++++++++---
 test_tools.hpp      | 33 +++++++++++++++++----------------
 test_tools_test.cpp | 21 +++++++++++++--------
 3 files changed, 44 insertions(+), 27 deletions(-)

diff --git a/test_main.cpp b/test_main.cpp
index f676c69..67eede0 100644
--- a/test_main.cpp
+++ b/test_main.cpp
@@ -67,6 +67,7 @@
 #include <ostream>
 #include <regex>
 #include <stdexcept>
+#include <string>
 
 // GWC changed namespace 'boost' to prevent any conflict with code in
 // a later version of boost.
@@ -74,6 +75,12 @@ namespace lmi_test
 {
   namespace test
   {
+    // Change this to test this testing library's facilities without
+    // emitting this actual prefix, e.g., to force simulated errors.
+    // Change it back to perform tests that are intended to pass,
+    // e.g., tests to validate internal helpers such as whats_what().
+    std::string error_prefix = "\n**** ";
+
     int test_tools_errors = 0;  // Count of errors detected.
     int test_tools_successes = 0;  // Count of successful tests.
 
@@ -86,7 +93,7 @@ namespace lmi_test
 
     std::ostream& error_stream()
     {
-        return std::cout << "\n**** test failed: ";
+        return std::cout << test::error_prefix << "test failed: ";
     }
 
     void record_error()
@@ -151,7 +158,11 @@ int cpp_main(int argc, char* argv[])
 
     catch(lmi_test::test::test_tools_exception const&)
         {
-        std::cout << "\n**** previous test error is fatal" << std::endl;
+        std::cout
+            << lmi_test::test::error_prefix
+            << "previous test error is fatal"
+            << std::endl
+            ;
         // Reset so we don't get two messages.
         lmi_test::test::test_tools_errors = 0;
         result = lmi_test::exit_test_failure;
@@ -160,7 +171,7 @@ int cpp_main(int argc, char* argv[])
     if(lmi_test::test::test_tools_errors)
         {
         std::cout
-            << "\n**** "
+            << lmi_test::test::error_prefix
             << lmi_test::test::test_tools_errors
             << " test errors detected; "
             << lmi_test::test::test_tools_successes
diff --git a/test_tools.hpp b/test_tools.hpp
index 7735258..dd3fbda 100644
--- a/test_tools.hpp
+++ b/test_tools.hpp
@@ -193,22 +193,23 @@ bool whats_what(std::string const& observed, what_regex 
const& expected);
             }                                                 \
         }                                                     \
 
-#define INVOKE_BOOST_TEST(exp,file,line) \
-    if(!(exp))                           \
-        {                                \
-        lmi_test::record_error();        \
-        lmi_test::error_stream()         \
-            << "\n**** test failed: "    \
-            << (exp)                     \
-            << "\n[invoked from "        \
-            << "file " << (file) << ", " \
-            << "line: " << (line)        \
-            << "]"                       \
-            << BOOST_TEST_FLUSH          \
-            ;                            \
-        }                                \
-    else                                 \
-        lmi_test::record_success();      \
+#define INVOKE_BOOST_TEST(exp,file,line)    \
+    if(!(exp))                              \
+        {                                   \
+        lmi_test::record_error();           \
+        lmi_test::error_stream()            \
+            << lmi_test::test::error_prefix \
+            << "test failed: "              \
+            << (exp)                        \
+            << "\n[invoked from "           \
+            << "file " << (file) << ", "    \
+            << "line: " << (line)           \
+            << "]"                          \
+            << BOOST_TEST_FLUSH             \
+            ;                               \
+        }                                   \
+    else                                    \
+        lmi_test::record_success();         \
 
 #define INVOKE_BOOST_TEST_EQUAL(a,b,file,line)   \
     INVOKE_BOOST_TEST_RELATION(a,==,b,file,line) \
diff --git a/test_tools_test.cpp b/test_tools_test.cpp
index 29c5eba..6625b1f 100644
--- a/test_tools_test.cpp
+++ b/test_tools_test.cpp
@@ -50,6 +50,12 @@ void throw_exception(ExceptionType const& e)
 
 int test_main(int, char*[])
 {
+    // Tests in this special section may be designed to fail. Their
+    // failures are reported with a distinctive prefix so that they
+    // don't look like real errors.
+
+    lmi_test::test::error_prefix = "\n#### ";
+
     BOOST_TEST(always_true);
     BOOST_TEST(always_false);
 
@@ -74,10 +80,6 @@ int test_main(int, char*[])
     BOOST_TEST_THROW((void)(0), std::runtime_error, "arbitrary");
     BOOST_TEST_THROW(;, std::runtime_error, "arbitrary");
 
-    // COMPILER !! The next two tests fail with borland C++ 5.5.1 .
-    // Probably this is a compiler defect, but someday this should be
-    // investigated.
-
     BOOST_TEST_THROW
         (throw_exception(std::runtime_error("arbitrary"))
         ,std::logic_error
@@ -91,16 +93,19 @@ int test_main(int, char*[])
         );
 
     std::cout
-        << "\n[This is a test of the testing framework's error-reporting\n"
-        << "facilities. It is contrived to report simulated errors.\n"
-        << "On exit, its error counter is overridden so that it reports\n"
-        << "a total of zero errors.]"
+        << "\n[This is a test of the testing framework's error-reporting"
+        << "\nfacilities. It is contrived to report simulated errors,"
+        << "\nwhich are marked with four '#' rather than '*' characters"
+        << "\nand are excluded from the count of real errors reported"
+        << "\nupon exit.]"
         << std::endl
         ;
     lmi_test::test::test_tools_errors = 0;
 
     // The following tests, unlike those above, should not fail.
 
+    lmi_test::test::error_prefix = "\n**** ";
+
     // Ensure that the anticipated and actually-thrown exceptions are
     // treated as equivalent even though the latter has an extra
     // terminal substring beginning with "\n[file ", which some lmi



reply via email to

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