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; }