summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-10-09 22:34:45 +0800
committerruki <[email protected]>2023-10-09 22:34:45 +0800
commit942b0c58ab326b389ecb45c472d42600440f293e (patch)
treeb2376b991927397f0df9744d1d9bb50a9bfbce53
parent6cf470f20d8e6511e1c9dd50ce3ef4bebf8bee89 (diff)
signal fail for test #4265
-rw-r--r--tests/actions/test/xmake.lua1
-rw-r--r--xmake/actions/test/main.lua15
-rw-r--r--xmake/core/project/policy.lua10
3 files changed, 23 insertions, 3 deletions
diff --git a/tests/actions/test/xmake.lua b/tests/actions/test/xmake.lua
index 086734631..5369ee0a4 100644
--- a/tests/actions/test/xmake.lua
+++ b/tests/actions/test/xmake.lua
@@ -1,4 +1,5 @@
add_rules("mode.debug", "mode.release")
+set_policy("test.return_zero_on_failure", true)
for _, file in ipairs(os.files("src/test_*.cpp")) do
local name = path.basename(file)
diff --git a/xmake/actions/test/main.lua b/xmake/actions/test/main.lua
index 857f06071..bea5f5ba2 100644
--- a/xmake/actions/test/main.lua
+++ b/xmake/actions/test/main.lua
@@ -271,6 +271,17 @@ function _run_tests(tests)
if not passed and errors and (option.get("verbose") or option.get("diagnosis")) then
cprint(errors)
end
+
+ -- stop it if be failed?
+ if not passed then
+ local stop = target:policy("test.stop_on_first_failure")
+ if stop == nil then
+ stop = project.policy("test.stop_on_first_failure")
+ end
+ if stop then
+ raise(errors)
+ end
+ end
end
end, {total = #ordertests,
comax = jobs,
@@ -282,6 +293,10 @@ function _run_tests(tests)
print("")
cprint("${color.success}%d%%${clear} tests passed, ${color.failure}%d${clear} tests failed out of ${bright}%d${clear}, spent ${bright}%0.3fs",
passed_rate, report.total - report.passed, report.total, spent / 1000)
+ local return_zero = project.policy("test.return_zero_on_failure")
+ if not return_zero and report.passed < report.total then
+ raise()
+ end
end
function main()
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua
index 8bda6cded..02a6132df 100644
--- a/xmake/core/project/policy.lua
+++ b/xmake/core/project/policy.lua
@@ -112,9 +112,13 @@ function policy.policies()
["package.librarydeps.strict_compatibility"] = {description = "Set strict compatibility for package and it's all library dependencies.", type = "boolean"},
-- Automatically passes dependency configuration for inner xmake package
-- https://github.com/xmake-io/xmake/issues/3952
- ["package.xmake.pass_depconfs"] = {description = "Automatically passes dependency configuration for inner xmake package", default = true, type = "boolean"},
- -- will force cmake package use ninja for build
- ["package.cmake_generator.ninja"] = {description = "Set cmake package use ninja for build", default = false, type = "boolean"}
+ ["package.xmake.pass_depconfs"] = {description = "Automatically passes dependency configuration for inner xmake package", default = true, type = "boolean"},
+ -- It will force cmake package use ninja for build
+ ["package.cmake_generator.ninja"] = {description = "Set cmake package use ninja for build", default = false, type = "boolean"},
+ -- Stop to test on the first failure
+ ["test.stop_on_first_failure"] = {description = "Stop to test on the first failure", default = false, type = "boolean"},
+ -- Return zero as exit code on failure
+ ["test.return_zero_on_failure"] = {description = "Return zero as the exit code on failure", default = false, type = "boolean"}
}
policy._POLICIES = policies
end