diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-02-16 19:42:05 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-02-18 19:19:03 +0100 |
commit | e72ecdb7ca1face1d16e622824aa7bd3c98f5673 (patch) | |
tree | 14aa6a8ed961ba7643a8c689f391107d009d8866 /test/helpers.lua | |
parent | 8b543d09d834994f7e696716ce8c146ab0652011 (diff) | |
download | rneovim-e72ecdb7ca1face1d16e622824aa7bd3c98f5673.tar.gz rneovim-e72ecdb7ca1face1d16e622824aa7bd3c98f5673.tar.bz2 rneovim-e72ecdb7ca1face1d16e622824aa7bd3c98f5673.zip |
test/util: expect_msg_seq()
job_spec.lua on AppVeyor (Windows) often fails like this:
FAILED ] C:/projects/neovim/test/functional\core\job_spec.lua @ 72: jobs changes to given `cwd` directory
C:/projects/neovim/test/functional\core\job_spec.lua:81: Expected objects to be the same.
Passed in:
(table) {
[1] = 'notification'
[2] = 'stdout'
*[3] = {
[1] = 0
*[2] = {
[1] = 'C:\projects\neovim\Xtest-tmpdir\nvimmSjq1S\0' } } }
Expected:
(table) {
[1] = 'notification'
[2] = 'stdout'
*[3] = {
[1] = 0
*[2] = {
[1] = 'C:\projects\neovim\Xtest-tmpdir\nvimmSjq1S\0'
*[2] = '' } } }
stack traceback:
Message chunking is non-deterministic, so we need to try different
variants.
Diffstat (limited to 'test/helpers.lua')
-rw-r--r-- | test/helpers.lua | 84 |
1 files changed, 62 insertions, 22 deletions
diff --git a/test/helpers.lua b/test/helpers.lua index 1c64f41b65..ee7dc5dfe5 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -7,13 +7,33 @@ local check_logs_useless_lines = { ['See README_MISSING_SYSCALL_OR_IOCTL for guidance']=3, } -local eq = function(exp, act) - return assert.are.same(exp, act) +local function eq(expected, actual) + return assert.are.same(expected, actual) end -local neq = function(exp, act) +-- Tries multiple accepted ("expected") values until one succeeds. +-- First N-1 arguments are the accepted values. +-- Last (Nth) argument is the "actual" value to be compared. +local function eq_any(...) + if select('#', ...) < 2 then + error('need at least 2 arguments') + end + local args = {...} + local actual = args[#args] + local final_error = '' + for anum = 1, select('#', ...) - 1 do + local accepted = args[anum] + local status, result = pcall(eq, accepted, actual) + if status then + return result + end + final_error = final_error..tostring(result) + end + error(final_error) +end +local function neq(exp, act) return assert.are_not.same(exp, act) end -local ok = function(res) +local function ok(res) return assert.is_true(res) end @@ -534,30 +554,50 @@ local function fixtbl_rec(tbl) return fixtbl(tbl) end +-- From https://github.com/premake/premake-core/blob/master/src/base/table.lua +local function table_flatten(arr) + local result = {} + local function _table_flatten(_arr) + local n = #_arr + for i = 1, n do + local v = _arr[i] + if type(v) == "table" then + _table_flatten(v) + elseif v then + table.insert(result, v) + end + end + end + _table_flatten(arr) + return result +end + return { - eq = eq, - neq = neq, - ok = ok, - check_logs = check_logs, - uname = uname, - tmpname = tmpname, - map = map, - filter = filter, - glob = glob, - check_cores = check_cores, - hasenv = hasenv, - which = which, - shallowcopy = shallowcopy, - deepcopy = deepcopy, - mergedicts_copy = mergedicts_copy, - dictdiff = dictdiff, REMOVE_THIS = REMOVE_THIS, + check_cores = check_cores, + check_logs = check_logs, concat_tables = concat_tables, dedent = dedent, + deepcopy = deepcopy, + dictdiff = dictdiff, + eq = eq, + eq_any = eq_any, + filter = filter, + fixtbl = fixtbl, + fixtbl_rec = fixtbl_rec, format_luav = format_luav, format_string = format_string, + glob = glob, + hasenv = hasenv, intchar2lua = intchar2lua, + map = map, + mergedicts_copy = mergedicts_copy, + neq = neq, + ok = ok, + shallowcopy = shallowcopy, + table_flatten = table_flatten, + tmpname = tmpname, + uname = uname, updated = updated, - fixtbl = fixtbl, - fixtbl_rec = fixtbl_rec, + which = which, } |