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 183D88024B1; Thu, 16 Nov 2023 11:06:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 183D88024B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1700122018; bh=ikZbuUGYlEnLQYCkIIVPLoylbdMMduysVlcCxPFESeY=; 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=cw0oE+nk/PcKuxxt4SFUfdl6RJyENzuvXjZoWi9L0yYSQ2/a8ccjk6Df0q4b8ASfR 4TaUlGQLtUoSgBjr97fgg0udO13eYgJ8LJwMmPjY9lD7RYfmb4O/3JQj+AZf+pXQwb ORzXuncWXp3F7pGWy3H4RfVNvq6tRAZS8u1tl7es= Received: from smtp43.i.mail.ru (smtp43.i.mail.ru [95.163.41.66]) (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 024B51B7EEE for ; Thu, 16 Nov 2023 11:06:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 024B51B7EEE Received: by smtp43.i.mail.ru with esmtpa (envelope-from ) id 1r3XOo-00H0M6-37; Thu, 16 Nov 2023 11:06:55 +0300 Date: Thu, 16 Nov 2023 11:02:22 +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: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9C2A6B03AB739174C98C7DD0DF98556B608BBEEF2999C341400894C459B0CD1B93D519C22EAB52BD3C52498C8173549F83D2312D2B9B5A3BB599FBF3E6EA3F319 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B114C2C2C20B7E62EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637737629E79DA7E02D8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D89E8E63BDB7EEA17DD48F08A0AF5B3D00117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC3733B5EC72352B9FA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18E5D25F19253116ADD2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE437C869540D2AB0F148812EF9080FC94D8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE3DA532D2019E286A79735652A29929C6CC4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947C989FD0BDF65E50FB2E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89FD2A95C73FD1EFF45A91E23F1B6B78B78B5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A58416DB0A9570DF6EA75599D1268C171DFC7F46EFFC1FFB31F87CCE6106E1FC07E67D4AC08A07B9B05E3BF8C76DC23F74CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF4E5CA5446A8D067DC578BBB95C92DDB773096D4DC6C8562A67AF75DDC188333A498A0925D89034508AC21204250FC4D06E46EECEB8CDEFBC992A71653342A171461A413F07889F2102C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojUgnpwJ++SjSN6lBoWHcjPA== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A7690BC50C7AAB6B145B2A4F09EBD08ABE2A49EBE2174CCC9479DEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF 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! LGTM, after fixing my comment below. On 15.11.23, Sergey Bronnikov wrote: > Hello, Sergey > > On 11/14/23 11:55, Sergey Kaplun wrote: > > > > > > 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. > > 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,    \ On the second thought, I insist on using `strcmp()` here since the expected string is always `\0` terminated, and we use "not safe" the `strlen()` anyway. >                 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,    \ Ditto. >                 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 */ -- Best regards, Sergey Kaplun