the Compartmented Robust Posix C++ Unit Test system |
|
---|
A test modifier which states that the normal way to finish the test is via a signal instead of returning from the function.
Used in: The modifier list of a test.
See TEST(name, ...)
Parameters
signo
ANY_CODE
if any signal is accepted.
action?
WIPE_WORKING_DIR
.
If the test finishes through any other means, it fails.
Tip | |
---|---|
EXPECT_SIGNAL_DEATH (SIGABRT )
is useful together with
NO_CORE_FILE to verify
that assert (expr ) traps.
|
Note | |
---|---|
EXPECT_SIGNAL_DEATH(signo) cannot be used together
with either of EXPECT_EXIT(num, action?) or
EXPECT_EXCEPTION(type) .
|
Example: The test program
#include <crpcut.hpp> extern "C" { #include <signal.h> } TEST(fail_no_signal, EXPECT_SIGNAL_DEATH(ANY_CODE)) { } TEST(pass_sigabort, EXPECT_SIGNAL_DEATH(SIGABRT), NO_CORE_FILE) { abort(); } TEST(fail_wrong_signal, EXPECT_SIGNAL_DEATH(SIGABRT), NO_CORE_FILE) { int *p = 0; *p = 1; } TEST(fail_by_exception, EXPECT_SIGNAL_DEATH(ANY_CODE)) { throw std::bad_alloc(); } int main(int argc, char *argv[]) { return crpcut::run(argc, argv); }
reports three failed tests:
FAILED!: fail_no_signal phase="running" -------------------------------------------------------------- samples/expect_signal_death.cpp:34 Unexpectedly survived Expected any signal ------------------------------------------------------------------------------- =============================================================================== FAILED!: fail_wrong_signal phase="running" -------------------------------------------------------------- samples/expect_signal_death.cpp:43 Died on signal 11 Expected signal 6 ------------------------------------------------------------------------------- =============================================================================== FAILED!: fail_by_exception phase="running" -------------------------------------------------------------- samples/expect_signal_death.cpp:49 Unexpectedly caught std::exception what()=std::bad_alloc ------------------------------------------------------------------------------- =============================================================================== 4 test cases selected Sum Critical Non-critical PASSED : 1 1 0 FAILED : 3 3 0