Add except, unexcept in suite

This commit is contained in:
Vinnie Falco
2015-07-24 16:15:43 -07:00
committed by Edward Hennis
parent 5063839ce5
commit 1883b40083

View File

@@ -176,6 +176,48 @@ public:
return expect (shouldBeTrue, "");
}
/** Expect an exception from f() */
/** @{ */
template <class F, class String>
bool
except (F&& f, String const& reason);
template <class F>
bool
except (F&& f)
{
return except(f, "");
}
/** @} */
/** Expect an exception of the given type from f() */
/** @{ */
template <class E, class F, class String>
bool
except (F&& f, String const& reason);
template <class E, class F>
bool
except (F&& f)
{
return except<E>(f, "");
}
/** @} */
/** Fail if f() throws */
/** @{ */
template <class F, class String>
bool
unexcept (F&& f, String const& reason);
template <class F>
bool
unexcept (F&& f)
{
return unexcept(f, "");
}
/** @} */
/** Return the argument associated with the runner. */
std::string const&
arg() const
@@ -355,6 +397,57 @@ suite::expect (Condition shouldBeTrue,
return b;
}
template <class F, class String>
bool
suite::except (F&& f, String const& reason)
{
try
{
f();
fail(reason);
return false;
}
catch(...)
{
pass();
}
return true;
}
template <class E, class F, class String>
bool
suite::except (F&& f, String const& reason)
{
try
{
f();
fail(reason);
return false;
}
catch(E const&)
{
pass();
}
return true;
}
template <class F, class String>
bool
suite::unexcept (F&& f, String const& reason)
{
try
{
f();
pass();
return true;
}
catch(...)
{
fail(reason);
}
return false;
}
template <class Condition, class String>
inline
bool