| the Compartmented Robust Posix C++ Unit Test system | hosted by |
|---|
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, ...)
The parameter to
EXPECT_EXIT(num) is the
exit code, or ANY_CODE
if any exit code is accepted.
If the test finishes through any other means, it fails.
![]() | Note |
|---|---|
EXPECT_EXIT(num) cannot be used together with
either of EXPECT_EXCEPTION(type) or
EXPECT_SIGNAL_DEATH(signo).
|
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" --------------------------------------------------------------
Unexpectedly survived
Expected exit with any code
-------------------------------------------------------------------------------
===============================================================================
FAILED: fail_wrong_code
phase="post_mortem" ----------------------------------------------------------
Exited with code 0
Expected exit with code 3
-------------------------------------------------------------------------------
===============================================================================
FAILED: fail_by_exception
phase="running" --------------------------------------------------------------
Unexpectedly caught std::exception
what()=std::bad_alloc
-------------------------------------------------------------------------------
===============================================================================
Total 5 test cases selected
UNTESTED : 0
PASSED : 2
FAILED : 3