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 62555711CF4; Sat, 18 Nov 2023 19:40:59 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 62555711CF4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1700325659; bh=EODS2+PeS95lZfvaw2X42wNr2prav/byApKrBTonJCA=; 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=YQunNBTmVz1N5LQyVecL3Q8QSsv/Ec6pwJ5gy8eBHU/HTKXE02hQwWYrBGiGCcd6j OaQZCAA15terylf1uJAv6Wez1IuyrD1qOM2UYrWtfYZ7ciKlZoDvHO9FrRDg6ayk+g 8OV7B70kg9M/7/ogx8IAPUzQRTBBPJ5+CqsStggA= Received: from smtp49.i.mail.ru (smtp49.i.mail.ru [95.163.41.91]) (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 2B87D6EFDF3 for ; Sat, 18 Nov 2023 19:40:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2B87D6EFDF3 Received: by smtp49.i.mail.ru with esmtpa (envelope-from ) id 1r4ONM-00E6CD-30; Sat, 18 Nov 2023 19:40:57 +0300 Content-Type: multipart/alternative; boundary="------------5XMaLhexrlhY6bMFXwFd00BR" Message-ID: <6bbe0451-345a-40fe-9387-1e107f7a3ba9@tarantool.org> Date: Sat, 18 Nov 2023 19:40:56 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun References: <639a0c42-13a6-4a2e-ac4f-6077b89ff6fe@tarantool.org> In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9BE2AA157F04678487A33E32BE3FBF935015569BDBD2A1B54182A05F5380850404C228DA9ACA6FE270B3840151A0D8D3701BADA8DDA4C9FE5FC91236B8B11383264135331CBC963C2 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A3295C83650092F9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063794BAA5DA89D799D78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8A0C0EAFC3F6F2263C282FA94A3256BD9117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC00AB816903775DDCA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10F2CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE140C956E756FBB7A4DC33E588678F033D8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE365B78C30F681404DC0837EA9F3D19764C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB861051D4BA689FC2E808ACE2090B5E1725E5C173C3A84C317B107DEF921CE79089D37D7C0E48F6C8AA50765F79006372C56F9BC9525AE6AEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A508019C648AFF2926099253AF1EDF3EC58B81E981850A5325F87CCE6106E1FC07E67D4AC08A07B9B0F254576263B31EA9CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF0618313B0C5D757685A1763FF03B0489B373AB0CB2FDED384866D00556465229A7825560E8A5912CFCC135EDF961F15FBE51659A298DA8FEEA01BD36B817BD69461A413F07889F2102C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojQSTOZvjxQBVgAWp3YM42Vg== X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F2588458B66E8D253454E0B6DBC9DDAA9808D70690C8A40EF5FCDEA9282EC151BADDC1D3523A6D01B4765B2DFB59E2DDD9FE06B14FA522850F29BC30B0DAF586E7D11B3E67EA787935ED9F1B 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" This is a multi-part message in MIME format. --------------5XMaLhexrlhY6bMFXwFd00BR Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello, On 11/16/23 11:02, Sergey Kaplun wrote: >> 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. Updated. diff --git a/test/tarantool-c-tests/test.h b/test/tarantool-c-tests/test.h index 5e5c96b2..3b22fb92 100644 --- a/test/tarantool-c-tests/test.h +++ b/test/tarantool-c-tests/test.h @@ -213,14 +213,14 @@ static inline int todo(const char *reason)  } while (0)  #define assert_str_equal(got, expected) do {                           \ -       assert_general(strncmp(got, expected, strlen(expected)) == 0,   \ +       assert_general(strcmp(got, expected) == 0,                      \                        ASSERT_EQUAL_FMT(str, "%s"),                     \                        __FILE__, __LINE__, (got), (expected)            \ );                                                              \  } while (0)  #define assert_str_not_equal(got, unexpected) do {                     \ -       assert_general(strncmp(got, expected, strlen(expected)) != 0,   \ +       assert_general(strcmp(got, expected) != 0,                      \                        ASSERT_NOT_EQUAL_FMT(str, "%s"),                 \                        __FILE__, __LINE__, (got), (unexpected)          \ );                                                              \ > >>                 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. 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 */ --------------5XMaLhexrlhY6bMFXwFd00BR Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hello,


On 11/16/23 11:02, Sergey Kaplun wrote:


<snipped>

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.


Updated.

diff --git a/test/tarantool-c-tests/test.h b/test/tarantool-c-tests/test.h
index 5e5c96b2..3b22fb92 100644
--- a/test/tarantool-c-tests/test.h
+++ b/test/tarantool-c-tests/test.h
@@ -213,14 +213,14 @@ static inline int todo(const char *reason)
 } while (0)
 
 #define assert_str_equal(got, expected) do {                           \
-       assert_general(strncmp(got, expected, strlen(expected)) == 0,   \
+       assert_general(strcmp(got, expected) == 0,                      \
                       ASSERT_EQUAL_FMT(str, "%s"),                     \
                       __FILE__, __LINE__, (got), (expected)            \
        );                                                              \
 } while (0)
 
 #define assert_str_not_equal(got, unexpected) do {                     \
-       assert_general(strncmp(got, expected, strlen(expected)) != 0,   \
+       assert_general(strcmp(got, expected) != 0,                      \
                       ASSERT_NOT_EQUAL_FMT(str, "%s"),                 \
                       __FILE__, __LINE__, (got), (unexpected)          \
        );                                                              \


    


                 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.
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 */

    
--------------5XMaLhexrlhY6bMFXwFd00BR--