the Compartmented Robust Posix C++ Unit Test system |
|
---|
Verify that an expression does not throw any exception.
Used in: A test function body, the constructor or destructor of a
fixture, or a function called from
them.
See TEST(name, ...)
.
Requirement: expr;
can be used as a complete
statement.
The check succeeds if, and only if, the statement
expr;
does not throw any exception.
On success the test function continues without side effects.
On failure the test is marked as failed, but continues execution
with an error report. The report
includes the exact expression text and, if the exception inherits from
std::exception the string from the virtual
member function std::exception::what()
, or a
generic message otherwise.
See also:
ASSERT_NO_THROW(expr)
Example: The test program
#include <crpcut.hpp> #include <stdexcept> class type {}; TEST(verify_no_throw_succeeds) { int n = 0; VERIFY_NO_THROW(n+=3); } TEST(assert_no_throw_fails) { VERIFY_NO_THROW(throw type()); VERIFY_NO_THROW(throw std::range_error("haha!!")); } int main(int argc, char *argv[]) { return crpcut::run(argc, argv); }
reports one failed test with two failed
VERIFY_NO_THROW
() checks:
FAILED!: assert_no_throw_fails fail--------------------------------------------------------------------------- samples/verify_no_throw_fails.cpp:40 VERIFY_NO_THROW(throw type()) caught ... ------------------------------------------------------------------------------- fail--------------------------------------------------------------------------- samples/verify_no_throw_fails.cpp:41 VERIFY_NO_THROW(throw std::range_error("haha!!")) caught std::exception what()=haha!! ------------------------------------------------------------------------------- phase="running" -------------------------------------------------------------- samples/verify_no_throw_fails.cpp:38 Earlier VERIFY failed ------------------------------------------------------------------------------- =============================================================================== 2 test cases selected Sum Critical Non-critical PASSED : 1 1 0 FAILED : 1 1 0