From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 33F5D2B14B for ; Tue, 23 Apr 2019 08:55:44 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9jl_Ac7Op5zC for ; Tue, 23 Apr 2019 08:55:44 -0400 (EDT) Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [217.69.128.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 7EB432B0AC for ; Tue, 23 Apr 2019 08:55:43 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v1 1/1] tap: fix is_deeply box.NULL corner cases Date: Tue, 23 Apr 2019 15:55:39 +0300 Message-Id: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org, v.shpilevoy@tarantool.org Cc: Kirill Shcherbatov The tap:is_deeply call used to return inconsistent result processing an empty tuple and tuple that has no values: is_deeply({a = box.NULL}, {}) == true is_deeply({}, {a = box.NULL}) == false Fixed to return true in such case. We shouldn't return false in such case because of marshaling features covered by tests: is_deeply(decode(encode(t)), t) must be true for all t, including t = nil; decode(encode(nil)) == box.NULL. Closes #4125 --- Branch: http://github.com/tarantool/tarantool/tree/kshch/gh-4125-inconsistent-isdeeply-results Issue: https://github.com/tarantool/tarantool/issues/4125 src/lua/tap.lua | 4 ++-- test/app-tap/tap.result | 8 ++++++-- test/app-tap/tap.test.lua | 10 +++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/lua/tap.lua b/src/lua/tap.lua index 546d15392..4f214ba52 100644 --- a/src/lua/tap.lua +++ b/src/lua/tap.lua @@ -117,8 +117,8 @@ local function cmpdeeply(got, expected, extra) end -- check if expected contains more keys then got - for i, _ in pairs(expected) do - if visited_keys[i] ~= true then + for i, v in pairs(expected) do + if visited_keys[i] ~= true and v ~= nil then extra.expected = 'key ' .. tostring(i) extra.got = 'nil' return false diff --git a/test/app-tap/tap.result b/test/app-tap/tap.result index 3e7882331..dced9a5a2 100644 --- a/test/app-tap/tap.result +++ b/test/app-tap/tap.result @@ -119,7 +119,7 @@ not ok - failed subtests failed: 1 ... # is_deeply - 1..6 + 1..10 ok - 1 and 1 ok - abc and abc ok - empty tables @@ -136,10 +136,14 @@ not ok - failed subtests expected: 5 got: 4 ... + ok - {} and {a = nil} + ok - {a = nil} and {} + ok - {a = nil} and {b = nil} + ok - {a = nil} and {b = nil, c = nil} # is_deeply: end not ok - failed subtests --- - planned: 6 + planned: 10 failed: 2 ... # like diff --git a/test/app-tap/tap.test.lua b/test/app-tap/tap.test.lua index 0e1de7f1c..c0593db46 100755 --- a/test/app-tap/tap.test.lua +++ b/test/app-tap/tap.test.lua @@ -118,7 +118,7 @@ end) test:test('is_deeply', function(t) - t:plan(6) + t:plan(10) t:is_deeply(1, 1, '1 and 1') t:is_deeply('abc', 'abc', 'abc and abc') @@ -127,6 +127,14 @@ test:test('is_deeply', function(t) t:is_deeply({1}, {2}, '{1} and {2}') t:is_deeply({1, 2, { 3, 4 }}, {1, 2, { 3, 5 }}, '{1,2,{3,4}} and {1,2,{3,5}}') + -- + -- gh-4125: is_deeply inconsistently works with box.NULL. + -- + t:is_deeply({}, {a = box.NULL}, '{} and {a = nil}') + t:is_deeply({a = box.NULL}, {}, '{a = nil} and {}') + t:is_deeply({a = box.NULL}, {b = box.NULL}, '{a = nil} and {b = nil}') + t:is_deeply({a = box.NULL}, {b = box.NULL, c = box.NULL}, + '{a = nil} and {b = nil, c = nil}') end) -- 2.21.0