tap: add expect_throw, expect_nothrow

This commit is contained in:
Danny Robson 2015-07-02 17:03:36 +10:00
parent 75a1f1e5e7
commit e03d1e57e3
2 changed files with 42 additions and 2 deletions

View File

@ -55,6 +55,10 @@ namespace util { namespace TAP {
//---------------------------------------------------------------------
template <typename T> void expect_nan (const T&, const std::string &msg = "nan");
//---------------------------------------------------------------------
template <typename T> void expect_nothrow (T&&, const std::string &msg = "nothrow");
template <typename E, typename T> void expect_throw (T&&, const std::string &msg = "throw");
//---------------------------------------------------------------------
void skip (const std::string &msg);
void todo (const std::string &msg);

40
tap.ipp
View File

@ -68,8 +68,10 @@ util::TAP::logger::expect_ ## SUFFIX (const T &a, \
const U &b, \
const std::string &msg) \
{ \
static const std::function<bool(const T&,const U&)> TEST = [] (const T&t, const U&u) { return t OP u; }; \
expect<const T&, const U&> (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<const T&, const U&> (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<const T&> (std::function<bool(const T&)> (func), t, msg);
}
//-----------------------------------------------------------------------------
template <typename T>
void
util::TAP::logger::expect_nothrow (T &&t, const std::string &msg)
{
bool success = true;
try {
t ();
} catch (...) {
success = false;
}
expect (success, msg);
}
//-----------------------------------------------------------------------------
template <typename E, typename T>
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);
}