Add hook to cancel running the tests

Open
#324 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
32/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
testing

Research direction

Start with include/boost/test/impl/unit_test_main.ipp around the linked line and trace how unit_test_main, unit_test_init(), --list_content, and --list_labels are handled. Compare the proposed overload and cancellation point with existing entry points and compatibility expectations. Done means a user-definable cancellation hook can stop the suite while preserving the documented command-line behavior.

Written by the indexing model from the issue text.

Description

discussion

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:

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()
  // ...
}
Dominant language
C++
Stars
213
Forks
149
Avg merge
18h 17m
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/test

All issues in boostorg/test

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.