From b8d44f433a936920e33e3834b8bf38bd939c93a2 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Fri, 24 Apr 2015 00:32:20 +0200 Subject: [PATCH 1/9] Added macro alias for assert and enhanced compatibility with assert.h --- include/criterion/assert.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/criterion/assert.h b/include/criterion/assert.h index 4a5b2b4b..4a1f7b1d 100644 --- a/include/criterion/assert.h +++ b/include/criterion/assert.h @@ -72,7 +72,13 @@ struct criterion_assert_args { .msg = (Message) \ ) +# ifdef assert +# undef assert +# pragma message("The assert macro has been replaced by criterion.") +# endif # define assert(...) assert_(__VA_ARGS__, .sentinel_ = 0) +# define criterion_assert(...) assert_(__VA_ARGS__, .sentinel_ = 0) + # define expect(...) expect_(__VA_ARGS__, .sentinel_ = 0) # define assert_(Condition, ...) assert_impl(FATAL, Condition, __VA_ARGS__) @@ -267,4 +273,8 @@ struct criterion_assert_args { expect_arrays_eq_cmp_(__VA_ARGS__, .sentinel_ = 0) # endif /* !__GNUC__ */ +// this is needed to make the POSIX assert.h redefine assert if +// subsequently included +# define _ASSERT_H 1 + #endif /* !CRITERION_ASSERT_H_ */ From 58581f5b180e878f56a9a0c915556fcb6d75a961 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 25 Apr 2015 16:45:31 +0200 Subject: [PATCH 2/9] [Issue #20] Added cr_ prefix to all assertion macros --- include/criterion/assert.h | 295 ++++++++++++++++++++++--------------- 1 file changed, 179 insertions(+), 116 deletions(-) diff --git a/include/criterion/assert.h b/include/criterion/assert.h index 4a1f7b1d..62378dcd 100644 --- a/include/criterion/assert.h +++ b/include/criterion/assert.h @@ -44,7 +44,7 @@ struct criterion_assert_args { int sentinel_; }; -# define assert_impl(Kind, Condition, ...) \ +# define cr_assert_impl(Kind, Condition, ...) \ do { \ struct criterion_assert_args args = { \ __VA_ARGS__ \ @@ -66,159 +66,154 @@ struct criterion_assert_args { // Common asserts -# define abort_test(Message) \ - assert(0, \ +# define cr_abort_test(Message) \ + cr_assert(0, \ .default_msg = "The conditions for this test were not met.", \ .msg = (Message) \ ) -# ifdef assert -# undef assert -# pragma message("The assert macro has been replaced by criterion.") -# endif -# define assert(...) assert_(__VA_ARGS__, .sentinel_ = 0) -# define criterion_assert(...) assert_(__VA_ARGS__, .sentinel_ = 0) +# define cr_assert(...) cr_assert_(__VA_ARGS__, .sentinel_ = 0) -# define expect(...) expect_(__VA_ARGS__, .sentinel_ = 0) +# define cr_expect(...) cr_expect_(__VA_ARGS__, .sentinel_ = 0) -# define assert_(Condition, ...) assert_impl(FATAL, Condition, __VA_ARGS__) -# define expect_(Condition, ...) assert_impl(NORMAL, Condition, __VA_ARGS__) +# define cr_assert_(Condition, ...) cr_assert_impl(FATAL, Condition, __VA_ARGS__) +# define cr_expect_(Condition, ...) cr_assert_impl(NORMAL, Condition, __VA_ARGS__) -# define assert_not(...) assert_not_(__VA_ARGS__, .sentinel_ = 0) -# define expect_not(...) expect_not_(__VA_ARGS__, .sentinel_ = 0) +# define cr_assert_not(...) cr_assert_not_(__VA_ARGS__, .sentinel_ = 0) +# define cr_expect_not(...) cr_expect_not_(__VA_ARGS__, .sentinel_ = 0) -# define assert_not_(Condition, ...) \ - assert_impl(FATAL, !(Condition), __VA_ARGS__) -# define expect_not_(Condition, ...) \ - expect_impl(NORMAL, !(Condition), __VA_ARGS__) +# define cr_assert_not_(Condition, ...) \ + cr_assert_impl(FATAL, !(Condition), __VA_ARGS__) +# define cr_expect_not_(Condition, ...) \ + cr_expect_impl(NORMAL, !(Condition), __VA_ARGS__) // Native asserts -# define assert_op_(Op, Actual, Expected, ...) \ - assert_impl(FATAL, (Actual) Op (Expected), __VA_ARGS__) -# define expect_op_(Op, Actual, Expected, ...) \ - assert_impl(NORMAL, (Actual) Op (Expected), __VA_ARGS__) +# define cr_assert_op_(Op, Actual, Expected, ...) \ + cr_assert_impl(FATAL, (Actual) Op (Expected), __VA_ARGS__) +# define cr_expect_op_(Op, Actual, Expected, ...) \ + cr_assert_impl(NORMAL, (Actual) Op (Expected), __VA_ARGS__) -# define assert_eq(...) assert_op_(==, __VA_ARGS__, .sentinel_ = 0) -# define expect_eq(...) expect_op_(==, __VA_ARGS__, .sentinel_ = 0) +# define cr_assert_eq(...) cr_assert_op_(==, __VA_ARGS__, .sentinel_ = 0) +# define cr_expect_eq(...) cr_expect_op_(==, __VA_ARGS__, .sentinel_ = 0) -# define assert_neq(...) assert_op_(!=, __VA_ARGS__, .sentinel_ = 0) -# define expect_neq(...) expect_op_(!=, __VA_ARGS__, .sentinel_ = 0) +# define cr_assert_neq(...) cr_assert_op_(!=, __VA_ARGS__, .sentinel_ = 0) +# define cr_expect_neq(...) cr_expect_op_(!=, __VA_ARGS__, .sentinel_ = 0) -# define assert_lt(...) assert_op_(<, __VA_ARGS__, .sentinel_ = 0) -# define expect_lt(...) expect_op_(<, __VA_ARGS__, .sentinel_ = 0) +# define cr_assert_lt(...) cr_assert_op_(<, __VA_ARGS__, .sentinel_ = 0) +# define cr_expect_lt(...) cr_expect_op_(<, __VA_ARGS__, .sentinel_ = 0) -# define assert_gt(...) assert_op_(>, __VA_ARGS__, .sentinel_ = 0) -# define expect_gt(...) expect_op_(>, __VA_ARGS__, .sentinel_ = 0) +# define cr_assert_gt(...) cr_assert_op_(>, __VA_ARGS__, .sentinel_ = 0) +# define cr_expect_gt(...) cr_expect_op_(>, __VA_ARGS__, .sentinel_ = 0) -# define assert_leq(...) assert_op_(<=, __VA_ARGS__, .sentinel_ = 0) -# define expect_leq(...) expect_op_(<=, __VA_ARGS__, .sentinel_ = 0) +# define cr_assert_leq(...) cr_assert_op_(<=, __VA_ARGS__, .sentinel_ = 0) +# define cr_expect_leq(...) cr_expect_op_(<=, __VA_ARGS__, .sentinel_ = 0) -# define assert_geq(...) assert_op_(>=, __VA_ARGS__, .sentinel_ = 0) -# define expect_geq(...) expect_op_(>=, __VA_ARGS__, .sentinel_ = 0) +# define cr_assert_geq(...) cr_assert_op_(>=, __VA_ARGS__, .sentinel_ = 0) +# define cr_expect_geq(...) cr_expect_op_(>=, __VA_ARGS__, .sentinel_ = 0) -# define assert_null_(Value, ...) \ - assert_impl(FATAL, (Value) == NULL, __VA_ARGS__) -# define expect_null_(Value, ...) \ - assert_impl(NORMAL, (Value) == NULL, __VA_ARGS__) +# define cr_assert_null_(Value, ...) \ + cr_assert_impl(FATAL, (Value) == NULL, __VA_ARGS__) +# define cr_expect_null_(Value, ...) \ + cr_assert_impl(NORMAL, (Value) == NULL, __VA_ARGS__) -# define assert_null(...) assert_null_(__VA_ARGS__, .sentinel_ = 0) -# define expect_null(...) expect_null_(__VA_ARGS__, .sentinel_ = 0) +# define cr_assert_null(...) cr_assert_null_(__VA_ARGS__, .sentinel_ = 0) +# define cr_expect_null(...) cr_expect_null_(__VA_ARGS__, .sentinel_ = 0) -# define assert_not_null_(Value, ...) \ - assert_impl(FATAL, (Value) != NULL, __VA_ARGS__) -# define expect_not_null_(Value, ...) \ - assert_impl(NORMAL, (Value) != NULL, __VA_ARGS__) +# define cr_assert_not_null_(Value, ...) \ + cr_assert_impl(FATAL, (Value) != NULL, __VA_ARGS__) +# define cr_expect_not_null_(Value, ...) \ + cr_assert_impl(NORMAL, (Value) != NULL, __VA_ARGS__) -# define assert_not_null(...) assert_not_null_(__VA_ARGS__, .sentinel_ = 0) -# define expect_not_null(...) expect_not_null_(__VA_ARGS__, .sentinel_ = 0) +# define cr_assert_not_null(...) cr_assert_not_null_(__VA_ARGS__, .sentinel_ = 0) +# define cr_expect_not_null(...) cr_expect_not_null_(__VA_ARGS__, .sentinel_ = 0) // Floating-point asserts -# define assert_float_eq(...) \ - assert_float_eq_(__VA_ARGS__, .sentinel_ = 0) -# define expect_float_eq(...) \ - expect_float_eq_(__VA_ARGS__, .sentinel_ = 0) +# define cr_assert_float_eq(...) \ + cr_assert_float_eq_(__VA_ARGS__, .sentinel_ = 0) +# define cr_expect_float_eq(...) \ + cr_expect_float_eq_(__VA_ARGS__, .sentinel_ = 0) -# define assert_float_eq_(Actual, Expected, Epsilon, ...) \ - assert_impl(FATAL, (Expected) - (Actual) <= (Epsilon) \ +# define cr_assert_float_eq_(Actual, Expected, Epsilon, ...) \ + cr_assert_impl(FATAL, (Expected) - (Actual) <= (Epsilon) \ && (Actual) - (Expected) <= (Epsilon), \ __VA_ARGS__) -# define expect_float_eq_(Actual, Expected, Epsilon, ...) \ - assert_impl(NORMAL, (Expected) - (Actual) <= (Epsilon) \ +# define cr_expect_float_eq_(Actual, Expected, Epsilon, ...) \ + cr_assert_impl(NORMAL, (Expected) - (Actual) <= (Epsilon) \ && (Actual) - (Expected) <= (Epsilon), \ __VA_ARGS__) -# define assert_float_neq(...) \ - assert_float_neq_(__VA_ARGS__, .sentinel_ = 0) -# define expect_float_neq(...) \ - expect_float_neq_(__VA_ARGS__, .sentinel_ = 0) +# define cr_assert_float_neq(...) \ + cr_assert_float_neq_(__VA_ARGS__, .sentinel_ = 0) +# define cr_expect_float_neq(...) \ + cr_expect_float_neq_(__VA_ARGS__, .sentinel_ = 0) -# define assert_float_neq_(Actual, Expected, Epsilon, ...) \ - assert_impl(FATAL, (Expected) - (Actual) > (Epsilon) \ +# define cr_assert_float_neq_(Actual, Expected, Epsilon, ...) \ + cr_assert_impl(FATAL, (Expected) - (Actual) > (Epsilon) \ || (Actual) - (Expected) > (Epsilon), \ __VA_ARGS__) -# define expect_float_neq_(Actual, Expected, Epsilon, ...) \ - assert_impl(NORMAL, (Expected) - (Actual) > (Epsilon) \ +# define cr_expect_float_neq_(Actual, Expected, Epsilon, ...) \ + cr_assert_impl(NORMAL, (Expected) - (Actual) > (Epsilon) \ || (Actual) - (Expected) > (Epsilon), \ __VA_ARGS__) // String asserts -# define assert_strings_(Op, Actual, Expected, ...) \ - assert_impl(FATAL, strcmp((Actual), (Expected)) Op 0, __VA_ARGS__) -# define expect_strings_(Op, Actual, Expected, ...) \ - assert_impl(NORMAL, strcmp((Actual), (Expected)) Op 0, __VA_ARGS__) +# define cr_assert_strings_(Op, Actual, Expected, ...) \ + cr_assert_impl(FATAL, strcmp((Actual), (Expected)) Op 0, __VA_ARGS__) +# define cr_expect_strings_(Op, Actual, Expected, ...) \ + cr_assert_impl(NORMAL, strcmp((Actual), (Expected)) Op 0, __VA_ARGS__) -# define assert_strings_eq(...) \ - assert_strings_(==, __VA_ARGS__, .sentinel_ = 0) -# define expect_strings_eq(...) \ - expect_strings_(==, __VA_ARGS__, .sentinel_ = 0) +# define cr_assert_strings_eq(...) \ + cr_assert_strings_(==, __VA_ARGS__, .sentinel_ = 0) +# define cr_expect_strings_eq(...) \ + cr_expect_strings_(==, __VA_ARGS__, .sentinel_ = 0) -# define assert_strings_neq(...) \ - assert_strings_(!=, __VA_ARGS__, .sentinel_ = 0) -# define expect_strings_neq(...) \ - expect_strings_(!=, __VA_ARGS__, .sentinel_ = 0) +# define cr_assert_strings_neq(...) \ + cr_assert_strings_(!=, __VA_ARGS__, .sentinel_ = 0) +# define cr_expect_strings_neq(...) \ + cr_expect_strings_(!=, __VA_ARGS__, .sentinel_ = 0) -# define assert_strings_gt(...) assert_strings_(>, __VA_ARGS__, .sentinel_ = 0) -# define expect_strings_gt(...) expect_strings_(>, __VA_ARGS__, .sentinel_ = 0) +# define cr_assert_strings_gt(...) cr_assert_strings_(>, __VA_ARGS__, .sentinel_ = 0) +# define cr_expect_strings_gt(...) cr_expect_strings_(>, __VA_ARGS__, .sentinel_ = 0) -# define assert_strings_lt(...) assert_strings_(<, __VA_ARGS__, .sentinel_ = 0) -# define expect_strings_lt(...) expect_strings_(<, __VA_ARGS__, .sentinel_ = 0) +# define cr_assert_strings_lt(...) cr_assert_strings_(<, __VA_ARGS__, .sentinel_ = 0) +# define cr_expect_strings_lt(...) cr_expect_strings_(<, __VA_ARGS__, .sentinel_ = 0) -# define assert_strings_leq(...) assert_strings_(<=, __VA_ARGS__, .sentinel_ = 0) -# define expect_strings_leq(...) expect_strings_(<=, __VA_ARGS__, .sentinel_ = 0) +# define cr_assert_strings_leq(...) cr_assert_strings_(<=, __VA_ARGS__, .sentinel_ = 0) +# define cr_expect_strings_leq(...) cr_expect_strings_(<=, __VA_ARGS__, .sentinel_ = 0) -# define assert_strings_geq(...) assert_strings_(>=, __VA_ARGS__, .sentinel_ = 0) -# define expect_strings_geq(...) expect_strings_(>=, __VA_ARGS__, .sentinel_ = 0) +# define cr_assert_strings_geq(...) cr_assert_strings_(>=, __VA_ARGS__, .sentinel_ = 0) +# define cr_expect_strings_geq(...) cr_expect_strings_(>=, __VA_ARGS__, .sentinel_ = 0) // Array asserts -# define assert_arrays_eq(...) \ - assert_arrays_eq_(__VA_ARGS__, .sentinel_ = 0) -# define expect_arrays_eq(...) \ - expect_arrays_eq_(__VA_ARGS__, .sentinel_ = 0) +# define cr_assert_arrays_eq(...) \ + cr_assert_arrays_eq_(__VA_ARGS__, .sentinel_ = 0) +# define cr_expect_arrays_eq(...) \ + cr_expect_arrays_eq_(__VA_ARGS__, .sentinel_ = 0) -# define assert_arrays_neq(...) \ - assert_arrays_neq_(__VA_ARGS__, .sentinel_ = 0) -# define expect_arrays_neq(...) \ - expect_arrays_neq_(__VA_ARGS__, .sentinel_ = 0) +# define cr_assert_arrays_neq(...) \ + cr_assert_arrays_neq_(__VA_ARGS__, .sentinel_ = 0) +# define cr_expect_arrays_neq(...) \ + cr_expect_arrays_neq_(__VA_ARGS__, .sentinel_ = 0) -# define assert_arrays_eq_(A, B, Size, ...) \ - assert_impl(FATAL, !memcmp((A), (B), (Size)), \ +# define cr_assert_arrays_eq_(A, B, Size, ...) \ + cr_assert_impl(FATAL, !memcmp((A), (B), (Size)), \ .default_msg = "Arrays are not equal.", \ __VA_ARGS__) -# define expect_arrays_eq_(A, B, Size, ...) \ - assert_impl(NORMAL, !memcmp((A), (B), (Size)), \ +# define cr_expect_arrays_eq_(A, B, Size, ...) \ + cr_assert_impl(NORMAL, !memcmp((A), (B), (Size)), \ .default_msg = "Arrays are not equal.", \ __VA_ARGS__) -# define assert_arrays_neq_(A, B, Size, ...) \ - assert_impl(FATAL, memcmp((A), (B), (Size)), \ +# define cr_assert_arrays_neq_(A, B, Size, ...) \ + cr_assert_impl(FATAL, memcmp((A), (B), (Size)), \ .default_msg = "Arrays are equal", \ __VA_ARGS__) -# define expect_arrays_neq_(A, B, Size, ...) \ - assert_impl(NORMAL, memcmp((A), (B), (Size)), \ +# define cr_expect_arrays_neq_(A, B, Size, ...) \ + cr_assert_impl(NORMAL, memcmp((A), (B), (Size)), \ .default_msg = "Arrays are equal", \ __VA_ARGS__) @@ -227,54 +222,122 @@ struct criterion_assert_args { __typeof__(&(A)[0]) first = (A); \ __typeof__(&(B)[0]) second = (B); \ int equals = 1; \ - for (size_t i = 0, size = (Size); equals && i < size; ++i) \ + size_t i, size; \ + for (i = 0, size = (Size); equals && i < size; ++i) \ equals = equals && !Cmp(first + i, second + i) -# define assert_arrays_eq_cmp_(A, B, Size, Cmp, ...) \ +# define cr_assert_arrays_eq_cmp_(A, B, Size, Cmp, ...) \ do { \ CRIT_ARR_COMPARE_(A, B, Size, Cmp, equals); \ - assert_impl(FATAL, equals, \ + cr_assert_impl(FATAL, equals, \ .default_msg = "Arrays are not equal", \ __VA_ARGS__); \ } while (0) -# define expect_arrays_eq_cmp_(A, B, Size, Cmp, ...) \ +# define cr_expect_arrays_eq_cmp_(A, B, Size, Cmp, ...) \ do { \ CRIT_ARR_COMPARE_(A, B, Size, Cmp, equals); \ - assert_impl(NORMAL, equals, \ + cr_assert_impl(NORMAL, equals, \ .default_msg = "Arrays are not equal", \ __VA_ARGS__); \ } while (0) -# define assert_arrays_eq_cmp(...) \ - assert_arrays_eq_cmp_(__VA_ARGS__, .sentinel_ = 0) -# define expect_arrays_eq_cmp(...) \ - expect_arrays_eq_cmp_(__VA_ARGS__, .sentinel_ = 0) +# define cr_assert_arrays_eq_cmp(...) \ + cr_assert_arrays_eq_cmp_(__VA_ARGS__, .sentinel_ = 0) +# define cr_expect_arrays_eq_cmp(...) \ + cr_expect_arrays_eq_cmp_(__VA_ARGS__, .sentinel_ = 0) -# define assert_arrays_neq_cmp_(A, B, Size, Cmp, ...) \ +# define cr_assert_arrays_neq_cmp_(A, B, Size, Cmp, ...) \ do { \ CRIT_ARR_COMPARE_(A, B, Size, Cmp, equals); \ - assert_impl(FATAL, !equals, \ + cr_assert_impl(FATAL, !equals, \ .default_msg = "Arrays not equal", \ __VA_ARGS__); \ } while (0) -# define expect_arrays_neq_cmp_(A, B, Size, Cmp, ...) \ +# define cr_expect_arrays_neq_cmp_(A, B, Size, Cmp, ...) \ do { \ CRIT_ARR_COMPARE_(A, B, Size, Cmp, equals); \ - assert_impl(NORMAL, equals, \ + cr_assert_impl(NORMAL, equals, \ .default_msg = "Arrays not equal", \ __VA_ARGS__); \ } while (0) -# define assert_arrays_neq_cmp(...) \ - assert_arrays_eq_cmp_(__VA_ARGS__, .sentinel_ = 0) -# define expect_arrays_neq_cmp(...) \ - expect_arrays_eq_cmp_(__VA_ARGS__, .sentinel_ = 0) +# define cr_assert_arrays_neq_cmp(...) \ + cr_assert_arrays_eq_cmp_(__VA_ARGS__, .sentinel_ = 0) +# define cr_expect_arrays_neq_cmp(...) \ + cr_expect_arrays_eq_cmp_(__VA_ARGS__, .sentinel_ = 0) # endif /* !__GNUC__ */ +// The section below is here for backward compatibility purposes. +// It shall be removed in the text major version of Criterion +# ifndef CRITERION_NO_COMPAT + +/* +# define CRITERION_ASSERT_DEPRECATED_(Name) \ + _Pragma("message \"" \ + "The " #Name " macro is deprecated, " \ + "please use cr_" #Name " instead." \ + "\"" \ + ) + */ + +# define CRITERION_ASSERT_DEPRECATED_(Name) \ + _Pragma("message \"This macro is deprecated, please use its `cr_`-prefixed alternative instead.\"") + +# ifndef assert +# define assert(...) CRITERION_ASSERT_DEPRECATED_(assert) cr_assert(__VA_ARGS__) + // this is needed to make the POSIX assert.h redefine assert if // subsequently included -# define _ASSERT_H 1 +# define _ASSERT_H 1 +# endif /* !assert */ + +# define abort_test(Message) CRITERION_ASSERT_DEPRECATED_(abort_test) cr_abort_test(Message) +# define expect(...) CRITERION_ASSERT_DEPRECATED_(expect) cr_expect(__VA_ARGS__) +# define assert_not(...) CRITERION_ASSERT_DEPRECATED_(assert_not) cr_assert_not(__VA_ARGS__) +# define expect_not(...) CRITERION_ASSERT_DEPRECATED_(expect_not) cr_expect_not(__VA_ARGS__) +# define assert_eq(...) CRITERION_ASSERT_DEPRECATED_(assert_eq) cr_assert_eq(__VA_ARGS__) +# define expect_eq(...) CRITERION_ASSERT_DEPRECATED_(expect_eq) cr_expect_eq(__VA_ARGS__) +# define assert_neq(...) CRITERION_ASSERT_DEPRECATED_(assert_neq) cr_assert_neq(__VA_ARGS__) +# define expect_neq(...) CRITERION_ASSERT_DEPRECATED_(expect_neq) cr_expect_neq(__VA_ARGS__) +# define assert_lt(...) CRITERION_ASSERT_DEPRECATED_(assert_lt) cr_assert_lt(__VA_ARGS__) +# define expect_lt(...) CRITERION_ASSERT_DEPRECATED_(expect_lt) cr_expect_lt(__VA_ARGS__) +# define assert_gt(...) CRITERION_ASSERT_DEPRECATED_(assert_gt) cr_assert_gt(__VA_ARGS__) +# define expect_gt(...) CRITERION_ASSERT_DEPRECATED_(expect_gt) cr_expect_gt(__VA_ARGS__) +# define assert_leq(...) CRITERION_ASSERT_DEPRECATED_(assert_leq) cr_assert_leq(__VA_ARGS__) +# define expect_leq(...) CRITERION_ASSERT_DEPRECATED_(expect_leq) cr_expect_leq(__VA_ARGS__) +# define assert_geq(...) CRITERION_ASSERT_DEPRECATED_(assert_geq) cr_assert_geq(__VA_ARGS__) +# define expect_geq(...) CRITERION_ASSERT_DEPRECATED_(expect_geq) cr_expect_geq(__VA_ARGS__) +# define assert_null(...) CRITERION_ASSERT_DEPRECATED_(assert_null) cr_assert_null(__VA_ARGS__) +# define expect_null(...) CRITERION_ASSERT_DEPRECATED_(expect_null) cr_expect_null(__VA_ARGS__) +# define assert_not_null(...) CRITERION_ASSERT_DEPRECATED_(assert_not_null) cr_assert_not_null(__VA_ARGS__) +# define expect_not_null(...) CRITERION_ASSERT_DEPRECATED_(expect_not_null) cr_expect_not_null(__VA_ARGS__) +# define assert_float_eq(...) CRITERION_ASSERT_DEPRECATED_(assert_float_eq) cr_assert_float_eq(__VA_ARGS__) +# define expect_float_eq(...) CRITERION_ASSERT_DEPRECATED_(expect_float_eq) cr_expect_float_eq(__VA_ARGS__) +# define assert_float_neq(...) CRITERION_ASSERT_DEPRECATED_(assert_float_neq) cr_assert_float_neq(__VA_ARGS__) +# define expect_float_neq(...) CRITERION_ASSERT_DEPRECATED_(expect_float_neq) cr_expect_float_neq(__VA_ARGS__) +# define assert_strings_eq(...) CRITERION_ASSERT_DEPRECATED_(assert_strings_eq) cr_assert_strings_eq(__VA_ARGS__) +# define expect_strings_eq(...) CRITERION_ASSERT_DEPRECATED_(expect_strings_eq) cr_expect_strings_eq(__VA_ARGS__) +# define assert_strings_neq(...) CRITERION_ASSERT_DEPRECATED_(assert_strings_neq) cr_assert_strings_neq(__VA_ARGS__) +# define expect_strings_neq(...) CRITERION_ASSERT_DEPRECATED_(expect_strings_neq) cr_expect_strings_neq(__VA_ARGS__) +# define assert_strings_gt(...) CRITERION_ASSERT_DEPRECATED_(assert_strings_gt) cr_assert_strings_gt(__VA_ARGS__) +# define expect_strings_gt(...) CRITERION_ASSERT_DEPRECATED_(expect_strings_gt) cr_expect_strings_gt(__VA_ARGS__) +# define assert_strings_lt(...) CRITERION_ASSERT_DEPRECATED_(assert_strings_lt) cr_assert_strings_lt(__VA_ARGS__) +# define expect_strings_lt(...) CRITERION_ASSERT_DEPRECATED_(expect_strings_lt) cr_expect_strings_lt(__VA_ARGS__) +# define assert_strings_leq(...) CRITERION_ASSERT_DEPRECATED_(assert_strings_leq) cr_assert_strings_leq(__VA_ARGS__) +# define expect_strings_leq(...) CRITERION_ASSERT_DEPRECATED_(expect_strings_leq) cr_expect_strings_leq(__VA_ARGS__) +# define assert_strings_geq(...) CRITERION_ASSERT_DEPRECATED_(assert_strings_geq) cr_assert_strings_geq(__VA_ARGS__) +# define expect_strings_geq(...) CRITERION_ASSERT_DEPRECATED_(expect_strings_geq) cr_expect_strings_geq(__VA_ARGS__) +# define assert_arrays_eq(...) CRITERION_ASSERT_DEPRECATED_(assert_arrays_eq) cr_assert_arrays_eq(__VA_ARGS__) +# define expect_arrays_eq(...) CRITERION_ASSERT_DEPRECATED_(expect_arrays_eq) cr_expect_arrays_eq(__VA_ARGS__) +# define assert_arrays_neq(...) CRITERION_ASSERT_DEPRECATED_(assert_arrays_neq) cr_assert_arrays_neq(__VA_ARGS__) +# define expect_arrays_neq(...) CRITERION_ASSERT_DEPRECATED_(expect_arrays_neq) cr_expect_arrays_neq(__VA_ARGS__) +# define assert_arrays_eq_cmp(...) CRITERION_ASSERT_DEPRECATED_(assert_arrays_eq_cmp) cr_assert_arrays_eq_cmp(__VA_ARGS__) +# define expect_arrays_eq_cmp(...) CRITERION_ASSERT_DEPRECATED_(expect_arrays_eq_cmp) cr_expect_arrays_eq_cmp(__VA_ARGS__) +# define assert_arrays_neq_cmp(...) CRITERION_ASSERT_DEPRECATED_(assert_arrays_neq_cmp) cr_assert_arrays_neq_cmp(__VA_ARGS__) +# define expect_arrays_neq_cmp(...) CRITERION_ASSERT_DEPRECATED_(expect_arrays_neq_cmp) cr_expect_arrays_neq_cmp(__VA_ARGS__) + +# endif #endif /* !CRITERION_ASSERT_H_ */ From 2d460062013c6e50e60b00783b2bfe89a68f0627 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 25 Apr 2015 16:48:34 +0200 Subject: [PATCH 3/9] Changed all tests to use cr_-prefixed macros --- samples/asserts.c | 62 ++++++++++++++++++++--------------------- samples/description.c | 2 +- samples/fixtures.c | 2 +- samples/long-messages.c | 2 +- samples/more-suites.c | 4 +-- samples/other-crashes.c | 4 +-- samples/report.c | 4 +-- samples/simple.c | 4 +-- samples/suites.c | 4 +-- samples/with-time.c | 2 +- 10 files changed, 45 insertions(+), 45 deletions(-) diff --git a/samples/asserts.c b/samples/asserts.c index abd20b0a..627f7787 100644 --- a/samples/asserts.c +++ b/samples/asserts.c @@ -1,54 +1,54 @@ #include Test(asserts, base) { - assert(true); - expect(true); + cr_assert(true); + cr_expect(true); - assert(true, "Assertions may take failure messages"); + cr_assert(true, "Assertions may take failure messages"); - assert(true, .msg = "You can use explicit named arguments"); + cr_assert(true, .msg = "You can use explicit named arguments"); - expect(false, "assert is fatal, expect isn't"); - assert(false, "This assert runs"); - assert(false, "This does not"); + cr_expect(false, "assert is fatal, expect isn't"); + cr_assert(false, "This assert runs"); + cr_assert(false, "This does not"); } Test(asserts, old_school) { if (false) - abort_test("You can abort the test with a message from anywhere"); + cr_abort_test("You can abort the test with a message from anywhere"); - abort_test(NULL); // or without a message + cr_abort_test(NULL); // or without a message } Test(asserts, string) { - assert_strings_eq("hello", "hello"); - assert_strings_neq("hello", "olleh"); + cr_assert_strings_eq("hello", "hello"); + cr_assert_strings_neq("hello", "olleh"); - assert_strings_gt("hello", "hell"); - assert_strings_geq("hello", "hell"); - assert_strings_geq("hello", "hello"); + cr_assert_strings_gt("hello", "hell"); + cr_assert_strings_geq("hello", "hell"); + cr_assert_strings_geq("hello", "hello"); - assert_strings_lt("hell", "hello"); - assert_strings_leq("hell", "hello"); - assert_strings_leq("hello", "hello"); + cr_assert_strings_lt("hell", "hello"); + cr_assert_strings_leq("hell", "hello"); + cr_assert_strings_leq("hello", "hello"); } Test(asserts, native) { - assert_eq(1, 1); - assert_neq(1, 2); + cr_assert_eq(1, 1); + cr_assert_neq(1, 2); - assert_lt(1, 2); - assert_leq(1, 2); - assert_leq(2, 2); + cr_assert_lt(1, 2); + cr_assert_leq(1, 2); + cr_assert_leq(2, 2); - assert_gt(2, 1); - assert_geq(2, 1); - assert_geq(2, 2); + cr_assert_gt(2, 1); + cr_assert_geq(2, 1); + cr_assert_geq(2, 2); } Test(asserts, float) { - assert_neq(0.1 * 0.1, 0.01); - assert_float_eq(0.1 * 0.1, 0.01, 0.001); + cr_assert_neq(0.1 * 0.1, 0.01); + cr_assert_float_eq(0.1 * 0.1, 0.01, 0.001); } struct dummy_struct { @@ -72,9 +72,9 @@ Test(asserts, array) { s2[1].a = 2; s2[1].b = 4; - assert_arrays_eq(arr1, arr1, 4); - assert_arrays_neq(arr1, arr2, 4); + cr_assert_arrays_eq(arr1, arr1, 4); + cr_assert_arrays_neq(arr1, arr2, 4); - assert_arrays_neq(s1, s2, 2); - assert_arrays_eq_cmp(s1, s2, 2, eq_dummy); + cr_assert_arrays_neq(s1, s2, 2); + cr_assert_arrays_eq_cmp(s1, s2, 2, eq_dummy); } diff --git a/samples/description.c b/samples/description.c index 335036ba..55b7b49c 100644 --- a/samples/description.c +++ b/samples/description.c @@ -1,7 +1,7 @@ #include Test(misc, failing, .description = "Just a failing test") { - assert(0); + cr_assert(0); } Test(misc, skipped, .description = "This one is skipped", .disabled = true) { diff --git a/samples/fixtures.c b/samples/fixtures.c index e077d8e2..1f7851c4 100644 --- a/samples/fixtures.c +++ b/samples/fixtures.c @@ -10,5 +10,5 @@ void teardown(void) { } Test(simple, fixtures, .init = setup, .fini = teardown) { - assert(1); + cr_assert(1); } diff --git a/samples/long-messages.c b/samples/long-messages.c index fc4c194a..02472e1b 100644 --- a/samples/long-messages.c +++ b/samples/long-messages.c @@ -1,5 +1,5 @@ #include Test(sample, long_msg) { - assert(0, "This is\nA long message\nSpawning multiple lines.\n\nFormatting is respected."); + cr_assert(0, "This is\nA long message\nSpawning multiple lines.\n\nFormatting is respected."); } diff --git a/samples/more-suites.c b/samples/more-suites.c index 1b2f14e0..95d70393 100644 --- a/samples/more-suites.c +++ b/samples/more-suites.c @@ -9,11 +9,11 @@ void teardown_suite(void) { TestSuite(suite1, .init = setup_suite, .fini = teardown_suite); Test(suite1, test) { - assert(1); + cr_assert(1); } Test(suite2, test) { - assert(1); + cr_assert(1); } TestSuite(disabled, .disabled = true); diff --git a/samples/other-crashes.c b/samples/other-crashes.c index a1baa278..ab689bb2 100644 --- a/samples/other-crashes.c +++ b/samples/other-crashes.c @@ -6,9 +6,9 @@ void crash(void) { } Test(misc, setup_crash, .init = crash) { - assert(true); + cr_assert(true); } Test(misc, teardown_crash, .fini = crash) { - assert(true); + cr_assert(true); } diff --git a/samples/report.c b/samples/report.c index 5c92b90f..4c7a8499 100644 --- a/samples/report.c +++ b/samples/report.c @@ -2,8 +2,8 @@ #include Test(sample, test) { - expect(0); - assert(1); + cr_expect(0); + cr_assert(1); } ReportHook(PRE_INIT)(struct criterion_test *test) { diff --git a/samples/simple.c b/samples/simple.c index c9dfa278..d5916f5a 100644 --- a/samples/simple.c +++ b/samples/simple.c @@ -1,9 +1,9 @@ #include Test(misc, failing) { - assert(0); + cr_assert(0); } Test(misc, passing) { - assert(1); + cr_assert(1); } diff --git a/samples/suites.c b/samples/suites.c index 50edf6ef..d19d7b2d 100644 --- a/samples/suites.c +++ b/samples/suites.c @@ -1,9 +1,9 @@ #include Test(first_suite, test) { - assert(1); + cr_assert(1); } Test(second_suite, test) { - assert(1); + cr_assert(1); } diff --git a/samples/with-time.c b/samples/with-time.c index 1d67a01b..65958f5d 100644 --- a/samples/with-time.c +++ b/samples/with-time.c @@ -1,5 +1,5 @@ #include Test(samples, timed) { - assert(0); + cr_assert(0); } From b0e5becfb9d67c1aa2feec37fda2194d596a53e8 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 25 Apr 2015 17:04:47 +0200 Subject: [PATCH 4/9] Added better deprecation message --- include/criterion/assert.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/include/criterion/assert.h b/include/criterion/assert.h index 62378dcd..aa160186 100644 --- a/include/criterion/assert.h +++ b/include/criterion/assert.h @@ -273,17 +273,14 @@ struct criterion_assert_args { // It shall be removed in the text major version of Criterion # ifndef CRITERION_NO_COMPAT -/* -# define CRITERION_ASSERT_DEPRECATED_(Name) \ - _Pragma("message \"" \ - "The " #Name " macro is deprecated, " \ - "please use cr_" #Name " instead." \ - "\"" \ +# define CRITERION_ASSERT_DEPRECATED_(Name) CRITERION_ASSERT_DEPRECATED__( \ + message \ + "The `" #Name "` macro is deprecated, " \ + "please use `cr_" #Name "` instead." \ ) - */ -# define CRITERION_ASSERT_DEPRECATED_(Name) \ - _Pragma("message \"This macro is deprecated, please use its `cr_`-prefixed alternative instead.\"") +# define CRITERION_ASSERT_DEPRECATED__(Msg) \ + _Pragma(#Msg) # ifndef assert # define assert(...) CRITERION_ASSERT_DEPRECATED_(assert) cr_assert(__VA_ARGS__) From 44b1bc45f6237ed5e05431e90d98e9096d7afc8d Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 25 Apr 2015 17:07:57 +0200 Subject: [PATCH 5/9] Updated doc with prefixed assertions --- doc/starter.rst | 54 ++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/doc/starter.rst b/doc/starter.rst index 7021a383..a85bfed0 100644 --- a/doc/starter.rst +++ b/doc/starter.rst @@ -26,14 +26,14 @@ Asserting things Assertions come in two kinds: -* ``assert*`` are assertions that are fatal to the current test if failed; +* ``cr_assert*`` are assertions that are fatal to the current test if failed; in other words, if the condition evaluates to ``false``, the test is marked as a failure and the execution of the function is aborted. -* ``expect*`` are, in the other hand, assertions that are not fatal to the +* ``cr_expect*`` are, in the other hand, assertions that are not fatal to the test. Execution will continue even if the condition evaluates to ``false``, but the test will be marked as a failure. -``assert()`` and ``expect()`` are the most simple kinds of assertions +``cr_assert()`` and ``cr_expect()`` are the most simple kinds of assertions criterion has to offer. They both take a mandatory condition as a first parameter, and an optional failure message: @@ -43,45 +43,45 @@ parameter, and an optional failure message: #include Test(sample, test) { - expect(strlen("Test") == 4, "Expected \"Test\" to have a length of 4."); - expect(strlen("Hello") == 4, "This will always fail, why did I add this?"); - assert(strlen("") == 0); + cr_expect(strlen("Test") == 4, "Expected \"Test\" to have a length of 4."); + cr_expect(strlen("Hello") == 4, "This will always fail, why did I add this?"); + cr_assert(strlen("") == 0); } On top of those, more assertions are available for common operations: -* ``assert_null(Ptr, [Message])``: passes if Ptr is NULL. -* ``assert_eq(Actual, Expected, [Message])``: passes if Actual == Expected. -* ``assert_lt(Actual, Expected, [Message])``: passes if Actual < Expected. -* ``assert_leq(Actual, Expected, [Message])``: passes if Actual <= Expected. -* ``assert_gt(Actual, Expected, [Message])``: passes if Actual > Expected. -* ``assert_geq(Actual, Expected, [Message])``: passes if Actual >= Expected. -* ``assert_float_eq(Actual, Expected, Epsilon, [Message])``: +* ``cr_assert_null(Ptr, [Message])``: passes if Ptr is NULL. +* ``cr_assert_eq(Actual, Expected, [Message])``: passes if Actual == Expected. +* ``cr_assert_lt(Actual, Expected, [Message])``: passes if Actual < Expected. +* ``cr_assert_leq(Actual, Expected, [Message])``: passes if Actual <= Expected. +* ``cr_assert_gt(Actual, Expected, [Message])``: passes if Actual > Expected. +* ``cr_assert_geq(Actual, Expected, [Message])``: passes if Actual >= Expected. +* ``cr_assert_float_eq(Actual, Expected, Epsilon, [Message])``: passes if Actual == Expected with an error of Epsilon. -* ``assert_arrays_eq(Actual, Expected, Size, [Message])``: +* ``cr_assert_arrays_eq(Actual, Expected, Size, [Message])``: passes if all elements of Actual (from 0 to Size - 1) are equals to those of Expected. -* ``assert_arrays_eq_cmp(Actual, Expected, Size, Cmp, [Message])``: +* ``cr_assert_arrays_eq_cmp(Actual, Expected, Size, Cmp, [Message])``: Same as ``arrays_eq`` but equality is defined by the result of the binary Cmp function. Equality and lexical comparison assertions are also available for strings: -* ``assert_strings_eq(Actual, Expected, [Message])`` -* ``assert_strings_lt(Actual, Expected, [Message])`` -* ``assert_strings_leq(Actual, Expected, [Message])`` -* ``assert_strings_gt(Actual, Expected, [Message])`` -* ``assert_strings_geq(Actual, Expected, [Message])`` +* ``cr_assert_strings_eq(Actual, Expected, [Message])`` +* ``cr_assert_strings_lt(Actual, Expected, [Message])`` +* ``cr_assert_strings_leq(Actual, Expected, [Message])`` +* ``cr_assert_strings_gt(Actual, Expected, [Message])`` +* ``cr_assert_strings_geq(Actual, Expected, [Message])`` And some assertions have a logical negative counterpart: -* ``assert_not(Condition, [Message])`` -* ``assert_not_null(Ptr, [Message])`` -* ``assert_neq(Actual, Unexpected, [Message])`` -* ``assert_float_neq(Actual, Unexpected, Epsilon, [Message])`` -* ``assert_strings_neq(Actual, Unexpected, [Message])`` -* ``assert_arrays_neq(Actual, Unexpected, Size, [Message])`` -* ``assert_arrays_neq_cmp(Actual, Unexpected, Size, Cmp, [Message])`` +* ``cr_assert_not(Condition, [Message])`` +* ``cr_assert_not_null(Ptr, [Message])`` +* ``cr_assert_neq(Actual, Unexpected, [Message])`` +* ``cr_assert_float_neq(Actual, Unexpected, Epsilon, [Message])`` +* ``cr_assert_strings_neq(Actual, Unexpected, [Message])`` +* ``cr_assert_arrays_neq(Actual, Unexpected, Size, [Message])`` +* ``cr_assert_arrays_neq_cmp(Actual, Unexpected, Size, Cmp, [Message])`` Of course, every ``assert`` has an ``expect`` counterpart. From 0179f32b0185163846fa69d113c489f14917e30e Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 25 Apr 2015 17:28:06 +0200 Subject: [PATCH 6/9] Only define _ASSERT_H when it is not already defined --- include/criterion/assert.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/criterion/assert.h b/include/criterion/assert.h index aa160186..5e7f6168 100644 --- a/include/criterion/assert.h +++ b/include/criterion/assert.h @@ -287,7 +287,9 @@ struct criterion_assert_args { // this is needed to make the POSIX assert.h redefine assert if // subsequently included -# define _ASSERT_H 1 +# ifndef _ASSERT_H +# define _ASSERT_H 1 +# endif /* !_ASSERT_H */ # endif /* !assert */ # define abort_test(Message) CRITERION_ASSERT_DEPRECATED_(abort_test) cr_abort_test(Message) From f7d88b3e7362bc5663ea68c0d1942e17e23fe3ca Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 26 Apr 2015 15:51:02 +0200 Subject: [PATCH 7/9] updated build version on appveyor --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 76e605fd..532782d8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 1.0.0_b{build}-{branch} +version: 1.2.0_b{build}-{branch} os: Windows Server 2012 From 94d48e4edd82e012c32591fbdfef98b5e6b07864 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 26 Apr 2015 16:01:44 +0200 Subject: [PATCH 8/9] Added bumpversion config --- .bumpversion.cfg | 10 ++++++++++ .gitignore | 1 + 2 files changed, 11 insertions(+) create mode 100644 .bumpversion.cfg diff --git a/.bumpversion.cfg b/.bumpversion.cfg new file mode 100644 index 00000000..0a160631 --- /dev/null +++ b/.bumpversion.cfg @@ -0,0 +1,10 @@ +[bumpversion] +current_version = 1.2.0 +commit = True + +[bumpversion:file:configure.ac] + +[bumpversion:file:doc/conf.py] + +[bumpversion:file:appveyor.yml] + diff --git a/.gitignore b/.gitignore index c1f4e54d..f9e0c456 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ !*/ !.gitignore +!.bumpversion.cfg !*.c !*.h From 0f25296e77dbca6999a9ff4bc8913b7a902977b0 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 26 Apr 2015 16:01:57 +0200 Subject: [PATCH 9/9] =?UTF-8?q?Bump=20version:=201.2.0=20=E2=86=92=201.2.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- appveyor.yml | 2 +- configure.ac | 2 +- doc/conf.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 0a160631..bbcb1950 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.2.0 +current_version = 1.2.1 commit = True [bumpversion:file:configure.ac] diff --git a/appveyor.yml b/appveyor.yml index 532782d8..38c1effe 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 1.2.0_b{build}-{branch} +version: 1.2.1_b{build}-{branch} os: Windows Server 2012 diff --git a/configure.ac b/configure.ac index 49e32525..228b0fe1 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ([2.60]) -AC_INIT([criterion], [1.2.0], [], [criterion], [franklinmathieu@gmail.com]) +AC_INIT([criterion], [1.2.1], [], [criterion], [franklinmathieu@gmail.com]) AC_CONFIG_SRCDIR([src/runner.c]) LT_PREREQ([2.2.4]) diff --git a/doc/conf.py b/doc/conf.py index 2dd677a8..a4d0f240 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -39,7 +39,7 @@ # built documents. # # The short X.Y version. -version = '1.2.0' +version = '1.2.1' # The full version, including alpha/beta/rc tags. release = version