boost-ext / ut

C++20 μ(micro)/Unit Testing Framework
https://boost-ext.github.io/ut
Boost Software License 1.0
1.26k stars 120 forks source link

TAP reporter - needs an event::on_tests_begin #591

Open talisein opened 1 year ago

talisein commented 1 year ago

The JUnit output is nice, but I'd like TAP as well. But I think I need a new event, on_tests_begin() that would have a size_t num_tests member that indicates how many tests are planned to have run (but they haven't run yet!)

TAP output is like:

1..2     # The plan is to execute 2 tests
ok 1     # The first test passed
not ok 2 # the second test failed
EOF

The idea of reporting how many tests are planned to execute is that if one test causes the whole executable to abort, anything parsing the output can understand that it is incomplete. e.g. the following can be caught as a failed test run:

1..2
ok 1
EOF

I've already implemented a similar on_suitesbegin() event, since there is a std::vector suites in the runner, but I don't understand the code well enough to make an on_tests_begin(). I suspect each test is simply run as it is encountered and there's no way to count them beforehand. Am I correct about that? Any ideas? In the worst case I can accumulate test results in the TAP reporter state and just output everything at once at the end, but it is less than ideal.