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.
First of all i get this odd behavior only on Linux.
I've found that Boost.Test changes the way it handles child exit codes with the deploy model you choose.
If you are using static linking of boost libraries or the "all in one" header boost/test/included/unit_test.hpp inserting a define:
#define BOOST_TEST_IGNORE_NON_ZERO_CHILD_CODE
before any include directive solves the problem.
If you are using dynamic linking, this isn't enough. You have either to call the resulting test with the command line option "--catch_system_errors=no" or define the following environment variable.
export BOOST_TEST_CATCH_SYSTEM_ERRORS="no"
I'm using boost 1.52 and 1.57, GCC 4.7.2, on a debian wheezy.
Here is the reference to deploy models of Boost.Test
see also this question: how-to-cancel-fatal-error-detection-in-boost-test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With