diff options
| author | Saikari <[email protected]> | 2026-07-26 23:07:59 +0300 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-07-30 10:17:31 +0800 |
| commit | b4e04c99d5e3d3a09ddec4ac1ceff016e05c1c64 (patch) | |
| tree | 846ec67493896fd9e8ec97896b584c289fdcbee8 /tests/plugins | |
| parent | d576e545908a520628d6823c4bd210d22458598e (diff) | |
Refactor test script to improve environment variable handling and streamline plugin execution
Diffstat (limited to 'tests/plugins')
| -rw-r--r-- | tests/plugins/repository/test.lua | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/tests/plugins/repository/test.lua b/tests/plugins/repository/test.lua index 0f7b1cc60..07d11eb37 100644 --- a/tests/plugins/repository/test.lua +++ b/tests/plugins/repository/test.lua @@ -1,54 +1,68 @@ function main() - local prog = os.programfile() + -- backup existing env vars + local prev_globaldir = os.getenv("XMAKE_GLOBALDIR") + local prev_main_repo = os.getenv("XMAKE_MAIN_REPO") + local gd = os.tmpfile() .. ".gd" - io.writefile(path.join(gd, ".xmake", "repositories", "xmake-repo", "plugins", "hello-world", "xmake.lua"), [[ + io.writefile(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"), [[ + io.writefile(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)) + + os.setenv("XMAKE_GLOBALDIR", gd) + os.exec("xmake hello-world") + + os.exec("xmake plugin --install hello-world") local md = os.tmpfile() .. ".md" - io.writefile(path.join(md, ".xmake", "plugins", "manual-plugin", "xmake.lua"), [[ + io.writefile(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"), [[ + io.writefile(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)) + os.setenv("XMAKE_GLOBALDIR", md) + os.exec("xmake plugin --list") + os.exec("xmake plugin --remove manual-plugin") local ld = os.tmpfile() .. ".ld" - io.writefile(path.join(ld, "plugins", "hello-world", "xmake.lua"), [[ + io.writefile(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"), [[ + io.writefile(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.setenv("XMAKE_GLOBALDIR", gd) + os.setenv("XMAKE_MAIN_REPO", ld) + os.exec("xmake hello-world") + + os.setenv("XMAKE_MAIN_REPO", "") + os.exec("xmake hello-world") + + -- restore env vars + if prev_globaldir then + os.setenv("XMAKE_GLOBALDIR", prev_globaldir) + else + os.setenv("XMAKE_GLOBALDIR", "") + end + if prev_main_repo then + os.setenv("XMAKE_MAIN_REPO", prev_main_repo) + else + os.setenv("XMAKE_MAIN_REPO", "") + end os.tryrm(gd) os.tryrm(md) |
