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

Sergey Bronnikov sergeyb at tarantool.org
Wed Nov 15 12:32:36 MSK 2023


Hello, Sergey

On 11/14/23 11:55, Sergey Kaplun wrote:


<snipped>

> I'll proceed with the review here with the diff below:
>
>> 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..2f2d9ea2 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,18 @@ static inline int todo(const char *reason)
>>           );                                                              \
>>   } while (0)
>>   
>> +#define assert_str_equal(got, expected, n) do {                         \
>> +        assert_general(strncmp(got, expected, n) == 0,                  \
> Maybe it is better to just use `strcmp(got, expected)` instead?
> We don't really care about the number of characters to check.
>
> Or we can use `strncmp(got, expected, strlen(expected))`, as the most
> common case.
>
> This removes an additional argument, and the description in the
> <README.md> and declaration here become the same.
>
>> +                       ASSERT_EQUAL_FMT(str, "%s"),                     \
>> +                       __FILE__, __LINE__, (got), (expected)            \
>> +        );                                                              \
>> +} while (0)
>> +
>> +#define assert_str_not_equal(got, unexpected, n) do {                   \
>> +        assert_general(strncmp(got, expected, n) != 0,                  \
> Ditto.

Fixed by patch below:


diff --git a/test/tarantool-c-tests/lj-881-fix-lua-concat.test.c 
b/test/tarantool-c-tests/lj-881-fix-lua-concat.test.c
index 1835d273..f028c457 100644
--- a/test/tarantool-c-tests/lj-881-fix-lua-concat.test.c
+++ b/test/tarantool-c-tests/lj-881-fix-lua-concat.test.c
@@ -77,7 +77,7 @@ static int lua_concat_testcase(void *test_state)
      const char *str = lua_tostring(L, -1);
      assert_int_equal(lua_gettop(L), top - 2 + 1);
      const char expected_str[] = CONCAT("A + ", TEST_VALUE);
-    assert_str_equal(str, expected_str, strlen(expected_str));
+    assert_str_equal(str, expected_str);

      /* Teardown. */
      lua_settop(L, 0);
diff --git a/test/tarantool-c-tests/test.h b/test/tarantool-c-tests/test.h
index 2f2d9ea2..5e5c96b2 100644
--- a/test/tarantool-c-tests/test.h
+++ b/test/tarantool-c-tests/test.h
@@ -212,15 +212,15 @@ static inline int todo(const char *reason)
      );                                \
  } while (0)

-#define assert_str_equal(got, expected, n) do {                \
-    assert_general(strncmp(got, expected, n) == 0,            \
+#define assert_str_equal(got, expected) do {                \
+    assert_general(strncmp(got, expected, strlen(expected)) == 0,    \
                 ASSERT_EQUAL_FMT(str, "%s"),            \
                 __FILE__, __LINE__, (got), (expected)        \
      );                                \
  } while (0)

-#define assert_str_not_equal(got, unexpected, n) do { \
-    assert_general(strncmp(got, expected, n) != 0,            \
+#define assert_str_not_equal(got, unexpected) do {            \
+    assert_general(strncmp(got, expected, strlen(expected)) != 0,    \
                 ASSERT_NOT_EQUAL_FMT(str, "%s"),            \
                 __FILE__, __LINE__, (got), (unexpected)        \
      );                                \

>
>> +                       ASSERT_NOT_EQUAL_FMT(str, "%s"),                 \
>> +                       __FILE__, __LINE__, (got), (unexpected)          \
>> +        );                                                              \
>> +} while (0)
>> +
>>   #endif /* TARANTOOL_LUAJIT_TEST_H */


More information about the Tarantool-patches mailing list