diff options
| author | Saikari <[email protected]> | 2026-07-26 22:50:42 +0300 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-07-30 10:17:31 +0800 |
| commit | 21f1b0efbf5441e5ec82a2caa84984a77ad7e7eb (patch) | |
| tree | 71bc6323bf53b2d92c04eb95e7e257362180c392 /tests/plugins/repository/test.lua | |
| parent | 5f9a9e45ecb47384aa6c80d3543b7c379cb4e5ea (diff) | |
Added tests for plugins
Diffstat (limited to 'tests/plugins/repository/test.lua')
| -rw-r--r-- | tests/plugins/repository/test.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/plugins/repository/test.lua b/tests/plugins/repository/test.lua new file mode 100644 index 000000000..0f7b1cc60 --- /dev/null +++ b/tests/plugins/repository/test.lua @@ -0,0 +1,56 @@ +function main() + local prog = os.programfile() + local gd = os.tmpfile() .. ".gd" + io.writefile(path.join(gd, ".xmake", "repositories", "xmake-repo", "plugins", "hello-world", "xmake.lua"), [[ +task("hello-world") + set_category("plugin") + on_run("main") + set_menu {usage = "xmake hello-world"} +]]) + io.writefile(path.join(gd, ".xmake", "repositories", "xmake-repo", "plugins", "hello-world", "main.lua"), [[ +function main() print("repo-ok") end +]]) + local out = os.iorunv(prog, {"hello-world"}, {envs = {XMAKE_GLOBALDIR = gd}}) + assert(out:find("repo%-ok", 1, true)) + local out = os.iorunv(prog, {"hello-world"}, {envs = {XMAKE_PROGRAM_DIR = os.programdir(), XMAKE_GLOBALDIR = gd}}) + assert(out:find("xrepo", 1, true)) + + local md = os.tmpfile() .. ".md" + io.writefile(path.join(md, ".xmake", "plugins", "manual-plugin", "xmake.lua"), [[ +task("manual-plugin") + set_category("plugin") + on_run("main") + set_menu {usage = "xmake manual-plugin"} +]]) + io.writefile(path.join(md, ".xmake", "plugins", "manual-plugin", "main.lua"), [[ +function main() print("manual") end +]]) + out = os.iorunv(prog, {"plugin", "--list"}, {envs = {XMAKE_GLOBALDIR = md}}) + assert(out:find("manual%-plugin", 1, true)) + out = os.iorunv(prog, {"plugin", "--list"}, {envs = {XMAKE_GLOBALDIR = gd}}) + assert(out:find("hello%-world", 1, true)) + + out = os.iorunv(prog, {"plugin", "--remove", "manual-plugin"}, {envs = {XMAKE_GLOBALDIR = md}}) + assert(out:find("remove plugin", 1, true)) + out = os.iorunv(prog, {"plugin", "--list"}, {envs = {XMAKE_GLOBALDIR = md}}) + assert(not out:find("manual%-plugin", 1, true)) + + local ld = os.tmpfile() .. ".ld" + io.writefile(path.join(ld, "plugins", "hello-world", "xmake.lua"), [[ +task("hello-world") + set_category("plugin") + on_run("main") + set_menu {usage = "xmake hello-world"} +]]) + io.writefile(path.join(ld, "plugins", "hello-world", "main.lua"), [[ +function main() print("local-ok") end +]]) + out = os.iorunv(prog, {"hello-world"}, {envs = {XMAKE_GLOBALDIR = gd, XMAKE_MAIN_REPO = ld}}) + assert(out:find("local%-ok", 1, true)) + out = os.iorunv(prog, {"hello-world"}, {envs = {XMAKE_GLOBALDIR = gd}}) + assert(out:find("repo%-ok", 1, true)) + + os.tryrm(gd) + os.tryrm(md) + os.tryrm(ld) +end |
