diff --git a/CHANGELOG.md b/CHANGELOG.md index e40d518..10ca38b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.4.4 + +- Properly handle fixture failures in Boost.Test. + Thanks @fj128 for the PR. + # 0.4.3 - Use XML in CAPS since beginning at Boost 1.61 the parameter value is case sensitive (#29). diff --git a/pytest_cpp/boost.py b/pytest_cpp/boost.py index 649878d..e091227 100644 --- a/pytest_cpp/boost.py +++ b/pytest_cpp/boost.py @@ -69,6 +69,13 @@ def read_file(name): returncode=p.returncode)) return [failure] + if report is not None and ( + report.startswith('Boost.Test framework internal error: ') or + report.startswith('Test setup error: ')): + # boost.test doesn't do XML output on fatal-enough errors. + failure = BoostTestFailure('unknown location', 0, report) + return [failure] + results = self._parse_log(log=log) shutil.rmtree(temp_dir) if results: diff --git a/tests/SConstruct b/tests/SConstruct index 40ba0b3..714b03c 100644 --- a/tests/SConstruct +++ b/tests/SConstruct @@ -20,8 +20,8 @@ Export('env genv') genv.Program('gtest.cpp') -for filename in ('boost_success.cpp', 'boost_failure.cpp', 'boost_error.cpp'): +for filename in ('boost_success.cpp', 'boost_failure.cpp', 'boost_error.cpp', 'boost_fixture_setup_error.cpp'): env.Program(filename) SConscript('acceptance/googletest-samples/SConscript') -SConscript('acceptance/boosttest-samples/SConscript') \ No newline at end of file +SConscript('acceptance/boosttest-samples/SConscript') diff --git a/tests/boost_fixture_setup_error.cpp b/tests/boost_fixture_setup_error.cpp new file mode 100644 index 0000000..2a41523 --- /dev/null +++ b/tests/boost_fixture_setup_error.cpp @@ -0,0 +1,21 @@ +#include +#define BOOST_TEST_MODULE MyTest +#include + +struct InitTests { + InitTests() { + fprintf(stdout, "something on the stdout\n"); + fflush(stdout); + fprintf(stderr, "something on the stderr\n"); + fflush(stderr); + throw std::runtime_error("This is a global fixture init failure"); + } +}; +BOOST_GLOBAL_FIXTURE(InitTests); + + +BOOST_AUTO_TEST_CASE( test_dummy ) +{ + return; +} + diff --git a/tests/test_pytest_cpp.py b/tests/test_pytest_cpp.py index 4da7baf..e5a463f 100644 --- a/tests/test_pytest_cpp.py +++ b/tests/test_pytest_cpp.py @@ -42,6 +42,7 @@ def get_file_reference(self): ]), (BoostTestFacade(), 'boost_success', ['boost_success']), (BoostTestFacade(), 'boost_error', ['boost_error']), + (BoostTestFacade(), 'boost_fixture_setup_error', ['boost_fixture_setup_error']), ]) def test_list_tests(facade, name, expected, exes): obtained = facade.list_tests(exes.get(name)) @@ -134,6 +135,18 @@ def test_boost_error(exes): assert fail2.get_file_reference() == ("unknown location", 0) +def test_boost_fixture_setup_error(exes): + facade = BoostTestFacade() + failures = facade.run_test(exes.get('boost_fixture_setup_error'), '') + assert len(failures) == 1 + + fail1 = failures[0] + colors = ('red', 'bold') + assert fail1.get_lines() == [ + ('Test setup error: std::runtime_error: This is a global fixture init failure', colors)] + assert fail1.get_file_reference() == ("unknown location", 0) + + def test_google_run(testdir, exes): result = testdir.inline_run('-v', exes.get('gtest', 'test_gtest')) assert_outcomes(result, [ @@ -179,12 +192,13 @@ def raise_error(*args, **kwargs): def test_boost_run(testdir, exes): - all_names = ['boost_success', 'boost_error', 'boost_failure'] + all_names = ['boost_success', 'boost_error', 'boost_fixture_setup_error', 'boost_failure'] all_files = [exes.get(n, 'test_' + n) for n in all_names] result = testdir.inline_run('-v', *all_files) assert_outcomes(result, [ ('test_boost_success', 'passed'), ('test_boost_error', 'failed'), + ('test_boost_fixture_setup_error', 'failed'), ('test_boost_failure', 'failed'), ])