[Tarantool-patches] [PATCH luajit 1/2] test: introduce asserts assert_str{_not}_equal

Sergey Bronnikov estetus at gmail.com
Tue Oct 31 21:11:43 MSK 2023


From: Sergey Bronnikov <sergeyb at tarantool.org>

The patch follows up commit a0483bd214f2 ("test: introduce module for C
tests") and adds additional asserts suitable for comparing strings.
---
 test/tarantool-c-tests/README.md |  2 ++
 test/tarantool-c-tests/test.h    | 17 +++++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/test/tarantool-c-tests/README.md b/test/tarantool-c-tests/README.md
index 462534be..8fad6407 100644
--- a/test/tarantool-c-tests/README.md
+++ b/test/tarantool-c-tests/README.md
@@ -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
 
diff --git a/test/tarantool-c-tests/test.h b/test/tarantool-c-tests/test.h
index 8b14c705..bbf573b2 100644
--- a/test/tarantool-c-tests/test.h
+++ b/test/tarantool-c-tests/test.h
@@ -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.
@@ -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 */
-- 
2.34.1



More information about the Tarantool-patches mailing list