diff options
| author | OpportunityLiu <[email protected]> | 2019-06-08 13:34:02 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-06-08 13:34:02 +0800 |
| commit | 1af88102687e493cab40e62b0a2b8b7d42417ae6 (patch) | |
| tree | 272a80b424e68024a9ecda138159864d9659fe5a /tests/test_utils/print_error.lua | |
| parent | e165a8e43abed4eb2eca64c3b5adefb57cd65600 (diff) | |
improve test lib
Diffstat (limited to 'tests/test_utils/print_error.lua')
| -rw-r--r-- | tests/test_utils/print_error.lua | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_utils/print_error.lua b/tests/test_utils/print_error.lua new file mode 100644 index 000000000..d4a4438ab --- /dev/null +++ b/tests/test_utils/print_error.lua @@ -0,0 +1,31 @@ + +function main(t, message, funcs_or_filename, abort_reason) + local funcs = nil + if type(funcs_or_filename) == "function" then + funcs = { debug.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)) + end + else + assert(type(funcs_or_filename) == "string") + funcs = {} + local uplevel = 2 + local func = nil + repeat + func = debug.getinfo(uplevel) + if (func and func.source:endswith(funcs_or_filename)) then + table.insert(funcs, func) + end + uplevel = uplevel + 1 + until func == nil + end + 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 + cprint(">> function %s ${underline}%s${reset}:${bright}%d${reset}", name, func.source, line) + end + raise("aborting because of ${red}%s${reset} ...", abort_reason or "failed assertion") +end
\ No newline at end of file |
