Skip to content

Commit

Permalink
test: introduce asserts assert_str{_not}_equal
Browse files Browse the repository at this point in the history
The patch follows up commit a0483bd ("test: introduce module for C
tests") and adds additional asserts suitable for comparing strings.
  • Loading branch information
ligurio committed Oct 3, 2023
1 parent 3a16be9 commit a860626
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions test/tarantool-c-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ glibc `assert()`:
equal to the `b`.
* `assert_double{_not}_equal(a, b)` -- check that two doubles are {not}
**exactly** equal.
* `assert_str{_not}_equal(a, b)` -- check that `char *` variable `a` is {not}
equal to the `b`.
## Directives
Expand Down
17 changes: 15 additions & 2 deletions test/tarantool-c-tests/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
* * Helpers assert macros:
* - assert_uint_equal if needed
* - assert_uint_not_equal if needed
* - assert_str_equal if needed
* - assert_str_not_equal if needed
* - assert_memory_equal if needed
* - assert_memory_not_equal if needed
* * Pragmas.
Expand Down Expand Up @@ -214,4 +212,19 @@ static inline int todo(const char *reason)
); \
} while (0)

#define assert_str_equal(got, expected, n) do { \
assert_general(strncmp(got, expected, n) == 0, \
ASSERT_EQUAL_FMT(int, "%d"), \
__FILE__, __LINE__, (got), (expected) \
); \
} while (0)

#define assert_str_not_equal(got, unexpected, n) do { \
assert_general(strncmp(got, expected, n) != 0, \
ASSERT_NOT_EQUAL_FMT(int, "%d"), \
__FILE__, __LINE__, (got), (unexpected) \
); \
} while (0)


#endif /* TARANTOOL_LUAJIT_TEST_H */

0 comments on commit a860626

Please sign in to comment.