diff --git a/README.md b/README.md index 55e2fd7..61a4fdc 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,16 @@ $ xmake We need install [lua](https://www.lua.org/) or [luajit](http://luajit.org/) to run tests first. +```console +$ xmake run test dialog +$ xmake run test window +$ xmake run test desktop +$ xmake run test inputdialog +$ xmake run test mconfdialog +``` + +Or + ```console $ lua tests\dialog.lua $ lua tests\window.lua diff --git a/README_zh.md b/README_zh.md index 44b9bec..7f99839 100644 --- a/README_zh.md +++ b/README_zh.md @@ -49,6 +49,16 @@ $ xmake 你需要先安装[lua](https://www.lua.org/)或者[luajit](http://luajit.org/)程序去加载运行测试程序: +```console +$ xmake run test dialog +$ xmake run test window +$ xmake run test desktop +$ xmake run test inputdialog +$ xmake run test mconfdialog +``` + +或者 + ```console $ lua tests\dialog.lua $ lua tests\window.lua diff --git a/src/core/xmake.lua b/src/core/xmake.lua index bddd1d2..3e4db45 100644 --- a/src/core/xmake.lua +++ b/src/core/xmake.lua @@ -43,6 +43,36 @@ else add_requires("lua", {nolink = not is_plat("windows")}) end +-- add target +target("test") + + -- only for test + set_kind("phony") + + -- default: disable + set_default(false) + + -- we need build ltui first + add_deps("ltui") + + -- run tests + on_run(function (target) + + -- imports + import("core.base.option") + import("lib.detect.find_tool") + + -- do run + local lua = has_config("luajit") and find_tool("luajit") or find_tool("lua") + if lua then + os.cd(os.projectdir()) + local testname = table.wrap(option.get("arguments"))[1] or "mconfdialog" + os.execv(lua.program, {path.join("tests", testname .. ".lua")}) + else + raise("%s not found!", has_config("luajit") and "luajit" or "lua") + end + end) + -- add target target("ltui")