Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception objects inspection while handling. #413

Open
wiluite opened this issue Dec 19, 2020 · 0 comments
Open

Exception objects inspection while handling. #413

wiluite opened this issue Dec 19, 2020 · 0 comments

Comments

@wiluite
Copy link

wiluite commented Dec 19, 2020

Expected Behavior

Something similar to
BOOST_REQUIRE_EXCEPTION(expression, exception_type, predicate);

In Boost.Test (at least) there is a useful opportunity to inspect exception object itself.
BOOST_REQUIRE_EXCEPTION

Actual Behavior

It seems now ut can not simulate this behaviour by overriding runner/reporter/... In the case of

expect(throws<std::runtime_error>([] { throw std::runtime_error{""}; }))

by the time runner::on(ut::events::assertion<TExpr>) fires, a decision on the status of test validation has already been made, without the ability to somehow intervene either before or after for completion.

As a workaround I just embed a 'predicate function' to ut::throws and ut::detail::throws_ as overriding variants.

template<class T>
void func_1(T const & e)
{
  boost::ut::expect(e.code() == ex_code_1);
}
...
"test1"_test = [] {

      /* some 'when' precondition */
      expect(throws<some_exception>(
          [] { raising_func(); },
          func_1) ); // fails at func_1 body line if raising_func throws with ex_code_2
      /* some other 'when' precondition */
      expect(throws<some_exception>(
          [] { raising_func(); },
          func_2) ); // passes if raising_func throws with ex_code_2
      expect((throws<some_exception>([] { throw some_exception(); })) >> fatal); // passes
      expect((throws<some_exception>([] { raising_func(); })) >> fatal); // passes if raising any "some_exception" (or fail at this particular line)
      expect((throws([] { throw 1; })) >> fatal); // as always!
}

And my question is: Will similar(somewhat) functionality be introduced to ut sometime?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant