the Compartmented Robust Posix C++ Unit Test system |
|
---|
Assert 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 assertion 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 terminated 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:
VERIFY_NO_THROW(expr)
Example: The test program
#include <crpcut.hpp> class type {}; TEST(assert_no_throw_succeeds) { int n = 0; ASSERT_NO_THROW(n+=3); } TEST(assert_no_throw_fails) { ASSERT_NO_THROW(throw type()); } int main(int argc, char *argv[]) { return crpcut::run(argc, argv); }
reports one failed test:
FAILED!: assert_no_throw_fails phase="running" -------------------------------------------------------------- samples/assert_no_throw_fails.cpp:40 ASSERT_NO_THROW(throw type()) caught ... ------------------------------------------------------------------------------- =============================================================================== 2 test cases selected Sum Critical Non-critical PASSED : 1 1 0 FAILED : 1 1 0