diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-01-01 09:18:12 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-01-01 09:18:12 -0500 |
commit | d946eeba71660b68d77f4a2d2bcf3609d472c2c7 (patch) | |
tree | 97afe34556601761da5e8066eef8d3acf1a4eb15 | |
parent | 6bf3a50d44cd3868b32c973f48d2c862a5c6385d (diff) |
basic testing of NDEBUG and assert()
-rw-r--r-- | assert.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/assert.c b/assert.c new file mode 100644 index 0000000..9b4f0ae --- /dev/null +++ b/assert.c @@ -0,0 +1,41 @@ +#include <stdio.h> +#include "test.h" + +void test_assert(void) +{ + int n = 0; + + testing_header("assert.h"); + +#define NDEBUG +#include <assert.h> + testing_comment("Expression with side-effect should be removed by preprocessor"); + test_void(assert(n = 1)); + test_int_equals(n, 0); + +#undef NDEBUG +#include <assert.h> + testing_comment("Expression with side-effect should execute"); + test_void(assert(n = 1)); + test_int_equals(n, 1); + +#define NDEBUG +#include <assert.h> + testing_comment("Successful assertion should be removed by preprocessor"); + test_void(assert(n == 1)); + +#undef NDEBUG +#include <assert.h> + testing_comment("Successful assertion should execute"); + test_void(assert(n == 1)); + +#define NDEBUG +#include <assert.h> + testing_comment("Unsuccessful assertion should be removed by preprocessor"); + test_void(assert(n == 0)); + +#undef NDEBUG +#include <assert.h> + testing_comment("Unsuccessful assertion should execute"); + test_void(assert(n == 0)); +} |