Skip to content

Commit

Permalink
fix: improve negated assertion messages
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschumann committed Jul 31, 2023
1 parent 8994065 commit dc9611b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
62 changes: 34 additions & 28 deletions src/cunit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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: <true> 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: <false> 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) \
Expand Down

0 comments on commit dc9611b

Please sign in to comment.