@@ -411,15 +411,22 @@ function M.assert_items_include(actual, expected, message)
411411 end
412412end
413413
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
417417 end
418418 local sliced = {}
419419 for k , _ in pairs (expected ) do
420- sliced [k ] = actual [k ]
420+ sliced [k ] = table_slice ( actual [k ], expected [ k ])
421421 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 )
423430end
424431
425432--- Checks that actual map includes expected one.
@@ -663,20 +670,6 @@ local function error_unpack(err)
663670 return unpacked
664671end
665672
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-
680673--- Checks that error raised by function is table that includes expected one.
681674--- box.error is unpacked to convert to table. Stacked errors are supported.
682675--- 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, ...)
693686 prettystr (actual ), prettystr (expected ))
694687 end
695688 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
697690 actual , expected = prettystr_pairs (unpacked , expected )
698691 fail_fmt (2 , nil , ' Error expected: %s\n Error received: %s' ,
699692 expected , actual )
0 commit comments