lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [6598] Permit regexen in thrown-exception tests


From: gchicares
Subject: [lmi-commits] [6598] Permit regexen in thrown-exception tests
Date: Tue, 17 May 2016 22:38:27 +0000 (UTC)

Revision: 6598
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=6598
Author:   chicares
Date:     2016-05-17 22:38:26 +0000 (Tue, 17 May 2016)
Log Message:
-----------
Permit regexen in thrown-exception tests

Modified Paths:
--------------
    lmi/trunk/ChangeLog
    lmi/trunk/test_main.cpp
    lmi/trunk/test_tools.hpp
    lmi/trunk/test_tools_test.cpp

Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2016-05-17 22:35:31 UTC (rev 6597)
+++ lmi/trunk/ChangeLog 2016-05-17 22:38:26 UTC (rev 6598)
@@ -39151,3 +39151,51 @@
   group_quote_pdf_gen_wx.cpp
 State individual (not group total) spouse rider amount.
 
+20160516T1556Z <address@hidden> [451]
+
+  group_quote_pdf_gen_wx.cpp
+  wx_table_generator.cpp
+  wx_table_generator.hpp
+Format totals and averages as other data are formatted (VZ).
+
+20160516T1608Z <address@hidden> [451]
+
+  catch_exceptions.hpp
+  gpt_server.cpp
+  mec_server.cpp
+  test_main.cpp
+Say why headers are included iff not obvious.
+
+20160516T1617Z <address@hidden> [451]
+
+  cpp_main.cpp
+  test_tools.hpp
+Reformat.
+
+20160516T2235Z <zeitlin> [451]
+
+  configure.ac
+Suppress deprecated declarations warnings in configure gcc build.
+
+20160516T2336Z <zeitlin> [451]
+
+  Makefile.am
+Fix building unit tests in autotools build.
+
+20160517T0100Z <address@hidden> [451]
+
+  test_tools.hpp
+Refactor.
+
+20160517T2235Z <address@hidden> [451]
+
+  workhorse.make
+Expunge obsolete _GLIBCXX_ macros, especially for concept checking.
+
+20160517T2238Z <address@hidden> [451]
+
+  test_main.cpp
+  test_tools.hpp
+  test_tools_test.cpp
+Permit regexen in thrown-exception tests.
+

Modified: lmi/trunk/test_main.cpp
===================================================================
--- lmi/trunk/test_main.cpp     2016-05-17 22:35:31 UTC (rev 6597)
+++ lmi/trunk/test_main.cpp     2016-05-17 22:38:26 UTC (rev 6598)
@@ -69,6 +69,8 @@
 #include "test_tools.hpp"
 
 #include <iostream>
+#include <ostream>
+#include <regex>
 #include <stdexcept>
 
 // GWC changed namespace 'boost' to prevent any conflict with code in
@@ -101,6 +103,33 @@
     {
         ++test::test_tools_successes;
     }
+
+    /// Preserve regex ctor argument so stream inserter can write it.
+    ///
+    /// The sole motivation for this simple std::regex wrapper is to
+    /// let BOOST_TEST_THROW print the regex in diagnostics like:
+    ///   "Caught 'XYZ' but expected '[0-9]*'."
+
+    class what_regex
+    {
+      public:
+        what_regex(std::string const& s) : s_(s) {}
+
+        std::string const& str() const {return s_;}
+
+      private:
+        std::string s_;
+    };
+
+    std::ostream& operator<<(std::ostream& os, what_regex const& z)
+    {
+        return os << z.str();
+    }
+
+    bool whats_what(std::string const& observed, what_regex const& expected)
+    {
+        return std::regex_search(observed, std::regex(expected.str()));
+    }
 } // namespace lmi_test
 
 // cpp_main()  --------------------------------------------------------------//

Modified: lmi/trunk/test_tools.hpp
===================================================================
--- lmi/trunk/test_tools.hpp    2016-05-17 22:35:31 UTC (rev 6597)
+++ lmi/trunk/test_tools.hpp    2016-05-17 22:38:26 UTC (rev 6598)
@@ -137,6 +137,10 @@
         || 0 == observed.compare(0, observed.find("\n[file "), expected)
         ;
 }
+
+class what_regex;
+
+bool whats_what(std::string const& observed, what_regex const& expected);
 } // namespace lmi_test
 
 /// Make sure 'expression' throws the anticipated exception. Signal an

Modified: lmi/trunk/test_tools_test.cpp
===================================================================
--- lmi/trunk/test_tools_test.cpp       2016-05-17 22:35:31 UTC (rev 6597)
+++ lmi/trunk/test_tools_test.cpp       2016-05-17 22:38:26 UTC (rev 6598)
@@ -104,8 +104,9 @@
         ;
     lmi_test::test::test_tools_errors = 0;
 
-    // This test, unlike the others above, should not fail. It makes
-    // sure that the anticipated and actually-thrown exceptions are
+    // The following tests, unlike those above, should not fail.
+
+    // 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
     // exceptions add.
@@ -114,13 +115,21 @@
         (throw_exception
             (std::runtime_error
                 ("arbitrary"
-                "\n[file <remainder of terminal substring to ignore>]"
+                "\n[file <remainder of terminal substring to ignore>"
                 )
             )
         ,std::runtime_error
         ,"arbitrary"
         );
 
+    // Test exception::what() against a regular expression.
+
+    BOOST_TEST_THROW
+        (throw_exception(std::runtime_error("Iteration 31: failure."))
+        ,std::runtime_error
+        ,lmi_test::what_regex("^Iteration [0-9]*: failure\\.$")
+        );
+
     return 0;
 }
 




reply via email to

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