Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org, v.shpilevoy@tarantool.org
Subject: [tarantool-patches] Re: [PATCH v1 1/1] tap: fix is_deeply box.NULL corner cases
Date: Tue, 23 Apr 2019 17:12:15 +0300	[thread overview]
Message-ID: <c64b2f43-dcd3-9674-0d58-f9721f16a11e@tarantool.org> (raw)
In-Reply-To: <b6785b2cba8a866bf3574efad039a4c47cf51798.1556024070.git.kshcherbatov@tarantool.org>

explicit is better than implicit, yep

- if visited_keys[i] ~= true and v ~= nil then
+ if visited_keys[i] ~= true and v ~= box.NULL then

===========================================

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
---
 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..e48adbbab 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 ~= box.NULL 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

  reply	other threads:[~2019-04-23 14:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-23 12:55 [tarantool-patches] " Kirill Shcherbatov
2019-04-23 14:12 ` Kirill Shcherbatov [this message]
2019-04-23 14:14   ` [tarantool-patches] " Vladislav Shpilevoy
2019-04-24  9:37 ` [tarantool-patches] [PATCH v2 " Kirill Shcherbatov
2019-04-24 11:23   ` [tarantool-patches] " Vladislav Shpilevoy
2019-04-24 11:56     ` Kirill Shcherbatov
2019-04-24 12:01       ` Vladislav Shpilevoy
2019-04-24 11:57   ` Alexander Turenko
2019-04-24 12:02     ` Vladislav Shpilevoy
2019-04-24 12:14       ` Alexander Turenko
2019-04-25 10:29 ` [tarantool-patches] Re: [PATCH v1 " Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c64b2f43-dcd3-9674-0d58-f9721f16a11e@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='[tarantool-patches] Re: [PATCH v1 1/1] tap: fix is_deeply box.NULL corner cases' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox