diff options
| author | ruki <[email protected]> | 2023-10-29 09:19:52 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-10-29 09:19:52 -0500 |
| commit | 9d420f0c0e112fe200823183a645bd076174c5ab (patch) | |
| tree | 29fd294c2783caa444b990612b4c523c193aaa79 | |
| parent | c38edc3a04d1e9eb4276997e1418679a91df2ce2 (diff) | |
| parent | e050e80ebbcae194e6f83692f0fb443f0ecd3dd5 (diff) | |
Merge pull request #4334 from xmake-io/tests
Improve `xmake test` to test compilation
| -rw-r--r-- | tests/actions/test/src/compile.cpp | 6 | ||||
| -rw-r--r-- | tests/actions/test/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/actions/test/main.lua | 35 |
3 files changed, 44 insertions, 2 deletions
diff --git a/tests/actions/test/src/compile.cpp b/tests/actions/test/src/compile.cpp new file mode 100644 index 000000000..adfe8588c --- /dev/null +++ b/tests/actions/test/src/compile.cpp @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main(int argc, char** argv) { + static_assert(0, "error"); + return 0; +} diff --git a/tests/actions/test/xmake.lua b/tests/actions/test/xmake.lua index 5369ee0a4..9af72dbfe 100644 --- a/tests/actions/test/xmake.lua +++ b/tests/actions/test/xmake.lua @@ -13,3 +13,8 @@ for _, file in ipairs(os.files("src/test_*.cpp")) do add_tests("fail_output", {fail_outputs = {"hello2 .*", "hello xmake"}}) end +target("test_compile") + set_kind("binary") + set_default(false) + add_files("src/compile.cpp") + add_tests("compile", {build_only = true}) diff --git a/xmake/actions/test/main.lua b/xmake/actions/test/main.lua index bea5f5ba2..56a52ad0b 100644 --- a/xmake/actions/test/main.lua +++ b/xmake/actions/test/main.lua @@ -35,6 +35,11 @@ import("actions.build.main", {rootdir = os.programdir(), alias = "build_action"} function _do_test_target(target, opt) opt = opt or {} + -- test build only + if opt.build_only then + return opt.passed, opt.errors + end + -- get run environments local envs = opt.runenvs if not envs then @@ -299,6 +304,23 @@ function _run_tests(tests) end end +-- try to build the given target +function _try_build_target(targetname) + local errors + local passed = try { + function () + build_action.build_targets(targetname) + return true + end, + catch { + function (errs) + errors = tostring(errs) + end + } + } + return passed, errors +end + function main() -- do action for remote? @@ -361,9 +383,18 @@ function main() -- build targets with the given tests first local targetnames = {} for _, testinfo in table.orderpairs(tests) do - table.insert(targetnames, testinfo.target:name()) + local targetname = testinfo.target:name() + if testinfo.build_only then + local passed, errors = _try_build_target(targetname) + testinfo.passed = passed + testinfo.errors = errors + else + table.insert(targetnames, targetname) + end + end + if #targetnames > 0 then + build_action.build_targets(targetnames) end - build_action.build_targets(targetnames) -- run tests _run_tests(tests) |
