diff --git a/src/pvxs/unittest.h b/src/pvxs/unittest.h index 51b64d833..6c8bd73f2 100644 --- a/src/pvxs/unittest.h +++ b/src/pvxs/unittest.h @@ -212,11 +212,15 @@ testCase testArrEq(const char *sLHS, const LHS& lhs, const char *sRHS, const RHS /** Assert that an exception is thrown. * * @tparam Exception The exception type which should be thrown - * @param fn A callable + * @param fn A callable which should throw the Exception type. + * @param chk Optional. If provided, a callable which takes an Exception + * reference and returns a true if it is as expected. * * @returns A testCase which passes if an Exception instance was caught, * and false otherwise (wrong type, or no exception). * + * @since UNRELEASED Added second (chk) argument. + * * @code * testThrows([]() { * testShow()<<"Now you see me"; @@ -224,16 +228,26 @@ testCase testArrEq(const char *sLHS, const LHS& lhs, const char *sRHS, const RHS * testShow()<<"Now you don't"; * })<<"some message"; * @endcode + * + * @code + * testThrows([]() { + * testShow()<<"Now you see me"; + * throw std::runtime_error("I happened"); + * testShow()<<"Now you don't"; + * }, [](std::runtime_error& e) -> bool { + * return strstr(e.what(), "happened"); + * })<<"some message"; + * @endcode */ -template -testCase testThrows(FN fn) +template +testCase testThrows(FN fn, CHK chk = nullptr) { testCase ret(false); try { fn(); ret<<"Unexpected success - "; }catch(Exception& e){ - ret.setPass(true)<<"Expected exception \""<