[Tarantool-patches] [PATCH luajit 1/2] test: introduce asserts assert_str{_not}_equal
Sergey Bronnikov
sergeyb at tarantool.org
Fri Nov 10 14:40:24 MSK 2023
Hi, Sergey
changes applied and force-pushed.
On 11/1/23 10:40, Sergey Kaplun wrote:
> Hi, Sergey!
> Thanks for the patch!
> Please, consider my comments below.
>
> On 31.10.23, Sergey Bronnikov wrote:
>> 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
> <snipped>
>
>> 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
> <snipped>
>
>> @@ -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"), \
> Typo: s/int/str/
Fixed, thanks.
>
>> + __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"), \
> Typo: s/int/str/
Fixed, thanks.
>> + __FILE__, __LINE__, (got), (unexpected) \
>> + ); \
>> +} while (0)
> If some test fails we got the following output:
>
> | TAP version 13
> | 1..1
> | not ok 1 - lua_concat_testcase
> | ---
> | location: /home/burii/reviews/luajit/lj-881-lua-concat/test/tarantool-c-tests/lj-881-fix-lua-concat.test.c:81
> | failed_assertion: assert_str_equal
> | got: 1652880104
> | expected: -1138225337
> | ...
> | # Failed 1 tests out of 1
>
> Failed assertion field is incorrect (see the comment above).
> But the most important is "got" and "expected" fields, that returns the
> addresses of strings, which isn't very meaningful.
>
> I suggest dumping the strings instead if they are not long enough (less
> than 128 symbols, I suppose). The maxdump string length should be
> a customizeable parameter. I suggest defining a macro `MAX_DUMP_STRLEN`
> inside the <test.h> header. So the user can redefine it before the
> `assert_str_{not_}equal()` and use a custom value.
I don't like your idea for the same reasons described by Igor.
> If the string is too long, we should dump the offset of the mismatched
> symbol. Or maybe it's better to always dump it.
>
> Thoughts?
Now implementation of `assert_str_{not}_equal` is good enough for
proposed test.
Don't get why we should think about comparison of long strings.
We could update assert implementation as soon it will be required by
other tests,
now it is not required.
>
> Side note:
>
> Also, this comparing "by eye" isn't very convenient if values aren't
> aligned, so maybe it is better to use spaces instead of tabs to align
> values? This may be added within the separate patch series later.
>
>> +
>> +
> Nit: Excess empty line.
Fixed, thanks.
>
>> #endif /* TARANTOOL_LUAJIT_TEST_H */
>> --
>> 2.34.1
>>
More information about the Tarantool-patches
mailing list