aboutsummaryrefslogtreecommitdiff
path: root/test/functional/helpers.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-02-16 19:42:05 +0100
committerJustin M. Keyes <justinkz@gmail.com>2018-02-18 19:19:03 +0100
commite72ecdb7ca1face1d16e622824aa7bd3c98f5673 (patch)
tree14aa6a8ed961ba7643a8c689f391107d009d8866 /test/functional/helpers.lua
parent8b543d09d834994f7e696716ce8c146ab0652011 (diff)
downloadrneovim-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/functional/helpers.lua')
-rw-r--r--test/functional/helpers.lua163
1 files changed, 104 insertions, 59 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index f0e47481da..3f3cdb56ba 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -14,10 +14,12 @@ local check_cores = global_helpers.check_cores
local check_logs = global_helpers.check_logs
local neq = global_helpers.neq
local eq = global_helpers.eq
+local eq_any = global_helpers.eq_any
local ok = global_helpers.ok
local map = global_helpers.map
local filter = global_helpers.filter
local dedent = global_helpers.dedent
+local table_flatten = global_helpers.table_flatten
local start_dir = lfs.currentdir()
-- XXX: NVIM_PROG takes precedence, QuickBuild sets it.
@@ -96,8 +98,8 @@ local function request(method, ...)
return rv
end
-local function next_message()
- return session:next_message()
+local function next_message(timeout)
+ return session:next_message(timeout)
end
local function expect_twostreams(msgs1, msgs2)
@@ -116,6 +118,46 @@ local function expect_twostreams(msgs1, msgs2)
end
end
+-- Expects a sequence of next_message() results. If multiple sequences are
+-- passed they are tried until one succeeds, in order of shortest to longest.
+local function expect_msg_seq(...)
+ if select('#', ...) < 1 then
+ error('need at least 1 argument')
+ end
+ local seqs = {...}
+ table.sort(seqs, function(a, b) -- Sort ascending, by (shallow) length.
+ return #a < #b
+ end)
+
+ local actual_seq = {}
+ local final_error = ''
+ local function cat_err(err1, err2)
+ if err1 == nil then
+ return err2
+ end
+ return string.format('%s\n%s\n%s', err1, string.rep('=', 78), err2)
+ end
+ for anum = 1, #seqs do
+ local expected_seq = seqs[anum]
+ -- Collect enough messages to compare the next expected sequence.
+ while #actual_seq < #expected_seq do
+ local msg = next_message(10000) -- Big timeout for ASAN/valgrind.
+ if msg == nil then
+ error(cat_err(final_error,
+ string.format('got %d messages, expected %d',
+ #actual_seq, #expected_seq)))
+ end
+ table.insert(actual_seq, msg)
+ end
+ local status, result = pcall(eq, expected_seq, actual_seq)
+ if status then
+ return result
+ end
+ final_error = cat_err(final_error, result)
+ end
+ error(final_error)
+end
+
local function call_and_stop_on_error(...)
local status, result = copcall(...) -- luacheck: ignore
if not status then
@@ -674,78 +716,81 @@ local function hexdump(str)
end
local module = {
- prepend_argv = prepend_argv,
+ NIL = mpack.NIL,
+ alter_slashes = alter_slashes,
+ buffer = buffer,
+ bufmeths = bufmeths,
+ call = nvim_call,
clear = clear,
+ command = nvim_command,
connect = connect,
- retry = retry,
- spawn = spawn,
+ curbuf = curbuf,
+ curbuf_contents = curbuf_contents,
+ curbufmeths = curbufmeths,
+ curtab = curtab,
+ curtabmeths = curtabmeths,
+ curwin = curwin,
+ curwinmeths = curwinmeths,
dedent = dedent,
- source = source,
- rawfeed = rawfeed,
- insert = insert,
- iswin = iswin,
- feed = feed,
- feed_command = feed_command,
- eval = nvim_eval,
- call = nvim_call,
- command = nvim_command,
- request = request,
- next_message = next_message,
- expect_twostreams = expect_twostreams,
- run = run,
- stop = stop,
eq = eq,
- neq = neq,
+ eq_any = eq_any,
+ eval = nvim_eval,
+ exc_exec = exc_exec,
expect = expect,
expect_any = expect_any,
- ok = ok,
- map = map,
+ expect_msg_seq = expect_msg_seq,
+ expect_twostreams = expect_twostreams,
+ feed = feed,
+ feed_command = feed_command,
filter = filter,
+ funcs = funcs,
+ get_pathsep = get_pathsep,
+ hexdump = hexdump,
+ insert = insert,
+ iswin = iswin,
+ map = map,
+ merge_args = merge_args,
+ meth_pcall = meth_pcall,
+ meths = meths,
+ missing_provider = missing_provider,
+ mkdir = lfs.mkdir,
+ neq = neq,
+ new_pipename = new_pipename,
+ next_message = next_message,
nvim = nvim,
+ nvim_argv = nvim_argv,
nvim_async = nvim_async,
+ nvim_dir = nvim_dir,
nvim_prog = nvim_prog,
- nvim_argv = nvim_argv,
nvim_set = nvim_set,
- nvim_dir = nvim_dir,
- buffer = buffer,
- window = window,
- tabpage = tabpage,
- curbuf = curbuf,
- curwin = curwin,
- curtab = curtab,
- curbuf_contents = curbuf_contents,
- wait = wait,
- sleep = sleep,
- set_session = set_session,
- write_file = write_file,
- read_file = read_file,
+ ok = ok,
os_name = os_name,
- rmdir = rmdir,
- mkdir = lfs.mkdir,
- exc_exec = exc_exec,
- redir_exec = redir_exec,
- merge_args = merge_args,
- funcs = funcs,
- meths = meths,
- bufmeths = bufmeths,
- winmeths = winmeths,
- tabmeths = tabmeths,
- uimeths = uimeths,
- curbufmeths = curbufmeths,
- curwinmeths = curwinmeths,
- curtabmeths = curtabmeths,
+ pathroot = pathroot,
pending_win32 = pending_win32,
- skip_fragile = skip_fragile,
+ prepend_argv = prepend_argv,
+ rawfeed = rawfeed,
+ read_file = read_file,
+ redir_exec = redir_exec,
+ request = request,
+ retry = retry,
+ rmdir = rmdir,
+ run = run,
+ set_session = set_session,
set_shell_powershell = set_shell_powershell,
+ skip_fragile = skip_fragile,
+ sleep = sleep,
+ source = source,
+ spawn = spawn,
+ stop = stop,
+ table_flatten = table_flatten,
+ tabmeths = tabmeths,
+ tabpage = tabpage,
tmpname = tmpname,
- meth_pcall = meth_pcall,
- NIL = mpack.NIL,
- get_pathsep = get_pathsep,
- pathroot = pathroot,
- missing_provider = missing_provider,
- alter_slashes = alter_slashes,
- hexdump = hexdump,
- new_pipename = new_pipename,
+ uimeths = uimeths,
+ wait = wait,
+ window = window,
+ winmeths = winmeths,
+ write_file = write_file,
}
return function(after_each)