[Issue #36] Added throw assertions
This commit is contained in:
parent
afad78c433
commit
b8374bca16
3 changed files with 41 additions and 4 deletions
|
@ -288,6 +288,34 @@ struct criterion_assert_args {
|
|||
cr_expect_arrays_eq_cmp_(__VA_ARGS__, CR_SENTINEL)
|
||||
# endif /* !__GNUC__ */
|
||||
|
||||
# ifdef __cplusplus
|
||||
# define cr_assert_throw(...) CR_EXPAND(cr_assert_throw_(__VA_ARGS__, CR_SENTINEL))
|
||||
# define cr_assert_throw_(Statement, Exception, ...) \
|
||||
try { \
|
||||
Statement; \
|
||||
} catch (Exception &ex) { \
|
||||
} catch (...) { CR_EXPAND(cr_assert_impl(FATAL, 0, __VA_ARGS__)); }
|
||||
|
||||
# define cr_assert_no_throw(...) CR_EXPAND(cr_assert_not_throw_(__VA_ARGS__, CR_SENTINEL))
|
||||
# define cr_assert_no_throw_(Statement, Exception, ...) \
|
||||
try { \
|
||||
Statement; \
|
||||
} catch (Exception &ex) { CR_EXPAND(cr_assert_impl(FATAL, 0, __VA_ARGS__)); }
|
||||
|
||||
# define cr_expect_throw(...) CR_EXPAND(cr_expect_throw_(__VA_ARGS__, CR_SENTINEL))
|
||||
# define cr_expect_throw_(Statement, Exception, ...) \
|
||||
try { \
|
||||
Statement; \
|
||||
} catch (Exception &ex) { \
|
||||
} catch (...) { CR_EXPAND(cr_assert_impl(NORMAL, 0, __VA_ARGS__)); }
|
||||
|
||||
# define cr_expect_no_throw(...) CR_EXPAND(cr_expect_not_throw_(__VA_ARGS__, CR_SENTINEL))
|
||||
# define cr_expect_no_throw_(Statement, Exception, ...) \
|
||||
try { \
|
||||
Statement; \
|
||||
} catch (Exception &ex) { CR_EXPAND(cr_assert_impl(NORMAL, 0, __VA_ARGS__)); }
|
||||
# endif
|
||||
|
||||
// The section below is here for backward compatibility purposes.
|
||||
// It shall be removed in the text major version of Criterion
|
||||
# ifndef CRITERION_NO_COMPAT
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include <criterion/criterion.h>
|
||||
#include <exception>
|
||||
#include <new>
|
||||
|
||||
Test(asserts, base) {
|
||||
cr_assert(true);
|
||||
|
@ -78,3 +80,8 @@ Test(asserts, array) {
|
|||
cr_assert_arrays_eq_cmp(s1, s2, 2, eq_dummy);
|
||||
#endif
|
||||
}
|
||||
|
||||
Test(asserts, exception) {
|
||||
cr_assert_throw(throw std::exception(), std::exception);
|
||||
cr_assert_throw(throw std::exception(), std::bad_alloc);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
[[0;34m----[0m] [0;1masserts.cc[0m:[0;31m9[0m: Assertion failed: assert is fatal, expect isn't
|
||||
[[0;34m----[0m] [0;1masserts.cc[0m:[0;31m10[0m: Assertion failed: This assert runs
|
||||
[[0;34m----[0m] [0;1masserts.cc[0m:[0;31m11[0m: Assertion failed: assert is fatal, expect isn't
|
||||
[[0;34m----[0m] [0;1masserts.cc[0m:[0;31m12[0m: Assertion failed: This assert runs
|
||||
[[0;31mFAIL[0m] asserts::base: (0.00s)
|
||||
[[0;34m----[0m] [0;1masserts.cc[0m:[0;31m18[0m: Assertion failed: The conditions for this test were not met.
|
||||
[[0;34m----[0m] [0;1masserts.cc[0m:[0;31m86[0m: Assertion failed: 0
|
||||
[[0;31mFAIL[0m] asserts::exception: (0.00s)
|
||||
[[0;34m----[0m] [0;1masserts.cc[0m:[0;31m20[0m: Assertion failed: The conditions for this test were not met.
|
||||
[[0;31mFAIL[0m] asserts::old_school: (0.00s)
|
||||
[[0;34m====[0m] [0;1mSynthesis: Tested: [0;34m6[0;1m | Passing: [0;32m4[0;1m | Failing: [0;31m2[0;1m | Crashing: [0;31m0[0;1m [0m
|
||||
[[0;34m====[0m] [0;1mSynthesis: Tested: [0;34m7[0;1m | Passing: [0;32m4[0;1m | Failing: [0;31m3[0;1m | Crashing: [0;31m0[0;1m [0m
|
||||
|
|
Loading…
Add table
Reference in a new issue