Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
7 changes: 7 additions & 0 deletions pytest_cpp/boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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')
SConscript('acceptance/boosttest-samples/SConscript')
21 changes: 21 additions & 0 deletions tests/boost_fixture_setup_error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdexcept>
#define BOOST_TEST_MODULE MyTest
#include <boost/test/included/unit_test.hpp>

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;
}

16 changes: 15 additions & 1 deletion tests/test_pytest_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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'), '<unused>')
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, [
Expand Down Expand Up @@ -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'),
])

Expand Down