From 21f1b0efbf5441e5ec82a2caa84984a77ad7e7eb Mon Sep 17 00:00:00 2001 From: Saikari Date: Sun, 26 Jul 2026 22:50:42 +0300 Subject: Added tests for plugins --- tests/plugins/repository/test.lua | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/plugins/repository/test.lua (limited to 'tests/plugins') 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 -- cgit v1.3.1