the Compartmented Robust Posix C++ Unit Test system |
|
---|
A test modifier which states that the normal way to finish the
test is via exit()
instead of returning from
the function.
Used in: The modifier list of a test.
See TEST(name, ...)
Parameters
num
ANY_CODE
if any exit code is accepted.
action?
WIPE_WORKING_DIR
.
If the test finishes through any other means, it fails.
Note | |
---|---|
EXPECT_EXIT(num, action?) cannot be used together
with either of EXPECT_EXCEPTION(type)
or EXPECT_SIGNAL_DEATH(signo, action?) .
|
Example: The test program
#include <crpcut.hpp> TEST(fail_no_exit, EXPECT_EXIT(ANY_CODE)) { } TEST(pass_any_code, EXPECT_EXIT(ANY_CODE)) { exit(3); } TEST(fail_wrong_code, EXPECT_EXIT(3)) { exit(0); } TEST(pass_correct_code, EXPECT_EXIT(3)) { exit(3); } TEST(fail_by_exception, EXPECT_EXIT(ANY_CODE)) { throw std::bad_alloc(); } int main(int argc, char *argv[]) { return crpcut::run(argc, argv); }
reports three failed tests:
FAILED!: fail_no_exit phase="running" -------------------------------------------------------------- samples/expect_exit.cpp:30 Unexpectedly survived Expected exit with any code ------------------------------------------------------------------------------- =============================================================================== FAILED!: fail_wrong_code phase="running" -------------------------------------------------------------- samples/expect_exit.cpp:39 Exited with code 0 Expected exit with code 3 ------------------------------------------------------------------------------- =============================================================================== FAILED!: fail_by_exception phase="running" -------------------------------------------------------------- samples/expect_exit.cpp:49 Unexpectedly caught std::exception what()=std::bad_alloc ------------------------------------------------------------------------------- =============================================================================== 5 test cases selected Sum Critical Non-critical PASSED : 2 2 0 FAILED : 3 3 0