diff --git a/tap.hpp b/tap.hpp index c1ddf001..5ffc414a 100644 --- a/tap.hpp +++ b/tap.hpp @@ -55,6 +55,10 @@ namespace util { namespace TAP { //--------------------------------------------------------------------- template void expect_nan (const T&, const std::string &msg = "nan"); + //--------------------------------------------------------------------- + template void expect_nothrow (T&&, const std::string &msg = "nothrow"); + template void expect_throw (T&&, const std::string &msg = "throw"); + //--------------------------------------------------------------------- void skip (const std::string &msg); void todo (const std::string &msg); diff --git a/tap.ipp b/tap.ipp index 570b2513..8eb580f5 100644 --- a/tap.ipp +++ b/tap.ipp @@ -68,8 +68,10 @@ util::TAP::logger::expect_ ## SUFFIX (const T &a, \ const U &b, \ const std::string &msg) \ { \ - static const std::function TEST = [] (const T&t, const U&u) { return t OP u; }; \ - expect (TEST, a, b, msg); \ + 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); \ } TAP_TEST(gt, > ) @@ -88,3 +90,37 @@ util::TAP::logger::expect_nan (const T &t, const std::string &msg) bool(*func)(T) = std::isnan; expect (std::function (func), t, msg); } + + +//----------------------------------------------------------------------------- +template +void +util::TAP::logger::expect_nothrow (T &&t, const std::string &msg) +{ + bool success = true; + + try { + t (); + } catch (...) { + success = false; + } + + expect (success, msg); +} + + +//----------------------------------------------------------------------------- +template +void +util::TAP::logger::expect_throw (T &&t, const std::string &msg) +{ + bool success = false; + + try { + t (); + } catch (const E&) { + success = true; + } + + expect (success, msg); +}