[Tarantool-patches] [PATCH luajit 1/3] test: fix path storage for non-concatable objects

sergos sergos at tarantool.org
Mon Sep 20 12:37:43 MSK 2021


Thanks for explanation! 

LGTM.

Sergos

> On 20 Sep 2021, at 11:28, Sergey Kaplun <skaplun at tarantool.org> wrote:
> 
> Hi, Sergos!
> 
> Thanks for the review!
> 
> On 15.09.21, sergos wrote:
>> Hi!
>> Thanks for the patch!
>> 
>>> On 9 Sep 2021, at 10:03, Sergey Kaplun <skaplun at tarantool.org <mailto:skaplun at tarantool.org>> wrote:
>>> 
>>> When the key of a table to compare via `tap.test:is_deeply()` is
>>> non-concatable object (i.e. lightuserdata) concatenation with path
>>  ^^^^ does it mean the object has no __concat, while has __tostring?
>> 
>> As a result: is there a case an object has no __tostring?
> 
> Yes, for example, userdata may have no neither __tostring, nor __concat
> metamethod, but tostring() will show us its value and prevent raising an
> error.
> 
> | luajit -e 'print(getmetatable(newproxy(true)).__tostring, getmetatable(newproxy(true)).__concat); local r = "ud: "..tostring(newproxy()) print(r)'
> | nil     nil
> | ud: userdata: 0x41edce48
> 
>> 
>>> raises an error.
>>> 
>>> This patch converts object to string to avoid this error.
>>> 
>>> Needed for tarantool/tarantool#5629
>>> ---
>>> test/tarantool-tests/tap.lua | 4 ++--
>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>> 
>>> diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
>>> index 44fcac3d..a1f54d20 100644
>>> --- a/test/tarantool-tests/tap.lua
>>> +++ b/test/tarantool-tests/tap.lua
>>> @@ -166,7 +166,7 @@ local function is_deeply(test, got, expected, message, extra)
>>> 
>>>    for k, v in pairs(got) do
>>>      has[k] = true
>>> -      extra.path = path .. "." .. k
>>> +      extra.path = path .. "." .. tostring(k)
>>>      if not cmpdeeply(v, expected[k], extra) then
>>>        return false
>>>      end
>>> @@ -175,7 +175,7 @@ local function is_deeply(test, got, expected, message, extra)
>>>    -- Check if expected contains more keys then got.
>>>    for k, v in pairs(expected) do
>>>      if has[k] ~= true and (extra.strict or v ~= NULL) then
>>> -        extra.path = path .. "." .. k
>>> +        extra.path = path .. "." .. tostring(k)
>>>        extra.expected = "key (exists): " ..  tostring(k)
>>>        extra.got = "key (missing): " .. tostring(k)
>>>        return false
>>> -- 
>>> 2.31.0
>>> 
>> 
> 
> -- 
> Best regards,
> Sergey Kaplun

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.tarantool.org/pipermail/tarantool-patches/attachments/20210920/be3e91c1/attachment.htm>


More information about the Tarantool-patches mailing list