Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2007-09-30 00:05:33


Author: eric_niebler
Date: 2007-09-30 00:05:31 EDT (Sun, 30 Sep 2007)
New Revision: 39614
URL: http://svn.boost.org/trac/boost/changeset/39614

Log:
slightly more informative test errors
Text files modified:
   trunk/libs/xpressive/test/regress.ipp | 35 ++++++++++++++++++++++++++---------
   trunk/libs/xpressive/test/test.hpp | 13 +------------
   2 files changed, 27 insertions(+), 21 deletions(-)

Modified: trunk/libs/xpressive/test/regress.ipp
==============================================================================
--- trunk/libs/xpressive/test/regress.ipp (original)
+++ trunk/libs/xpressive/test/regress.ipp 2007-09-30 00:05:31 EDT (Sun, 30 Sep 2007)
@@ -13,6 +13,7 @@
 
 #include <locale>
 #include <vector>
+#include <string>
 #include <fstream>
 #include <iostream>
 #include <boost/lexical_cast.hpp>
@@ -24,8 +25,20 @@
 # include <crtdbg.h>
 #endif
 
+#ifndef BOOST_XPRESSIVE_NO_WREGEX
+namespace std
+{
+ inline std::ostream &operator <<(std::ostream &sout, std::wstring const &wstr)
+ {
+ for(std::size_t n = 0; n < wstr.size(); ++n)
+ sout.put(sout.narrow(wstr[n], '?'));
+ return sout;
+ }
+}
+#endif
+
 #define BOOST_XPR_CHECK(pred) \
- if(pred) {} else { BOOST_ERROR(format_msg(#pred).c_str()); }
+ if(pred) {} else { BOOST_ERROR(case_ << #pred); }
 
 using namespace boost::unit_test;
 using namespace boost::xpressive;
@@ -79,19 +92,23 @@
 sregex const rx_res = "res=" >> (s1= *_);
 sregex const rx_br = "br" >> (s1= +digit) >> '=' >> (s2= *_);
 
-///////////////////////////////////////////////////////////////////////////////
-// format_msg
-std::string format_msg(char const *msg)
+struct test_case_formatter
 {
- return test.section + " /" + test.pat + "/ : " + msg;
-}
+ friend std::ostream &operator <<(std::ostream &sout, test_case_formatter)
+ {
+ sout << test.section << " /" << test.pat << "/ : ";
+ return sout;
+ }
+};
+
+test_case_formatter const case_ = {};
 
 #ifndef BOOST_XPRESSIVE_NO_WREGEX
 ///////////////////////////////////////////////////////////////////////////////
 // widen
 // make a std::wstring from a std::string by widening according to the
 // current ctype<char> facet
-std::wstring widen(std::string const &str)
+inline std::wstring widen(std::string const &str)
 {
     std::ctype<char> const &ct = BOOST_USE_FACET(std::ctype<char>, std::locale());
     std::wstring res;
@@ -259,7 +276,7 @@
         {
             // test regex_replace
             std::basic_string<Char> res = regex_replace(test.str, rx, test.sub, test.match_flags);
- BOOST_XPR_CHECK(res == test.res);
+ BOOST_CHECK_MESSAGE(res == test.res, case_ << res << " != " << test.res );
         }
 
         if(0 == (test.match_flags & regex_constants::format_first_only))
@@ -330,7 +347,7 @@
     }
     catch(regex_error const &e)
     {
- BOOST_ERROR(format_msg(e.what()).c_str());
+ BOOST_ERROR(case_ << e.what());
     }
 }
 

Modified: trunk/libs/xpressive/test/test.hpp
==============================================================================
--- trunk/libs/xpressive/test/test.hpp (original)
+++ trunk/libs/xpressive/test/test.hpp 2007-09-30 00:05:31 EDT (Sun, 30 Sep 2007)
@@ -28,7 +28,7 @@
 #define L(x) BOOST_XPR_CSTR_(char_type, x)
 
 #define BOOST_XPR_CHECK(pred) \
- if( pred ) {} else { BOOST_ERROR( this->format_msg(#pred).c_str() ); }
+ if( pred ) {} else { BOOST_ERROR( this->section_ << " : " << #pred ); }
 
 using namespace boost::xpressive;
 
@@ -60,12 +60,6 @@
 struct no_match_t {};
 no_match_t const no_match = {};
 
-template<typename BidiIter>
-struct xpr_test_case;
-
-template<typename BidiIter>
-std::string format_msg(xpr_test_case<BidiIter> const &test, char const *msg);
-
 ///////////////////////////////////////////////////////////////////////////////
 // xpr_test_case
 //
@@ -117,11 +111,6 @@
 
 private:
 
- std::string format_msg(char const *msg) const
- {
- return this->section_ + " : " + msg;
- }
-
     std::string section_;
     string_type str_;
     regex_type rex_;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk