summaryrefslogtreecommitdiff
path: root/tests/plugins/repository
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-07-27 11:51:12 +0300
committerruki <[email protected]>2026-07-30 10:17:31 +0800
commit0376ff7ab486d773458886982f465897ca18a978 (patch)
tree1cdc17f77c73df3160b7ef24fefe09a9105629cc /tests/plugins/repository
parentb4e04c99d5e3d3a09ddec4ac1ceff016e05c1c64 (diff)
Enhance plugin management by adding support for installing plugins from GitHub and local directories, and streamline repository handling in the task system.
Diffstat (limited to 'tests/plugins/repository')
-rw-r--r--tests/plugins/repository/test.lua136
1 files changed, 78 insertions, 58 deletions
diff --git a/tests/plugins/repository/test.lua b/tests/plugins/repository/test.lua
index 07d11eb37..bbff847a5 100644
--- a/tests/plugins/repository/test.lua
+++ b/tests/plugins/repository/test.lua
@@ -1,70 +1,90 @@
-function main()
- -- 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(gd .. "/.xmake/repositories/xmake-repo/plugins/hello-world/xmake.lua", [[
-task("hello-world")
+function _write_plugin(dir, name, text)
+ io.writefile(path.join(dir, "xmake.lua"), string.format([[
+task("%s")
set_category("plugin")
on_run("main")
- set_menu {usage = "xmake hello-world"}
-]])
- io.writefile(gd .. "/.xmake/repositories/xmake-repo/plugins/hello-world/main.lua", [[
-function main() print("repo-ok") end
-]])
+ set_menu {usage = "xmake %s"}
+]], name, name))
+ io.writefile(path.join(dir, "main.lua"), string.format([[function main() print("%s") end]], text))
+end
- os.setenv("XMAKE_GLOBALDIR", gd)
- os.exec("xmake hello-world")
+function main()
+ local global = import("core.base.global")
+ local suffix = path.filename(os.tmpfile()):gsub("[^%w]", "")
+ local reponame = "plugin-test-repository-" .. suffix
+ local hello_name = "plugin-test-hello-" .. suffix
+ local formatter_name = "plugin-test-formatter-" .. suffix
+ local available_name = "plugin-test-available-" .. suffix
+ local local_name = "plugin-test-local-" .. suffix
+ local repodir = os.tmpfile() .. ".plugins-repository"
+ local localdir = path.join(os.tmpfile() .. ".local-plugin", local_name)
+ local plugindir = path.join(global.directory(), "plugins")
+ local cachefile = path.join(global.directory(), "cache", "repository")
+ local cachebackup = os.tmpfile() .. ".repository"
- os.exec("xmake plugin --install hello-world")
+ if os.isfile(cachefile) then
+ os.cp(cachefile, cachebackup)
+ end
- local md = os.tmpfile() .. ".md"
- 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(md .. "/.xmake/plugins/manual-plugin/main.lua", [[
-function main() print("manual") end
-]])
+ try
+ {
+ function ()
+ -- mock repository with installed and available plugins
+ _write_plugin(path.join(repodir, "plugins", hello_name), hello_name, "repo-ok")
+ _write_plugin(path.join(repodir, "plugins", formatter_name), formatter_name, "format-ok")
+ _write_plugin(path.join(repodir, "plugins", available_name), available_name, "available-ok")
+ local cache = io.load(cachefile) or {}
+ cache.repositories = cache.repositories or {}
+ cache.repositories[reponame] = {repodir}
+ io.save(cachefile, cache)
- os.setenv("XMAKE_GLOBALDIR", md)
- os.exec("xmake plugin --list")
- os.exec("xmake plugin --remove manual-plugin")
+ -- Feature: install by plain name from repository
+ os.exec("xmake plugin --install " .. hello_name)
+ os.exec("xmake " .. hello_name)
- local ld = os.tmpfile() .. ".ld"
- 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(ld .. "/plugins/hello-world/main.lua", [[
-function main() print("local-ok") end
-]])
+ -- Feature: install by repo@name format
+ os.exec("xmake plugin --install " .. reponame .. "@" .. formatter_name)
+ os.exec("xmake " .. formatter_name)
- os.setenv("XMAKE_GLOBALDIR", gd)
- os.setenv("XMAKE_MAIN_REPO", ld)
- os.exec("xmake hello-world")
+ -- Feature: --list shows installed and available repository plugins
+ local out = os.iorun("xmake plugin --list")
+ assert(out:find(hello_name, 1, true))
+ assert(out:find(formatter_name, 1, true))
+ assert(out:find(available_name, 1, true))
+ assert(out:find("xmake plugin --install " .. available_name, 1, true))
- os.setenv("XMAKE_MAIN_REPO", "")
- os.exec("xmake hello-world")
+ -- Feature: install from local directory
+ _write_plugin(localdir, local_name, "local-ok")
+ os.exec("xmake plugin --install " .. os.args(localdir))
+ os.exec("xmake " .. local_name)
- -- 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
+ out = os.iorun("xmake plugin --list")
+ assert(out:find(local_name, 1, true))
+
+ -- Feature: remove plugin
+ os.exec("xmake plugin --remove " .. local_name)
+ out = os.iorun("xmake plugin --list")
+ assert(not out:find(local_name, 1, true))
- os.tryrm(gd)
- os.tryrm(md)
- os.tryrm(ld)
+ -- Feature: install non-existent plugin fails gracefully
+ local ok = try { function () os.exec("xmake plugin --install plugin-test-missing-" .. suffix) end }
+ assert(not ok)
+ end,
+ finally
+ {
+ function ()
+ for _, name in ipairs({hello_name, formatter_name, available_name, local_name}) do
+ os.tryrm(path.join(plugindir, name))
+ end
+ if os.isfile(cachebackup) then
+ os.cp(cachebackup, cachefile)
+ else
+ os.tryrm(cachefile)
+ end
+ os.tryrm(cachebackup)
+ os.tryrm(repodir)
+ os.tryrm(path.directory(localdir))
+ end
+ }
+ }
end