From 8cd44c637db82b42ab67fc21c675e0c67795082f Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Fri, 24 Jul 2015 16:15:43 -0700 Subject: [PATCH] Add except, unexcept in suite --- src/beast/beast/unit_test/suite.h | 93 +++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/beast/beast/unit_test/suite.h b/src/beast/beast/unit_test/suite.h index 1e9dab6aae..6a9e8e986e 100644 --- a/src/beast/beast/unit_test/suite.h +++ b/src/beast/beast/unit_test/suite.h @@ -176,6 +176,48 @@ public: return expect (shouldBeTrue, ""); } + /** Expect an exception from f() */ + /** @{ */ + template + bool + except (F&& f, String const& reason); + + template + bool + except (F&& f) + { + return except(f, ""); + } + /** @} */ + + /** Expect an exception of the given type from f() */ + /** @{ */ + template + bool + except (F&& f, String const& reason); + + template + bool + except (F&& f) + { + return except(f, ""); + } + /** @} */ + + /** Fail if f() throws */ + /** @{ */ + template + bool + unexcept (F&& f, String const& reason); + + template + bool + unexcept (F&& f) + { + return unexcept(f, ""); + } + /** @} */ + /** Return the argument associated with the runner. */ std::string const& arg() const @@ -355,6 +397,57 @@ suite::expect (Condition shouldBeTrue, return b; } +template +bool +suite::except (F&& f, String const& reason) +{ + try + { + f(); + fail(reason); + return false; + } + catch(...) + { + pass(); + } + return true; +} + +template +bool +suite::except (F&& f, String const& reason) +{ + try + { + f(); + fail(reason); + return false; + } + catch(E const&) + { + pass(); + } + return true; +} + +template +bool +suite::unexcept (F&& f, String const& reason) +{ + try + { + f(); + pass(); + return true; + } + catch(...) + { + fail(reason); + } + return false; +} + template inline bool