fix test_dir param and allow userdata in table_eq

develop
myk002 2021-03-06 05:02:05 -08:00
parent 6a95308123
commit 4779dd678d
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
2 changed files with 7 additions and 3 deletions

@ -37,7 +37,7 @@ local done_command = utils.processArgsGetopt({...}, {
{'h', 'help', handler=function() help = true end}, {'h', 'help', handler=function() help = true end},
{'n', 'nocache', handler=function() nocache = true end}, {'n', 'nocache', handler=function() nocache = true end},
{'d', 'test_dir', hasArg=true, {'d', 'test_dir', hasArg=true,
handler=function(arg) mode_filter = arg:split(',') end}, handler=function(arg) test_dir = arg end},
{'m', 'modes', hasArg=true, {'m', 'modes', hasArg=true,
handler=function(arg) mode_filter = arg:split(',') end}, handler=function(arg) mode_filter = arg:split(',') end},
{'t', 'tests', hasArg=true, {'t', 'tests', hasArg=true,
@ -127,8 +127,9 @@ local function table_eq_recurse(a, b, keys, known_eq)
return true return true
end end
function expect.table_eq(a, b, comment) function expect.table_eq(a, b, comment)
if type(a) ~= 'table' or type(b) ~= 'table' then if (type(a) ~= 'table' and type(a) ~= 'userdata') or
return false, comment, 'both operands to table_eq must be tables' (type(b) ~= 'table' and type(b) ~= 'userdata') then
return false, comment, 'operands to table_eq must be tables or userdata'
end end
local keys, known_eq = {}, {} local keys, known_eq = {}, {}
local matched, keys_at_diff, diff = table_eq_recurse(a, b, keys, known_eq) local matched, keys_at_diff, diff = table_eq_recurse(a, b, keys, known_eq)

@ -8,6 +8,9 @@ function test.table_eq()
expect.true_(expect_raw.table_eq({{'a', k='val'}, 'b'}, expect.true_(expect_raw.table_eq({{'a', k='val'}, 'b'},
{{'a', k='val'}, 'b'})) {{'a', k='val'}, 'b'}))
expect.false_(expect_raw.table_eq(nil, nil)) -- operands must be non-nil
expect.false_(expect_raw.table_eq({}, nil))
expect.false_(expect_raw.table_eq(nil, {}))
expect.false_(expect_raw.table_eq({}, {''})) expect.false_(expect_raw.table_eq({}, {''}))
expect.false_(expect_raw.table_eq({''}, {})) expect.false_(expect_raw.table_eq({''}, {}))
expect.false_(expect_raw.table_eq({'a', {}}, {'a'})) expect.false_(expect_raw.table_eq({'a', {}}, {'a'}))