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 BFF626D9DC3; Wed, 15 Nov 2023 12:32:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BFF626D9DC3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1700040760; bh=zXyrXWAyx6QbTHeqNZmrFwV3l0l0nHUpPdUzOfdzLIE=; 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=LADAR0EjlnW2KCQ5ebUsWTSn6MiLrstu2KJT9O4u5EvpVjvKgKynHZzN313k21B72 56ee40BJQ77gPIkCi5CshO/irTLQx74UxAcVx+W8ysADA77PGBrf5Jg86TX74oerNC jvCDdlciff1Rjmx+Wl0OPnouQf0of0ID3BbV+sDQ= Received: from smtp37.i.mail.ru (smtp37.i.mail.ru [95.163.41.78]) (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 E20BB68CAE9 for ; Wed, 15 Nov 2023 12:32:38 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E20BB68CAE9 Received: by smtp37.i.mail.ru with esmtpa (envelope-from ) id 1r3CGC-001dvc-1d; Wed, 15 Nov 2023 12:32:37 +0300 Message-ID: Date: Wed, 15 Nov 2023 12:32:36 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Sergey Kaplun References: <639a0c42-13a6-4a2e-ac4f-6077b89ff6fe@tarantool.org> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9C2A6B03AB739174C6E86FCE1CC902D40CD6F1F1BD9F1501500894C459B0CD1B901E88D702EE1DA45449E597DDEA594A37D7D2B80D35BF41D11835EED5C149C5A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE73F300A97FDD4E158EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006379EF8ECDDDA8246E28638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D87B8F9BF34B2805298D0EE3B32DA9022A117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC5FC25ED3FCEC3375A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751FF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947CF8BD4E506CFA3D88BA3038C0950A5D36C8A9BA7A39EFB766D91E3A1F190DE8FDBA3038C0950A5D36D5E8D9A59859A8B6EC9D17400D4640693AA81AA40904B5D99C9F4D5AE37F343AD1F44FA8B9022EA23BBE47FD9DD3FB595F5C1EE8F4F765FC60CDF180582EB8FBE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B426E46268278306375ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A50A1F36410B0E4601317D9278CB83E6ADC6CF5357FD83DF48F87CCE6106E1FC07E67D4AC08A07B9B086D40F53BA192295CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFEAE86F2716330A4952F3C9516274DCD2964EFBEA440B036A39AA57BF99F4113C500AA17B1AA25A4F8AC21204250FC4D0138A1B9BE54097FCDF333B5FF0051EE9461A413F07889F2102C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojqFo78WLxrjFK48I/S8yW4A== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A76916A7974E3DAB9A8C60E99110D8B4E39BC9F871340C5A6C40EBA65886582A37BD66FEC6BF5C9C28D98A98C1125256619760D574B6FC815AB872D6B4FCE48DF648AE208404248635DF 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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Cc: Sergey Bronnikov , max.kokryashkin@gmail.com, tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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,    \                 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 */