Closed vid512 closed 1 year ago
You can use the matcher snitch::matchers::with_what_contains{"message"}
, which checks against the output of what()
. The test macro REQUIRE_THROWS_MATCHES(...)
doesn't require an exception object that derives from std::exception
(e.g., could be int
), so it can't call what()
directly; that needs to happen in the matcher.
Thanks, I've missed with_what_contains matcher. Sorry for not reading docs properly.
No worries!
I am trying to write something analogous to Catch2
REQUIRE_THROWS_WITH( func(), ContainsString("too big"))
.My first instinct was to use REQUIRE_THROWS_MATCHES like this:
But apprently, I need to provide matcher for std::exception object, not just for its what() message?
Is there any shorthand for this (IMO common) scenario? Or do I need to write my own set of matchers for std::exception message? Or am I missing something obvious?