From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 5B066651F79; Tue, 14 Nov 2023 11:59:47 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5B066651F79 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1699952387; bh=LpzlGT54TgYljVtVurzDm9wwWU7KhHxZXJDUbv2qDd4=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=h92hIve2vt7JMi7kwGwf17bA4OgGUoDhvbFKM2YTmW+7Wx55eRJH4lNXO1jRJqOtO LPEqPW1sSFm/ubxQNVgs5WQanYb/6jR8g2dTQyg8nO8Oy/CUajVSJDGMA/73ffQcVJ TphPbQv5Q6oJ/Oy/2RTYY16c30svUeCzBfI3/+5s= Received: from smtp48.i.mail.ru (smtp48.i.mail.ru [95.163.41.86]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 945B9651F79 for ; Tue, 14 Nov 2023 11:59:45 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 945B9651F79 Received: by smtp48.i.mail.ru with esmtpa (envelope-from ) id 1r2pGq-001xJE-0B; Tue, 14 Nov 2023 11:59:44 +0300 Date: Tue, 14 Nov 2023 11:55:10 +0300 To: Sergey Bronnikov Message-ID: References: <639a0c42-13a6-4a2e-ac4f-6077b89ff6fe@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <639a0c42-13a6-4a2e-ac4f-6077b89ff6fe@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9562B317E0136C8D382B5AB51A0CE7EC9F5A0ADFABA6D1A49182A05F5380850404C228DA9ACA6FE279EF8997C2D7A180F2016D387473C64187193E17BF7E23B1AABD58DC5E47996AE X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A3295C83650092F9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375E7A1B5661595F038638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D869674729277FFED0975141451F7C4E49117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCECADA55FE5B58BB7A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD186FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE0AC5B80A05675ACDC67AC315686ED4D3D8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE3D56D36E97F3F038C6136E347CC761E07C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CA9FF340AA05FB58C2E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F890A246B268E114EC6EABA9B74D0DA47B5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A5B013D21EBFF323196282E802F4110ED8891F63FD86D96750F87CCE6106E1FC07E67D4AC08A07B9B0F254576263B31EA9CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D34A783A638E01A3CDE3639B0CB6E9DB9D9E3FF44F602B71B06131C911ACB7480EB780A3D111188FBD71D7E09C32AA3244C5CFD91C85515A918DBB9775CBFAC55A2795D98D676DD64D0ED9A463B7D0AAFF65DA084F8E80FEBD3202CD0F03380D9577A83BD0C44CE203720ABEDE4BBDD9CDD X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojNAMxVcV6vdU0Ix1KT4d4nA== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769E62CD0C1D75558122016D387473C641884876E3DC5E244DFDEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] test: introduce asserts assert_str{_not}_equal X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: Sergey Bronnikov , max.kokryashkin@gmail.com, tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for the fixes. Please, consider my comments below. On 10.11.23, Sergey Bronnikov wrote: > Hi, Igor > > On 11/1/23 11:28, Igor Munkin via Tarantool-patches wrote: > > Sergey, > > > > On 01.11.23, Sergey Kaplun via Tarantool-patches wrote: > >> Hi, Sergey! > > > > > >> 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 header. So the user can redefine it before the > >> `assert_str_{not_}equal()` and use a custom value. > >> > >> 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? > > What if the different part starts after 128 symbols? I believe the most > > valuable part is the one where the difference starts, so you have to > > dump the beginning (for convenience), the difference and some numeric > > parameters (length, offset where strings differ, etc). > > > > Furthermore, I suggest implementing <*_str_*> helpers for nul-terminated > > strings and <*_mem_*> helpers for length limited memory blobs. > I would postpone implementation of  <*_mem_*> helpers until we will need > them in tests. I'm totally OK with it. > > > >> 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. > > I believe, this is quite minor thing (at least for now). > > > > > > > >> -- > >> Best regards, > >> Sergey Kaplun 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 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. > + ASSERT_NOT_EQUAL_FMT(str, "%s"), \ > + __FILE__, __LINE__, (got), (unexpected) \ > + ); \ > +} while (0) > + > #endif /* TARANTOOL_LUAJIT_TEST_H */ -- Best regards, Sergey Kaplun