From dc9611bfa5e70ea608c08a2a901d2ffe35bda3d8 Mon Sep 17 00:00:00 2001 From: Falko Schumann Date: Mon, 31 Jul 2023 10:53:55 +0200 Subject: [PATCH] fix: improve negated assertion messages --- CHANGELOG.md | 6 +++-- src/cunit.h | 62 ++++++++++++++++++++++++++++------------------------ 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a4b1bc..cbfa017 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - In assertion messages, the variable name was displayed instead of the variable value. +- Fix messages of negated assertions. ## [1.0.0] - 2013-07-31 @@ -24,5 +25,6 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Check assertions with ASSERT macros. - Run tests with CI friendly output on console and return value. -[unreleased]: https://github.com/falkoschumann/cunit/compare/v1.0.0...HEAD -[0.0.1]: https://github.com/falkoschumann/cunit/releases/tag/v1.0.0 +[unreleased]: https://github.com/falkoschumann/cunit/compare/v1.0.1...HEAD +[1.0.1]: https://github.com/falkoschumann/cunit/compare/v1.0.0...v1.0.1 +[1.0.0]: https://github.com/falkoschumann/cunit/releases/tag/v1.0.0 diff --git a/src/cunit.h b/src/cunit.h index 815f103..4b866dc 100644 --- a/src/cunit.h +++ b/src/cunit.h @@ -44,46 +44,52 @@ void clear_tests(void); } \ } -#define ASSERT_TRUE(value) \ - { ASSERT_IMPLEMENTATION((value), "expected: true but was: false", 1, 0); } +#define ASSERT_TRUE(value) \ + { \ + ASSERT_IMPLEMENTATION((value), "expected: but was: <%d>", value, \ + NULL); \ + } -#define ASSERT_FALSE(value) \ - { ASSERT_IMPLEMENTATION(!(value), "expected: false but was: true", 0, 1); } +#define ASSERT_FALSE(value) \ + { \ + ASSERT_IMPLEMENTATION(!(value), "expected: but was: <%d>", value, \ + NULL); \ + } -#define ASSERT_LONG_EQUALS(expected, actual) \ - { \ - ASSERT_IMPLEMENTATION((expected == actual), "expected: %d but was: %d", \ - expected, actual); \ +#define ASSERT_LONG_EQUALS(expected, actual) \ + { \ + ASSERT_IMPLEMENTATION((expected == actual), \ + "expected: <%d> but was: <%d>", expected, actual); \ } -#define ASSERT_LONG_NOT_EQUALS(expected, actual) \ - { \ - ASSERT_IMPLEMENTATION((expected != actual), "expected: %d but was: %d", \ - expected, actual); \ +#define ASSERT_LONG_NOT_EQUALS(expected, actual) \ + { \ + ASSERT_IMPLEMENTATION((expected != actual), \ + "expected: not equal but was: <%d>", actual, NULL); \ } -#define ASSERT_DOUBLE_EQUALS(expected, actual, delta) \ - { \ - ASSERT_IMPLEMENTATION((fabs(expected - actual) < delta), \ - "expected: %f but was: %f", expected, actual); \ +#define ASSERT_DOUBLE_EQUALS(expected, actual, delta) \ + { \ + ASSERT_IMPLEMENTATION((fabs(expected - actual) <= delta), \ + "expected: <%f> but was: <%f>", expected, actual); \ } -#define ASSERT_DOUBLE_NOT_EQUALS(expected, actual, delta) \ - { \ - ASSERT_IMPLEMENTATION((fabs(expected - actual) >= delta), \ - "expected: %f but was: %f", expected, actual); \ +#define ASSERT_DOUBLE_NOT_EQUALS(expected, actual, delta) \ + { \ + ASSERT_IMPLEMENTATION((fabs(expected - actual) > delta), \ + "expected: not equal but was: <%f>", actual, NULL); \ } -#define ASSERT_STRING_EQUALS(expected, actual) \ - { \ - ASSERT_IMPLEMENTATION((strcmp(expected, actual) == 0), \ - "expected: %s but was: %s", expected, actual); \ +#define ASSERT_STRING_EQUALS(expected, actual) \ + { \ + ASSERT_IMPLEMENTATION((strcmp(expected, actual) == 0), \ + "expected: <%s> but was: <%s>", expected, actual); \ } -#define ASSERT_STRING_NOT_EQUALS(expected, actual) \ - { \ - ASSERT_IMPLEMENTATION((strcmp(expected, actual) != 0), \ - "expected: %s but was: %s", expected, actual); \ +#define ASSERT_STRING_NOT_EQUALS(expected, actual) \ + { \ + ASSERT_IMPLEMENTATION((strcmp(expected, actual) != 0), \ + "expected: not equal but was: <%s>", actual, NULL); \ } #define ASSERT_NULL(value) \