diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2020-02-16 23:30:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-16 23:30:24 -0800 |
commit | b353a5c05f026f46aeef0843007ba9c553533248 (patch) | |
tree | fcbc68000b559d2c0c7d7bbb1a4c5efe36f63304 /test/helpers.lua | |
parent | 03f245c0b810fa2ff980bd3bf2530d94fd0f05d3 (diff) | |
download | rneovim-b353a5c05f026f46aeef0843007ba9c553533248.tar.gz rneovim-b353a5c05f026f46aeef0843007ba9c553533248.tar.bz2 rneovim-b353a5c05f026f46aeef0843007ba9c553533248.zip |
test: always dump logs on failure #11886
Whenever `eq()`, `ok()`, etc. fails, include log tail in the failure
message. This helps to correlate log messages with a particular test
failure.
Diffstat (limited to 'test/helpers.lua')
-rw-r--r-- | test/helpers.lua | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/test/helpers.lua b/test/helpers.lua index a31a7733bf..72b1bdcadd 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -55,25 +55,32 @@ local check_logs_useless_lines = { ['See README_MISSING_SYSCALL_OR_IOCTL for guidance']=3, } -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 +--- Invokes `fn` and includes the tail of `logfile` in the error message if it +--- fails. +--- +--@param logfile Log file, defaults to $NVIM_LOG_FILE or '.nvimlog' +--@param fn Function to invoke +--@param ... Function arguments +local function dumplog(logfile, fn, ...) + -- module.validate({ + -- logfile={logfile,'s',true}, + -- fn={fn,'f',false}, + -- }) + local status, rv = pcall(fn, ...) + if status == false then + logfile = logfile or os.getenv('NVIM_LOG_FILE') or '.nvimlog' 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) +function module.eq(expected, actual, context, logfile) + return dumplog(logfile, assert.are.same, expected, actual, context) end -function module.ok(res, msg) - return assert.is_true(res, msg) +function module.neq(expected, actual, context, logfile) + return dumplog(logfile, assert.are_not.same, expected, actual, context) end -function module.near(actual, expected, tolerance) - return assert.is.near(actual, expected, tolerance) +function module.ok(res, msg, logfile) + return dumplog(logfile, assert.is_true, res, msg) end function module.matches(pat, actual) if nil ~= string.match(actual, pat) then |