Skip to content

Commit aad8926

Browse files
authored
Merge pull request #31 from fj128/master
Deal with fixture init failures in boost.test
2 parents d1116a7 + bc3316a commit aad8926

5 files changed

Lines changed: 50 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 0.4.4
2+
3+
- Properly handle fixture failures in Boost.Test.
4+
Thanks @fj128 for the PR.
5+
16
# 0.4.3
27

38
- Use XML in CAPS since beginning at Boost 1.61 the parameter value is case sensitive (#29).

pytest_cpp/boost.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ def read_file(name):
6969
returncode=p.returncode))
7070
return [failure]
7171

72+
if report is not None and (
73+
report.startswith('Boost.Test framework internal error: ') or
74+
report.startswith('Test setup error: ')):
75+
# boost.test doesn't do XML output on fatal-enough errors.
76+
failure = BoostTestFailure('unknown location', 0, report)
77+
return [failure]
78+
7279
results = self._parse_log(log=log)
7380
shutil.rmtree(temp_dir)
7481
if results:

tests/SConstruct

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Export('env genv')
2020

2121
genv.Program('gtest.cpp')
2222

23-
for filename in ('boost_success.cpp', 'boost_failure.cpp', 'boost_error.cpp'):
23+
for filename in ('boost_success.cpp', 'boost_failure.cpp', 'boost_error.cpp', 'boost_fixture_setup_error.cpp'):
2424
env.Program(filename)
2525

2626
SConscript('acceptance/googletest-samples/SConscript')
27-
SConscript('acceptance/boosttest-samples/SConscript')
27+
SConscript('acceptance/boosttest-samples/SConscript')
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <stdexcept>
2+
#define BOOST_TEST_MODULE MyTest
3+
#include <boost/test/included/unit_test.hpp>
4+
5+
struct InitTests {
6+
InitTests() {
7+
fprintf(stdout, "something on the stdout\n");
8+
fflush(stdout);
9+
fprintf(stderr, "something on the stderr\n");
10+
fflush(stderr);
11+
throw std::runtime_error("This is a global fixture init failure");
12+
}
13+
};
14+
BOOST_GLOBAL_FIXTURE(InitTests);
15+
16+
17+
BOOST_AUTO_TEST_CASE( test_dummy )
18+
{
19+
return;
20+
}
21+

tests/test_pytest_cpp.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def get_file_reference(self):
4242
]),
4343
(BoostTestFacade(), 'boost_success', ['boost_success']),
4444
(BoostTestFacade(), 'boost_error', ['boost_error']),
45+
(BoostTestFacade(), 'boost_fixture_setup_error', ['boost_fixture_setup_error']),
4546
])
4647
def test_list_tests(facade, name, expected, exes):
4748
obtained = facade.list_tests(exes.get(name))
@@ -134,6 +135,18 @@ def test_boost_error(exes):
134135
assert fail2.get_file_reference() == ("unknown location", 0)
135136

136137

138+
def test_boost_fixture_setup_error(exes):
139+
facade = BoostTestFacade()
140+
failures = facade.run_test(exes.get('boost_fixture_setup_error'), '<unused>')
141+
assert len(failures) == 1
142+
143+
fail1 = failures[0]
144+
colors = ('red', 'bold')
145+
assert fail1.get_lines() == [
146+
('Test setup error: std::runtime_error: This is a global fixture init failure', colors)]
147+
assert fail1.get_file_reference() == ("unknown location", 0)
148+
149+
137150
def test_google_run(testdir, exes):
138151
result = testdir.inline_run('-v', exes.get('gtest', 'test_gtest'))
139152
assert_outcomes(result, [
@@ -179,12 +192,13 @@ def raise_error(*args, **kwargs):
179192

180193

181194
def test_boost_run(testdir, exes):
182-
all_names = ['boost_success', 'boost_error', 'boost_failure']
195+
all_names = ['boost_success', 'boost_error', 'boost_fixture_setup_error', 'boost_failure']
183196
all_files = [exes.get(n, 'test_' + n) for n in all_names]
184197
result = testdir.inline_run('-v', *all_files)
185198
assert_outcomes(result, [
186199
('test_boost_success', 'passed'),
187200
('test_boost_error', 'failed'),
201+
('test_boost_fixture_setup_error', 'failed'),
188202
('test_boost_failure', 'failed'),
189203
])
190204

0 commit comments

Comments
 (0)