diff options
| author | OpportunityLiu <[email protected]> | 2019-07-01 14:19:05 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-07-01 14:19:05 +0800 |
| commit | f40152174188626df4b70ca1b9044a721fd3c6e8 (patch) | |
| tree | 388f5b8e3acdcf1bc9253556fe762dc8b09a5d2a /tests/test_utils/print_error.lua | |
| parent | 19cbd06f95dddacd1247d1dffab9fa29d719d02b (diff) | |
utf8 support
Diffstat (limited to 'tests/test_utils/print_error.lua')
| -rw-r--r-- | tests/test_utils/print_error.lua | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/tests/test_utils/print_error.lua b/tests/test_utils/print_error.lua index dcf1e82bb..814389c5b 100644 --- a/tests/test_utils/print_error.lua +++ b/tests/test_utils/print_error.lua @@ -1,31 +1,47 @@ -function main(t, message, funcs_or_filename, abort_reason) +function _getinfo(v) + local info = debug.getinfo(v) + if info == nil then return end + if info and info.source:startswith("@") then + info.fullpath = path.absolute(vformat(info.source:sub(2)), os.workingdir()) + info.path = path.relative(info.fullpath, os.workingdir()) + end + return info +end + +function _getfuncs(funcs_or_filename) local funcs = nil if type(funcs_or_filename) == "function" then - funcs = { debug.getinfo(funcs_or_filename) } + funcs = { _getinfo(funcs_or_filename) } elseif type(funcs_or_filename) == "table" then funcs = {} for _, v in ipairs(funcs_or_filename) do - table.insert(funcs, debug.getinfo(v)) + table.join2(funcs, _getfuncs(v)) end else assert(type(funcs_or_filename) == "string") + funcs_or_filename = path.absolute(funcs_or_filename) funcs = {} local uplevel = 2 local func = nil repeat - func = debug.getinfo(uplevel) - if (func and func.source:endswith(funcs_or_filename)) then + func = _getinfo(uplevel) + if func and func.fullpath == funcs_or_filename then table.insert(funcs, func) end uplevel = uplevel + 1 until func == nil end + return funcs +end + +function main(t, message, funcs_or_filename, abort_reason) + local funcs = _getfuncs(funcs_or_filename) cprint(">> ${red}test failed:${reset} %s", message) for _, func in ipairs(funcs) do local line = (func.currentline >= 0) and func.currentline or func.linedefined local name = (func.func == t.func) and t.funcname or func.name or "(anonymous)" - cprint(">> function %s ${underline}%s${reset}:${bright}%d${reset}", name, func.source, line) + cprint(">> function %s ${underline}%s${reset}:${bright}%d${reset}", name, func.path, line) end raise("aborting because of ${red}%s${reset} ...", abort_reason or "failed assertion") end
\ No newline at end of file |
