summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-01-09 00:46:21 +0800
committerruki <[email protected]>2024-01-09 00:46:21 +0800
commitc09b920d694e40a7875db6ee07cd7a3556f9515a (patch)
treee8d716e0cfd9de92ac0a93275bcafb968a1b79a8
parent94b1ac8bf678cf5de937be08073bd13e534728c3 (diff)
improve test output #4571
-rw-r--r--xmake/actions/test/main.lua50
1 files changed, 27 insertions, 23 deletions
diff --git a/xmake/actions/test/main.lua b/xmake/actions/test/main.lua
index ad68ece6d..620c63134 100644
--- a/xmake/actions/test/main.lua
+++ b/xmake/actions/test/main.lua
@@ -37,7 +37,10 @@ function _do_test_target(target, opt)
-- early out: results were computed during build
if opt.build_should_fail or opt.build_should_pass then
- return opt.passed, opt.errors
+ if opt.errors then
+ vprint(opt.errors)
+ end
+ return opt.passed
end
-- get run environments
@@ -59,25 +62,26 @@ function _do_test_target(target, opt)
local ok, syserrors = os.execv(targetfile, runargs, {try = true, timeout = run_timeout,
curdir = rundir, envs = envs, stdout = outfile, stderr = errfile})
local outdata = os.isfile(outfile) and io.readfile(outfile) or ""
+ local errdata = os.isfile(errfile) and io.readfile(errfile) or ""
+ if outdata and #outdata > 0 then
+ vprint(outdata)
+ end
+ if errdata and #errdata > 0 then
+ vprint(errdata)
+ end
if opt.trim_output then
outdata = outdata:trim()
end
if ok ~= 0 then
- local errdata = os.isfile(errfile) and io.readfile(errfile)
- errors = errdata or errors
if not errors or #errors == 0 then
if ok ~= nil then
- errors = outdata or ""
- if #errors > 0 then
- errors = errors .. "\n"
- end
if syserrors then
- errors = errors .. string.format("run failed, exit code: %d, exit error: %s", ok, syserrors)
+ errors = string.format("run %s failed, exit code: %d, exit error: %s", opt.name, ok, syserrors)
else
- errors = errors .. string.format("run failed, exit code: %d", ok)
+ errors = string.format("run %s failed, exit code: %d", opt.name, ok)
end
else
- errors = string.format("run failed, exit error: %s", syserrors and syserrors or "unknown reason")
+ errors = string.format("run %s failed, exit error: %s", opt.name, syserrors and syserrors or "unknown reason")
end
end
end
@@ -154,9 +158,15 @@ function _do_test_target(target, opt)
end
end
end
- return passed, passed and outdata or errors
+ if errors and #errors > 0 and (option.get("verbose") or option.get("diagnosis")) then
+ cprint(errors)
+ end
+ return passed
+ end
+ if errors and #errors > 0 and (option.get("verbose") or option.get("diagnosis")) then
+ cprint(errors)
end
- return false, errors
+ return false
end
-- test target
@@ -164,17 +174,16 @@ function _on_test_target(target, opt)
-- build target with rules
local passed
- local output
local done = false
for _, r in ipairs(target:orderules()) do
local on_test = r:script("test")
if on_test then
- passed, output = on_test(target, opt)
+ passed = on_test(target, opt)
done = true
end
end
if done then
- return passed, output
+ return passed
end
-- do test
@@ -226,21 +235,19 @@ function _run_test(target, test)
-- run the target scripts
local passed
- local output
for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
- local ok, out = script(target, test)
+ local ok = script(target, test)
if i == 3 then
passed = ok
- output = out
end
end
end
-- leave the environments of the target packages
os.setenvs(oldenvs)
- return passed, output
+ return passed
end
-- run tests
@@ -269,7 +276,7 @@ function _run_tests(tests)
local target = testinfo.target
testinfo.target = nil
local spent = os.mclock()
- local passed, output = _run_test(target, testinfo)
+ local passed = _run_test(target, testinfo)
spent = os.mclock() - spent
if passed then
report.passed = report.passed + 1
@@ -283,9 +290,6 @@ function _run_tests(tests)
local padding = maxwidth - #testinfo.name
cprint(progress_format .. "%s%s .................................... " .. status_color .. "%s${clear} ${bright}%0.3fs",
progress, testinfo.name, (" "):rep(padding), passed and "passed" or "failed", spent / 1000)
- if output and (option.get("verbose") or option.get("diagnosis")) then
- cprint(output)
- end
-- stop it if be failed?
if not passed then