diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2020-02-16 23:02:23 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-16 23:02:23 -0800 |
commit | 0c5d2ffebe92e710ca57d4e3f0b0789ccc369660 (patch) | |
tree | 5d94ed3b0b007f4cd966d956f5cde241a8735b83 /test/helpers.lua | |
parent | a1d6c2f5c9e7834ec6eb087b72354a1257582f3d (diff) | |
parent | 6e13b9d26134210f0963341bd77c64a4437f37ec (diff) | |
download | rneovim-0c5d2ffebe92e710ca57d4e3f0b0789ccc369660.tar.gz rneovim-0c5d2ffebe92e710ca57d4e3f0b0789ccc369660.tar.bz2 rneovim-0c5d2ffebe92e710ca57d4e3f0b0789ccc369660.zip |
Merge #11837 'LSP: fixes, improve test visibility'
Diffstat (limited to 'test/helpers.lua')
-rw-r--r-- | test/helpers.lua | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/test/helpers.lua b/test/helpers.lua index 98f003f208..a31a7733bf 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -58,6 +58,14 @@ local check_logs_useless_lines = { function module.eq(expected, actual, context) return assert.are.same(expected, actual, context) end +-- Like eq(), but includes tail of `logfile` in failure message. +function module.eq_dumplog(logfile, expected, actual, context) + local status, rv = pcall(module.eq, expected, actual, context) + if not status then + local logtail = module.read_nvim_log(logfile) + error(string.format('%s\n%s', rv, logtail)) + end +end function module.neq(expected, actual, context) return assert.are_not.same(expected, actual, context) end @@ -74,6 +82,22 @@ function module.matches(pat, actual) error(string.format('Pattern does not match.\nPattern:\n%s\nActual:\n%s', pat, actual)) end +--- Asserts that `pat` matches one or more lines in the tail of $NVIM_LOG_FILE. +--- +--@param pat (string) Lua pattern to search for in the log file. +--@param logfile (string, default=$NVIM_LOG_FILE) full path to log file. +function module.assert_log(pat, logfile) + logfile = logfile or os.getenv('NVIM_LOG_FILE') or '.nvimlog' + local nrlines = 10 + local lines = module.read_file_list(logfile, -nrlines) or {} + for _,line in ipairs(lines) do + if line:match(pat) then return end + end + local logtail = module.read_nvim_log(logfile) + error(string.format('Pattern %q not found in log (last %d lines): %s:\n%s', + pat, nrlines, logfile, logtail)) +end + -- Invokes `fn` and returns the error string (may truncate full paths), or -- raises an error if `fn` succeeds. -- @@ -737,10 +761,10 @@ function module.isCI(name) end --- Gets the contents of $NVIM_LOG_FILE for printing to the build log. +-- Gets the (tail) contents of `logfile`. -- Also moves the file to "${NVIM_LOG_FILE}.displayed" on CI environments. -function module.read_nvim_log() - local logfile = os.getenv('NVIM_LOG_FILE') or '.nvimlog' +function module.read_nvim_log(logfile, ci_rename) + logfile = logfile or os.getenv('NVIM_LOG_FILE') or '.nvimlog' local is_ci = module.isCI() local keep = is_ci and 999 or 10 local lines = module.read_file_list(logfile, -keep) or {} @@ -751,7 +775,7 @@ function module.read_nvim_log() log = log..line..'\n' end log = log..('-'):rep(78)..'\n' - if is_ci then + if is_ci and ci_rename then os.rename(logfile, logfile .. '.displayed') end return log |