I have the following code:
bool f()
{
command = "mkdir -p /\/\/";
result = aSystemCall(command);
if (result == ...
}
BOOST_AUTO_TEST_CASE(BadDir)
{
BOOST_CHECK_EQUAL(false, f());
}
If I execute command
in command line, I get a permission denied error. I'm aware of this. That's exactly what I want to test.
aSystemCall
executes the command as a child process. As the child exits with a nonzero error for this command, aSystemCall
returns an error. It doesn't throw.
If I run BadDir
test case in command line, the code after aSystemCall
is never executed, and the test fails, with the following output:
mkdir: cannot create directory '/\/\/': Permission denied
unknown location(0): fatal error in "BadDir": child has exited; pid: 25356; uid: 19753; exit value: 1
test.cpp(100): last checkpoint
Leaving test case "BadDir"; testing time: 10ms
Leaving test suite "Test"
Leaving test suite "Master Test Suite"
If I run BadDir
test case within gdb, aSystemCall
returns, the result can be checked, and the test passes.
Is there a way to telling boost::unit_test to filter out possible errors like this one, so that execution can continue? I've tried BOOST_AUTO_TEST_CASE_EXPECTED_FAILURE(blah, 1)
, but this is just to tell boost::unit_test that you are expecting a failure. It reports failure detected (failure expected) in test. I would like a passed test situation instead.