11#include < testcpplite/testcpplite.hpp>
22#include < sstream>
33#include < iostream>
4+ #include < exception>
5+ #include < string>
46
57namespace testcpplite {
68namespace {
@@ -28,6 +30,16 @@ void passesNegativeBooleanAssertion(TestResult &result) {
2830
2931void expectsFalseActualTrue (TestResult &result) { assertFalse (result, true ); }
3032
33+ class StandardException : public std ::exception {
34+ public:
35+ explicit StandardException (std::string s) : s{std::move (s)} {}
36+
37+ auto what () const noexcept -> const char * override { return s.c_str (); }
38+
39+ private:
40+ std::string s;
41+ };
42+
3143auto testStream (const std::vector<Test> &tests) -> std::stringstream {
3244 std::stringstream stream;
3345 test (tests, stream);
@@ -140,6 +152,11 @@ void failedUnsignedIntegerComparisonShowsFailedMessage(TestResult &result) {
140152 {expects2147483647Actual2147483648, " myTest" });
141153}
142154
155+ void catchesStandardExceptions (TestResult &result) {
156+ assertEqual (result, failMessage (" myTest" ) + " error\n " ,
157+ {[](TestResult &) { throw StandardException{" error" }; }, " myTest" });
158+ }
159+
143160int main () {
144161 return testcpplite::test (
145162 {{passedOnlyTestShowsPassedMessage, " passedOnlyTestShowsPassedMessage" },
@@ -166,7 +183,8 @@ int main() {
166183 {failedNegativeBooleanAssertionShowsFailedMessage,
167184 " failedNegativeBooleanAssertionShowsFailedMessage" },
168185 {failedUnsignedIntegerComparisonShowsFailedMessage,
169- " failedUnsignedIntegerComparisonShowsFailedMessage" }},
186+ " failedUnsignedIntegerComparisonShowsFailedMessage" },
187+ {catchesStandardExceptions, " catchesStandardExceptions" }},
170188 std::cout);
171189}
172190}
0 commit comments