项目作者: daddinuz

项目描述 :
An assertions library written in C99.
高级语言: C
项目地址: git://github.com/daddinuz/traits.git
创建时间: 2016-10-09T22:31:39Z
项目社区:https://github.com/daddinuz/traits

开源协议:MIT License

下载


Traits

Build Status

Traits is an assertion library written in C99.
It’s an header only library so you just have to include
traits.h in your code and you are ready for bugs hunting.

Assertion Summary

Below are listed all the assertion macros in the library.
Every macro is “overloaded” and can be called specifying
a custom message in the same way as you would do using printf.

That means that you can write something like this:

  1. /* Just assert without specifying a message */
  2. assert_that(5 == 5);
  3. /* Assert specifying a message */
  4. int x = 5, y = 6;
  5. assert_that(x == y, "Ops! Expected: %d, got: %d", x, y);

Basic

  1. traits_assert(x);
  2. assert_that(x);

Boolean

  1. assert_true(x);
  2. assert_false(x);

Numerical

  1. assert_equal(e, a);
  2. assert_not_equal(e, a);
  3. assert_greater(e, a);
  4. assert_greater_equal(e, a);
  5. assert_less(e, a);
  6. assert_less_equal(e, a);

Pointer

  1. assert_null(x);
  2. assert_not_null(x);

Memory

  1. assert_memory_equal(e, a, s);
  2. assert_memory_not_equal(e, a, s);

String

  1. assert_string_equal(e, a);
  2. assert_string_not_equal(e, a);

Helpers

Traits defines also some helpers to make easier and safer your custom assertion:

  1. eq(e, a) /* ((e) == (a)) */
  2. ne(e, a) /* ((e) != (a)) */
  3. gt(e, a) /* ((e) > (a)) */
  4. ge(e, a) /* ((e) >= (a)) */
  5. lt(e, a) /* ((e) < (a)) */
  6. le(e, a) /* ((e) <= (a)) */
  7. as(T, x) /* It's simply a cast: ((T)(x)) */
  8. /* Those are just a combination of the above */
  9. eq_as(T, e, a) /* eq(as(T, e), as(T, a)) */
  10. ne_as(T, e, a) /* ne(as(T, e), as(T, a)) */
  11. gt_as(T, e, a) /* gt(as(T, e), as(T, a)) */
  12. ge_as(T, e, a) /* ge(as(T, e), as(T, a)) */
  13. lt_as(T, e, a) /* lt(as(T, e), as(T, a)) */
  14. le_as(T, e, a) /* le(as(T, e), as(T, a)) */