Skip to content

Commit 53ec103

Browse files
committed
Make assert_covers check array items for coverage
Treating arrays as maps in `assert_covers` is error-prone so we fixed it in commit 95a1c3f ("Fix `assert_covers` treat arrays as maps"), but we did it over-zealously - now arrays are treated just like scalars (numbers, for example). This breaks the case when array items are supposed to be checked for coverage for example: ```lua t.assert_covers({ {a = 1, b = 10}, {a = 2, b = 20}, {a = 3, b = 30}, }, {{a = 1}, {a = 2}, {a = 3}}) ``` Fix this. Follow-up #405 Closes #439
1 parent 731ba6f commit 53ec103

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Fixed a bug when `assert_covers` didn't check array items for coverage and
6+
instead treated arrays as scalars (gh-439).
7+
38
## 1.3.0
49

510
- Fixed a bug when `assert_covers` treats arrays as maps (gh-405).

luatest/assertions.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,12 @@ local function table_slice(actual, expected)
443443
if type(expected) ~= 'table' or type(actual) ~= 'table' then
444444
return actual
445445
end
446-
446+
local sliced
447447
if utils.table_is_array(actual) or utils.table_is_array(expected) then
448-
return actual
448+
sliced = table.copy(actual)
449+
else
450+
sliced = {}
449451
end
450-
451-
local sliced = {}
452452
for k, _ in pairs(expected) do
453453
sliced[k] = table_slice(actual[k], expected[k])
454454
end

test/luatest_test.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ g.test_assert_covers = function()
113113
subject({a = box.NULL}, {a = box.NULL})
114114
subject({a = box.tuple.new({1})}, {a = box.tuple.new({1})})
115115
subject({1, 2}, {1, 2})
116+
subject({{a = 1, b = 10}, {a = 2, b = 20}, {a = 3, b = 30}}, {{a = 1}, {a = 2}, {a = 3}})
117+
subject({x = {{a = 1, b = 10}, {a = 2, b = 20}}, y = {}}, {x = {{a = 1}, {a = 2}}})
116118
subject({[0] = 'zero', [1] = 'one'}, {[0] = 'zero'})
117119

118120
helper.assert_failure(subject, {a = 1, b = 2, c = 3}, {a = 2})
@@ -123,6 +125,9 @@ g.test_assert_covers = function()
123125
helper.assert_failure(subject, {a = {b = 1, c = 2}}, {a = {b = 1, c = 2, d = 3}})
124126
helper.assert_failure(subject, {1, 2}, {})
125127
helper.assert_failure(subject, {1, 2, 3}, {1, 2})
128+
helper.assert_failure(subject, {{a = 1, b = 10}, {a = 2, b = 20}}, {{a = 1}})
129+
helper.assert_failure(subject, {{a = 1, b = 10}, {a = 2, b = 20}}, {{a = 1}, {a = 2}, {a = 3}})
130+
helper.assert_failure(subject, {1, 2}, {nil, 2})
126131
helper.assert_failure(subject, {1, 2, foo = 'bar'}, {1, 2})
127132
helper.assert_failure(subject, {a = {1, 2, 3}}, {a = {1, 2}})
128133
helper.assert_failure(subject, {a = {1, 2}}, {a = {}})

0 commit comments

Comments
 (0)