Boost :: unit_test does not work because the child process exits with non-zero

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, . ( ) . .

+3
5

Boost.Test

0

, Linux.

, Boost.Test . boost " " boost/test/included/unit_test.hpp, :

#define BOOST_TEST_IGNORE_NON_ZERO_CHILD_CODE

- include .

, . "--catch_system_errors = no", .

export BOOST_TEST_CATCH_SYSTEM_ERRORS="no"

boost 1.52 1.57, GCC 4.7.2, debian wheezy.

Boost.Test

. : how-to-cancel-fatal-error-detection-in-boost-test

+4

--catch_system_errors = no .

, BOOST_CHECK_THROW #define, unit_test, .

+1

, "no" Boost catch_system_errors. Ubuntu OS :

export BOOST_TEST_CATCH_SYSTEM_ERRORS="no"
0
source

Bit extension in Chip Christian answer : (re) compiling boost.test using the BOOST_TEST_IGNORE_NON_ZERO_CHILD_CODE flag (tested on boost 1.53). At the bjam command line, add:

cxxflags="-DBOOST_TEST_IGNORE_NON_ZERO_CHILD_CODE"

Note that adding this flag did not always result in recompilation, so I did the following to force recompilation:

touch boost/test/impl/execution_monitor.ipp
0
source

All Articles