From 37def859e5f927a43a65b58a72801122193458ea Mon Sep 17 00:00:00 2001 From: q66 Date: Wed, 26 Apr 2017 23:12:59 +0200 Subject: [PATCH] catch all exceptions in unit tester --- ostd/unit_test.hh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ostd/unit_test.hh b/ostd/unit_test.hh index d12ac83..68a2ca2 100644 --- a/ostd/unit_test.hh +++ b/ostd/unit_test.hh @@ -81,7 +81,7 @@ static bool test_case_##module##_##__LINE__ = \ * be able to see how many tests of the module succeeded and how many * failed. * - * @see ostd::test::fail_if_not() + * @see ostd::test::fail(), ostd::test::fail_if_not() */ void fail_if(bool b) { if (b) { @@ -99,6 +99,16 @@ void fail_if_not(bool b) { } } +/** @brief Makes the test fail. + * + * The current test will exit. + * + * @see ostd::test::fail_if() + */ +void fail() { + throw detail::test_error{}; +} + /** @brief Runs all enabled test cases. * * @returns An std::pair containing the number of tests that succeeded @@ -112,6 +122,10 @@ std::pair run() { } catch (detail::test_error) { ++fail; continue; + } catch (...) { + std::printf("warning: uncaught exception"); + ++fail; + continue; } ++succ; }