diff --git a/tap.hpp b/tap.hpp index 5ffc414a..cec93d36 100644 --- a/tap.hpp +++ b/tap.hpp @@ -43,21 +43,35 @@ namespace util { namespace TAP { void expect (std::function, Args&&..., const std::string& msg); //--------------------------------------------------------------------- - template void expect_eq (const T&, const U&, const std::string &msg = "equality"); - template void expect_neq (const T&, const U&, const std::string &msg = "inequality"); + template + void expect_eq (const T&, const U&, const std::string &fmt = "equality", Args&...); + + template + void expect_neq (const T&, const U&, const std::string &msg = "inequality", Args&...); //--------------------------------------------------------------------- - template void expect_gt (const T&, const U&, const std::string &msg = "gt"); - template void expect_ge (const T&, const U&, const std::string &msg = "ge"); - template void expect_lt (const T&, const U&, const std::string &msg = "lt"); - template void expect_le (const T&, const U&, const std::string &msg = "le"); + template + void expect_gt (const T&, const U&, const std::string &msg = "gt", Args&...); + + template + void expect_ge (const T&, const U&, const std::string &msg = "ge", Args&...); + + template + void expect_lt (const T&, const U&, const std::string &msg = "lt", Args&...); + + template + void expect_le (const T&, const U&, const std::string &msg = "le", Args&...); //--------------------------------------------------------------------- - template void expect_nan (const T&, const std::string &msg = "nan"); + template + void expect_nan (const T&, const std::string &msg = "nan", Args&...); //--------------------------------------------------------------------- - template void expect_nothrow (T&&, const std::string &msg = "nothrow"); - template void expect_throw (T&&, const std::string &msg = "throw"); + template + void expect_nothrow (T&&, const std::string &msg = "nothrow", Args&...); + + template + void expect_throw (T&&, const std::string &msg = "throw", Args&...); //--------------------------------------------------------------------- void skip (const std::string &msg); diff --git a/tap.ipp b/tap.ipp index 8eb580f5..5ca1a675 100644 --- a/tap.ipp +++ b/tap.ipp @@ -24,6 +24,8 @@ #include #include +#include "format.hpp" + //----------------------------------------------------------------------------- template @@ -35,43 +37,52 @@ util::TAP::logger::expect (std::function test, Args&&... args, co //----------------------------------------------------------------------------- -template +template void -util::TAP::logger::expect_eq (const T&a, const U &b, const std::string &msg) +util::TAP::logger::expect_eq (const T&a, const U &b, const std::string &fmt, Args&... args) { static const std::function TEST = [] (const T &t, const U &u) -> bool { return almost_equal (t, u); }; - expect (TEST, a, b, msg); + expect (TEST, a, b, util::format::render (fmt, std::forward (args)...)); } //----------------------------------------------------------------------------- -template +template void -util::TAP::logger::expect_neq (const T&a, const U &b, const std::string &msg) +util::TAP::logger::expect_neq (const T&a, const U &b, const std::string &fmt, Args&... args) { static const std::function TEST = [] (const T &t, const U &u) -> bool { return !almost_equal (t, u); }; - expect (TEST, a, b, msg); + expect (TEST, a, b, util::format::render (fmt, std::forward (args)...)); } //----------------------------------------------------------------------------- #define TAP_TEST(SUFFIX,OP) \ -template \ +template \ void \ util::TAP::logger::expect_ ## SUFFIX (const T &a, \ const U &b, \ - const std::string &msg) \ + const std::string &fmt, \ + Args&... args) \ { \ static const std::function< \ bool(const T&,const U&) \ > TEST = [] (const T&t, const U&u) { return t OP u; }; \ - expect (TEST, a, b, msg); \ + \ + expect ( \ + TEST, \ + a, b, \ + util::format::render ( \ + fmt, \ + std::forward (args)... \ + ) \ + ); \ } TAP_TEST(gt, > ) @@ -83,19 +94,23 @@ TAP_TEST(le, <=) //----------------------------------------------------------------------------- -template +template void -util::TAP::logger::expect_nan (const T &t, const std::string &msg) +util::TAP::logger::expect_nan (const T &t, const std::string &fmt, Args&... args) { bool(*func)(T) = std::isnan; - expect (std::function (func), t, msg); + expect ( + std::function (func), + t, + util::format::render (fmt, std::forward (args)...) + ); } //----------------------------------------------------------------------------- -template +template void -util::TAP::logger::expect_nothrow (T &&t, const std::string &msg) +util::TAP::logger::expect_nothrow (T &&t, const std::string &fmt, Args&... args) { bool success = true; @@ -105,14 +120,14 @@ util::TAP::logger::expect_nothrow (T &&t, const std::string &msg) success = false; } - expect (success, msg); + expect (success, util::format::render (fmt, std::forward (args)...)); } //----------------------------------------------------------------------------- -template +template void -util::TAP::logger::expect_throw (T &&t, const std::string &msg) +util::TAP::logger::expect_throw (T &&t, const std::string &fmt, Args&... args) { bool success = false; @@ -120,7 +135,9 @@ util::TAP::logger::expect_throw (T &&t, const std::string &msg) t (); } catch (const E&) { success = true; + } catch (...) { + success = false; } - expect (success, msg); + expect (success, util::format::render (fmt, std::forward (args)...)); }