[Tarantool-patches] [PATCH v2 luajit 2/6] test: introduce module for C tests
Maxim Kokryashkin
m.kokryashkin at tarantool.org
Fri May 19 14:46:16 MSK 2023
Hi, Sergey!
Thanks for the patch!
LGTM.
>
>diff --git a/test/tarantool-c-tests/test.h b/test/tarantool-c-tests/test.h
>new file mode 100644
>index 00000000..28df9daf
>--- /dev/null
>+++ b/test/tarantool-c-tests/test.h
>@@ -0,0 +1,217 @@
Looks so much better now!
>+#define LOCATION_FMT "location:\t%s:%d\n"
>+#define ASSERT_NAME_FMT(name) "failed_assertion:\t" #name "\n"
>+#define ASSERT_EQUAL_FMT(name_type, type_fmt) \
>+ LOCATION_FMT \
>+ ASSERT_NAME_FMT(assert_ ## name_type ## _equal) \
>+ "got: " type_fmt "\n" \
>+ "expected: " type_fmt "\n"
>+
>+#define ASSERT_NOT_EQUAL_FMT(type_fmt) \
>+ LOCATION_FMT \
>+ ASSERT_NAME_FMT(assert_ ## name_type ## _not_equal) \
>+ "got: " type_fmt "\n" \
>+ "unexpected: " type_fmt "\n"
>+
>+#define assert_true(cond) do { \
>+ if (!(cond)) { \
>+ test_save_diag_data(LOCATION_FMT \
>+ "condition_failed:\t'" #cond "'\n", \
>+ __FILE__, __LINE__); \
>+ _test_exit(TEST_LJMP_EXIT_FAILURE); \
>+ } \
>+} while (0)
>+
>+#define assert_false(cond) assert_true(!(cond))
>+
>+#define assert_general(cond, fmt, ...) do { \
>+ if (!(cond)) { \
>+ test_save_diag_data(fmt, __VA_ARGS__); \
>+ _test_exit(TEST_LJMP_EXIT_FAILURE); \
>+ } \
>+} while (0)
>+
>+#define assert_ptr_equal(got, expected) do { \
>+ assert_general((got) == (expected), \
>+ ASSERT_EQUAL_FMT(ptr, "%p"), \
>+ __FILE__, __LINE__, (got), (expected) \
>+ ); \
>+} while (0)
>+
>+#define assert_ptr_not_equal(got, unexpected) do { \
>+ assert_general((got) != (unexpected), \
>+ ASSERT_NOT_EQUAL_FMT(ptr, "%p"), \
>+ __FILE__, __LINE__, (got), (unexpected) \
>+ ); \
>+} while (0)
>+
>+
>+#define assert_int_equal(got, expected) do { \
>+ assert_general((got) == (expected), \
>+ ASSERT_EQUAL_FMT(int, "%d"), \
>+ __FILE__, __LINE__, (got), (expected) \
>+ ); \
>+} while (0)
>+
>+#define assert_int_not_equal(got, unexpected) do { \
>+ assert_general((got) != (unexpected), \
>+ ASSERT_NOT_EQUAL_FMT(int, "%d"), \
>+ __FILE__, __LINE__, (got), (unexpected) \
>+ ); \
>+} while (0)
>+
>+#define assert_sizet_equal(got, expected) do { \
>+ assert_general((got) == (expected), \
>+ ASSERT_EQUAL_FMT(sizet, "%lu"), \
>+ __FILE__, __LINE__, (got), (expected) \
>+ ); \
>+} while (0)
>+
>+#define assert_sizet_not_equal(got, unexpected) do { \
>+ assert_general((got) != (unexpected), \
>+ ASSERT_NOT_EQUAL_FMT(sizet, "%lu"), \
>+ __FILE__, __LINE__, (got), (unexpected) \
>+ ); \
>+} while (0)
>+
>+/* Check that doubles are __exactly__ the same. */
>+#define assert_double_equal(got, expected) do { \
>+ assert_general((got) == (expected), \
>+ ASSERT_EQUAL_FMT(double, "%lf"), \
>+ __FILE__, __LINE__, (got), (expected) \
>+ ); \
>+} while (0)
>+
>+/* Check that doubles are not __exactly__ the same. */
>+#define assert_double_not_equal(got, unexpected) do { \
>+ assert_general((got) != (unexpected), \
>+ ASSERT_NOT_EQUAL_FMT(double, "%lf"), \
>+ __FILE__, __LINE__, (got), (unexpected) \
>+ ); \
>+} while (0)
>+
>+#endif /* TEST_H */
>--
>2.34.1
--
Best regards,
Maxim Kokryashkin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.tarantool.org/pipermail/tarantool-patches/attachments/20230519/2ebc7aaa/attachment.htm>
More information about the Tarantool-patches
mailing list