Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55611 - in trunk/libs/spirit: repository/test/karma test/karma
From: frabar666_at_[hidden]
Date: 2009-08-16 05:26:06


Author: fbarel
Date: 2009-08-16 05:26:05 EDT (Sun, 16 Aug 2009)
New Revision: 55611
URL: http://svn.boost.org/trac/boost/changeset/55611

Log:
Spirit: make Karma tests more verbose on failure
Text files modified:
   trunk/libs/spirit/repository/test/karma/test.hpp | 21 +++++++++++++++++++++
   trunk/libs/spirit/test/karma/test.hpp | 21 +++++++++++++++++++++
   trunk/libs/spirit/test/karma/test_attr.hpp | 16 ++++++++++++++++
   trunk/libs/spirit/test/karma/test_manip_attr.hpp | 22 ++++++++++++++++++++++
   4 files changed, 80 insertions(+), 0 deletions(-)

Modified: trunk/libs/spirit/repository/test/karma/test.hpp
==============================================================================
--- trunk/libs/spirit/repository/test/karma/test.hpp (original)
+++ trunk/libs/spirit/repository/test/karma/test.hpp 2009-08-16 05:26:05 EDT (Sun, 16 Aug 2009)
@@ -44,6 +44,19 @@
     };
 
     ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename T>
+ void print_if_failed(char const* func, bool result
+ , std::basic_string<Char> const& generated, T const& expected)
+ {
+ if (!result)
+ std::cerr << "in " << func << ": result is false" << std::endl;
+ else if (generated != expected)
+ std::cerr << "in " << func << ": generated \""
+ << std::string(generated.begin(), generated.end())
+ << "\"" << std::endl;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
     template <typename Char, typename Generator>
     inline bool test(Char const *expected, Generator const& g)
     {
@@ -58,6 +71,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate(outit, g);
 
+ print_if_failed("test", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -75,6 +89,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate(outit, g);
 
+ print_if_failed("test", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -94,6 +109,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate(outit, g, attr);
 
+ print_if_failed("test", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -112,6 +128,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate(outit, g, attr);
 
+ print_if_failed("test", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -131,6 +148,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate_delimited(outit, g, d);
 
+ print_if_failed("test_delimited", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -149,6 +167,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate_delimited(outit, g, d);
 
+ print_if_failed("test_delimited", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -169,6 +188,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate_delimited(outit, g, d, attr);
 
+ print_if_failed("test_delimited", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -188,6 +208,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate_delimited(outit, g, d, attr);
 
+ print_if_failed("test_delimited", result, generated, expected);
         return result && generated == expected;
     }
 

Modified: trunk/libs/spirit/test/karma/test.hpp
==============================================================================
--- trunk/libs/spirit/test/karma/test.hpp (original)
+++ trunk/libs/spirit/test/karma/test.hpp 2009-08-16 05:26:05 EDT (Sun, 16 Aug 2009)
@@ -44,6 +44,19 @@
     };
 
     ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename T>
+ void print_if_failed(char const* func, bool result
+ , std::basic_string<Char> const& generated, T const& expected)
+ {
+ if (!result)
+ std::cerr << "in " << func << ": result is false" << std::endl;
+ else if (generated != expected)
+ std::cerr << "in " << func << ": generated \""
+ << std::string(generated.begin(), generated.end())
+ << "\"" << std::endl;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
     template <typename Char, typename Generator>
     inline bool test(Char const *expected, Generator const& g)
     {
@@ -58,6 +71,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate(outit, g);
 
+ print_if_failed("test", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -75,6 +89,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate(outit, g);
 
+ print_if_failed("test", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -94,6 +109,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate(outit, g, attr);
 
+ print_if_failed("test", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -112,6 +128,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate(outit, g, attr);
 
+ print_if_failed("test", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -131,6 +148,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate_delimited(outit, g, d);
 
+ print_if_failed("test_delimited", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -149,6 +167,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate_delimited(outit, g, d);
 
+ print_if_failed("test_delimited", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -169,6 +188,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate_delimited(outit, g, d, attr);
 
+ print_if_failed("test_delimited", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -188,6 +208,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate_delimited(outit, g, d, attr);
 
+ print_if_failed("test_delimited", result, generated, expected);
         return result && generated == expected;
     }
 

Modified: trunk/libs/spirit/test/karma/test_attr.hpp
==============================================================================
--- trunk/libs/spirit/test/karma/test_attr.hpp (original)
+++ trunk/libs/spirit/test/karma/test_attr.hpp 2009-08-16 05:26:05 EDT (Sun, 16 Aug 2009)
@@ -31,6 +31,19 @@
         typedef std::basic_string<Char> string_type;
         typedef std::back_insert_iterator<string_type> type;
     };
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename T>
+ void print_if_failed(char const* func, bool result
+ , std::basic_string<Char> const& generated, T const& expected)
+ {
+ if (!result)
+ std::cerr << "in " << func << ": result is false" << std::endl;
+ else if (generated != expected)
+ std::cerr << "in " << func << ": generated \""
+ << std::string(generated.begin(), generated.end())
+ << "\"" << std::endl;
+ }
 }
 
 #define BOOST_PP_FILENAME_1 "karma/test_attr.hpp"
@@ -67,6 +80,7 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate(outit, g, BOOST_PP_ENUM_PARAMS(N, attr));
 
+ print_if_failed("test", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -88,6 +102,7 @@
         bool result = karma::generate_delimited(outit, g, d
           , BOOST_PP_ENUM_PARAMS(N, attr));
 
+ print_if_failed("test_delimited", result, generated, expected);
         return result && generated == expected;
     }
 
@@ -111,6 +126,7 @@
         bool result = karma::generate_delimited(outit, g, d
           , pre_delimit, BOOST_PP_ENUM_PARAMS(N, attr));
 
+ print_if_failed("test_predelimited", result, generated, expected);
         return result && generated == expected;
     }
 

Modified: trunk/libs/spirit/test/karma/test_manip_attr.hpp
==============================================================================
--- trunk/libs/spirit/test/karma/test_manip_attr.hpp (original)
+++ trunk/libs/spirit/test/karma/test_manip_attr.hpp 2009-08-16 05:26:05 EDT (Sun, 16 Aug 2009)
@@ -21,6 +21,22 @@
 #include <boost/preprocessor/repetition/enum_params.hpp>
 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
 
+namespace spirit_test
+{
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename T>
+ void print_if_failed(char const* func, bool result
+ , std::basic_string<Char> const& generated, T const& expected)
+ {
+ if (!result)
+ std::cerr << "in " << func << ": result is false" << std::endl;
+ else if (generated != expected)
+ std::cerr << "in " << func << ": generated \""
+ << std::string(generated.begin(), generated.end())
+ << "\"" << std::endl;
+ }
+}
+
 #define BOOST_PP_FILENAME_1 "karma/test_manip_attr.hpp"
 #define BOOST_PP_ITERATION_LIMITS (1, SPIRIT_ARGUMENTS_LIMIT)
 #include BOOST_PP_ITERATE()
@@ -48,6 +64,8 @@
 
         std::ostringstream ostrm;
         ostrm << karma::format(g, BOOST_PP_ENUM_PARAMS(N, attr));
+
+ print_if_failed("test", ostrm.good(), ostrm.str(), expected);
         return ostrm.good() && ostrm.str() == expected;
     }
 
@@ -61,6 +79,8 @@
 
         std::ostringstream ostrm;
         ostrm << karma::format_delimited(g, d, BOOST_PP_ENUM_PARAMS(N, attr));
+
+ print_if_failed("test_delimited", ostrm.good(), ostrm.str(), expected);
         return ostrm.good() && ostrm.str() == expected;
     }
 
@@ -77,6 +97,8 @@
         std::ostringstream ostrm;
         ostrm << karma::format_delimited(g, d, pre_delimit
           , BOOST_PP_ENUM_PARAMS(N, attr));
+
+ print_if_failed("test_predelimited", ostrm.good(), ostrm.str(), expected);
         return ostrm.good() && ostrm.str() == expected;
     }
 


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