Skip to content

Commit 889d77d

Browse files
ligurioigormunkin
authored andcommitted
test: introduce asserts assert_str{_not}_equal
The patch follows up commit a0483bd ("test: introduce module for C tests") and adds additional asserts suitable for comparing strings. Reviewed-by: Sergey Kaplun <[email protected]> Reviewed-by: Igor Munkin <[email protected]> Signed-off-by: Igor Munkin <[email protected]>
1 parent 116bde6 commit 889d77d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

test/tarantool-c-tests/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ glibc `assert()`:
3535
equal to the `b`.
3636
* `assert_double{_not}_equal(a, b)` -- check that two doubles are {not}
3737
**exactly** equal.
38+
* `assert_str{_not}_equal(a, b)` -- check that `char *` variable `a` is {not}
39+
equal to the `b`.
3840
3941
## Directives
4042

test/tarantool-c-tests/test.h

+14-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
* * Helpers assert macros:
1414
* - assert_uint_equal if needed
1515
* - assert_uint_not_equal if needed
16-
* - assert_str_equal if needed
17-
* - assert_str_not_equal if needed
1816
* - assert_memory_equal if needed
1917
* - assert_memory_not_equal if needed
2018
* * Pragmas.
@@ -214,4 +212,18 @@ static inline int todo(const char *reason)
214212
); \
215213
} while (0)
216214

215+
#define assert_str_equal(got, expected) do { \
216+
assert_general(strcmp(got, expected) == 0, \
217+
ASSERT_EQUAL_FMT(str, "%s"), \
218+
__FILE__, __LINE__, (got), (expected) \
219+
); \
220+
} while (0)
221+
222+
#define assert_str_not_equal(got, unexpected) do { \
223+
assert_general(strcmp(got, expected) != 0, \
224+
ASSERT_NOT_EQUAL_FMT(str, "%s"), \
225+
__FILE__, __LINE__, (got), (unexpected) \
226+
); \
227+
} while (0)
228+
217229
#endif /* TARANTOOL_LUAJIT_TEST_H */

0 commit comments

Comments
 (0)