Report test complete time
This commit is contained in:
parent
8c406a46b3
commit
b0efc9f783
@ -8,8 +8,8 @@ if not ok then error("lua test harness requires lb:fs module") end
|
||||
local global = _G
|
||||
local colors = {
|
||||
reset = "\x1b[0m",
|
||||
pass = "\x1b[32;1m",
|
||||
fail = "\x1b[31;1m",
|
||||
pass = "\x1b[32;1m", -- green
|
||||
fail = "\x1b[31;1m", -- red
|
||||
}
|
||||
|
||||
local icons = {
|
||||
@ -18,7 +18,7 @@ local icons = {
|
||||
chevron = "\u{203a}",
|
||||
}
|
||||
|
||||
local function color(name, s)
|
||||
local function style(name, s)
|
||||
return ("%s%s%s"):format(colors[name], s, colors.reset)
|
||||
end
|
||||
|
||||
@ -61,17 +61,17 @@ local function name_test(test)
|
||||
end
|
||||
|
||||
local function trace(msg)
|
||||
return color("fail", msg) .. debug.traceback("", 2):sub(("\nstack traceback:"):len() + 1)
|
||||
return style("fail", msg) .. debug.traceback("", 2):sub(("\nstack traceback:"):len() + 1)
|
||||
end
|
||||
|
||||
local function run_test(test)
|
||||
local ok, res = xpcall(test.f, trace, test)
|
||||
if ok then
|
||||
test.state = "pass"
|
||||
print("", ("%s %s"):format(color("pass", "PASS"), name_test(test)))
|
||||
print("", ("%s %s"):format(style("pass", "PASS"), name_test(test)))
|
||||
else
|
||||
test.state = "fail"
|
||||
print("", ("%s %s\n\n%s\n"):format(color("fail", "FAIL"), name_test(test), res))
|
||||
print("", ("%s %s\n\n%s\n"):format(style("fail", "FAIL"), name_test(test), res))
|
||||
end
|
||||
collectgarbage() -- gc after each test to test destructors
|
||||
return test
|
||||
@ -87,7 +87,7 @@ local function start(cx, item)
|
||||
end
|
||||
end
|
||||
|
||||
local function check_unrefs()
|
||||
local function check_refs()
|
||||
-- ensure all refs were properly unref'ed
|
||||
local registry = debug.getregistry()
|
||||
local count = #registry
|
||||
@ -106,7 +106,7 @@ end
|
||||
|
||||
local function main(item)
|
||||
local cx = { tasks = {} }
|
||||
local pass, fail = 0, 0
|
||||
local time, pass, fail = os.clock(), 0, 0
|
||||
start(cx, item)
|
||||
for _, task in ipairs(cx.tasks) do
|
||||
if task:await().state == "pass" then
|
||||
@ -115,22 +115,24 @@ local function main(item)
|
||||
fail = fail + 1
|
||||
end
|
||||
end
|
||||
local time = (os.clock() - time) * 1000
|
||||
local code = 1
|
||||
if fail == 0 then
|
||||
print("", color("pass", ("%s %d tests passed"):format(icons.check, pass)))
|
||||
print("", style("pass", ("%s %d tests passed"):format(icons.check, pass)))
|
||||
code = 0
|
||||
else
|
||||
print(
|
||||
"",
|
||||
("%s, %s"):format(
|
||||
color("pass", ("%s %d tests passed"):format(icons.check, pass)),
|
||||
color("fail", ("%s %d tests failed"):format(icons.cross, fail))
|
||||
style("pass", ("%s %d tests passed"):format(icons.check, pass)),
|
||||
style("fail", ("%s %d tests failed"):format(icons.cross, fail))
|
||||
)
|
||||
)
|
||||
end
|
||||
print("", ("%s completed in %d ms"):format(icons.chevron, time))
|
||||
cx = nil
|
||||
collectgarbage()
|
||||
check_unrefs()
|
||||
check_refs()
|
||||
return code -- report error to cargo
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user