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 commandon the command line, I get a permission denial. I know about it. This is exactly what I want to check.
aSystemCallexecutes the command as a child process. When a child exits with a non-zero error for this command, aSystemCallreturns an error. He does not quit.
If I run a test case BadDiron the command line, the code after aSystemCallwill never be executed, and the test will fail, 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 the test case BadDirin gdb, it aSystemCallreturns, the result can be checked, and the test will pass.
boost:: unit_test, , , ? BOOST_AUTO_TEST_CASE_EXPECTED_FAILURE(blah, 1), boost:: unit_test, . ( ) . .