Skip to content
Snippets Groups Projects

Add checkThrow to Dune::TestSuite

This MR adds the methods checkThrow,requireThrow and the corresponding checkNoThrow,requireNoThrowto the Dune::TestSuite.

These method add the capability to check, if something throws an exception.

This is done by wrapping the function under consideration inside a nullary functor, e.g. a lambda.

This allows something like this:

Dune::TestSuite t;
Dune::FieldVector<double, 3> a = {1, 2, 3};
Dune::FieldVector<double, 2> const b = {1, 2};

auto plusEqual = [&]{ a+=b;};
t.checkThrow<Dune::RangeError>(plusEqual,"Add vectors of different sizes didn't throw."); // check specific exception is thrown
t.requireThrow<Dune::RangeError>(plusEqual,"Add vectors of different sizes didn't throw."); // require specific exception is thrown

t.checkThrow(plusEqual,"Add vectors of different sizes didn't throw."); // check any exception is thrown
t.requireThrow(plusEqual,"Add vectors of different sizes didn't throw."); // require any exception is thrown

Dune::FieldVector<double, 3> c = {1, 2, 3};

t.checkNoThrow([&]{ a+=c;},"Add vectors of the same size throws."); // check no exception is thrown
t.requireNoThrow([&]{ a+=c;},"Add vectors of the same size throws."); // require no exception is thrown
Edited by Alexander Müller

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
Please register or sign in to reply
Loading