Add hook to cancel running the tests
- Dominant language
- C++
- Stars
- 213
- Forks
- 149
- Avg merge
- 18h 17m
- Merged PRs (30d)
- 2
Description
I am working with a boost test suite, which needs to run under some conditions.
There is currently no way of checking these conditions and exiting early, while keeping the boost test command line flags working.
* If I use a custom main and exit before calling boost test, then _obviously_ no flags will be checked by boost test.
* If I use a custom `unit_test_init()`, then flags like `--help` will work.
The flags `--list_content` and `--list_labels` are handled after `unit_test_init()`, so they won't work.
Currently, I either have to either sacrifice the very useful `--list_content` and `--list_labels` flags, or I have to exit in the first test.
I propose to add another user-definable hook, which allows the user to cancel the testsuite:
https://github.com/boostorg/test/blob/9d863d07e864ef663e3e8573b55905099b938d3e/include/boost/test/impl/unit_test_main.ipp#L250
This could be a simple predicate:
```cpp
typedef bool (*cancel_unit_test_func)();
// For backwards compatibility
int BOOST_TEST_DECL
unit_test_main( init_unit_test_func init_func, int argc, char* argv[] ) {
return unit_test_main(init_func, nullptr, argc, argv);
}
// New main with additional cancel_unit_test_func
int BOOST_TEST_DECL
unit_test_main( init_unit_test_func init_func, cancel_unit_test_func cancel_func, int argc, char* argv[] ) {
// ...
if(cancel_func && cancel_func()) {
return boost::exit_cancelled;
}
framework::run()
// ...
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.