@@ -411,15 +411,22 @@ function M.assert_items_include(actual, expected, message)
411
411
end
412
412
end
413
413
414
- local function table_covers (actual , expected )
415
- if type (actual ) ~= ' table' or type (expected ) ~= ' table' then
416
- failure ( ' Argument 1 and 2 must be tables ' , nil , 3 )
414
+ local function table_slice (actual , expected )
415
+ if type (expected ) ~= ' table' or type (actual ) ~= ' table' then
416
+ return actual
417
417
end
418
418
local sliced = {}
419
419
for k , _ in pairs (expected ) do
420
- sliced [k ] = actual [k ]
420
+ sliced [k ] = table_slice ( actual [k ], expected [ k ])
421
421
end
422
- return comparator .equals (sliced , expected )
422
+ return sliced
423
+ end
424
+
425
+ local function table_covers (actual , expected )
426
+ if type (actual ) ~= ' table' or type (expected ) ~= ' table' then
427
+ failure (' Argument 1 and 2 must be tables' , nil , 3 )
428
+ end
429
+ return comparator .equals (table_slice (actual , expected ), expected )
423
430
end
424
431
425
432
--- Checks that actual map includes expected one.
@@ -663,20 +670,6 @@ local function error_unpack(err)
663
670
return unpacked
664
671
end
665
672
666
- -- Return table with keys from expected but values from actual. Apply
667
- -- same changes recursively for key 'prev'.
668
- local function error_slice (actual , expected )
669
- if type (expected ) ~= ' table' or type (actual ) ~= ' table' then
670
- return actual
671
- end
672
- local sliced = {}
673
- for k , _ in pairs (expected ) do
674
- sliced [k ] = actual [k ]
675
- end
676
- sliced .prev = error_slice (sliced .prev , expected .prev )
677
- return sliced
678
- end
679
-
680
673
--- Checks that error raised by function is table that includes expected one.
681
674
--- box.error is unpacked to convert to table. Stacked errors are supported.
682
675
--- That is if there is prev field in expected then it should cover prev field
@@ -693,7 +686,7 @@ function M.assert_error_covers(expected, fn, ...)
693
686
prettystr (actual ), prettystr (expected ))
694
687
end
695
688
local unpacked = error_unpack (actual )
696
- if not comparator .equals (error_slice (unpacked , expected ), expected ) then
689
+ if not comparator .equals (table_slice (unpacked , expected ), expected ) then
697
690
actual , expected = prettystr_pairs (unpacked , expected )
698
691
fail_fmt (2 , nil , ' Error expected: %s\n Error received: %s' ,
699
692
expected , actual )
0 commit comments