summaryrefslogtreecommitdiff
path: root/tests/actions
diff options
context:
space:
mode:
authorruki <[email protected]>2026-08-08 23:17:52 +0800
committerruki <[email protected]>2026-08-09 18:28:59 +0800
commitcf62f410738a7489fe052d183bcf616ecf5f7067 (patch)
treeea9d09e1d05c3a392e9f08688618a1a9663625b3 /tests/actions
parent8564ea66201d1398cb8ee5b91efc784a379c4a64 (diff)
add addon search
Diffstat (limited to 'tests/actions')
-rw-r--r--tests/actions/addon/test.lua114
1 files changed, 74 insertions, 40 deletions
diff --git a/tests/actions/addon/test.lua b/tests/actions/addon/test.lua
index 17a5dc33c..d393c0545 100644
--- a/tests/actions/addon/test.lua
+++ b/tests/actions/addon/test.lua
@@ -68,6 +68,9 @@ function _mock_repo(basenames)
cache.repositories[reponame] = {repodir}
io.save(cachefile, cache)
+ -- we need to clear the quick search cache, it will be rebuilt on the next search
+ os.tryrm(path.join(global.cachedir(), "quick_search"))
+
local function cleanup()
for _, name in ipairs(names) do
os.tryrm(path.join(global.directory(), "addons", name))
@@ -78,49 +81,65 @@ function _mock_repo(basenames)
cache.repositories[reponame] = nil
end
io.save(cachefile, cache)
+ os.tryrm(path.join(global.cachedir(), "quick_search"))
os.tryrm(repodir)
end
return reponame, names, cleanup
end
+-- run the given function with a mocked repository, we always clean it up even if the test fails
+function _with_repo(basenames, func)
+ local reponame, names, cleanup = _mock_repo(basenames)
+ try
+ {
+ function ()
+ func(reponame, names)
+ end,
+ finally
+ {
+ cleanup
+ }
+ }
+end
+
-- install an addon from a repository, by plain name and by repo@name
function test_install_from_repo(t)
- local reponame, names, cleanup = _mock_repo({"hello"})
- local name = names[1]
+ _with_repo({"hello"}, function (reponame, names)
+ local name = names[1]
- -- install by plain name (searched across all repositories)
- os.runv("xmake", {"addon", "--install", "-y", name})
- t:require(os.iorunv("xmake", {name}):find(name, 1, true))
+ -- install by plain name (searched across all repositories)
+ os.runv("xmake", {"addon", "--install", "-y", name})
+ t:require(os.iorunv("xmake", {name}):find(name, 1, true))
- -- reinstall by repo@name
- os.runv("xmake", {"addon", "--remove", name})
- os.runv("xmake", {"addon", "--install", "-y", reponame .. "@" .. name})
- t:require(os.iorunv("xmake", {name}):find(name, 1, true))
+ -- reinstall by repo@name
+ os.runv("xmake", {"addon", "--remove", name})
+ os.runv("xmake", {"addon", "--install", "-y", reponame .. "@" .. name})
+ t:require(os.iorunv("xmake", {name}):find(name, 1, true))
- os.runv("xmake", {"addon", "--remove", name})
- cleanup()
+ os.runv("xmake", {"addon", "--remove", name})
+ end)
end
-- the templates of an installed addon can be used by `xmake create`
function test_install_templates(t)
- local _, names, cleanup = _mock_repo({"hello"})
- local name = names[1]
- os.runv("xmake", {"addon", "--install", "-y", name})
+ _with_repo({"hello"}, function (_, names)
+ local name = names[1]
+ os.runv("xmake", {"addon", "--install", "-y", name})
- -- this template should be listed and grouped by its addon name
- local out = os.iorunv("xmake", {"create", "--list"})
- t:require(out:find(name, 1, true))
+ -- this template should be listed and grouped by its addon name
+ local out = os.iorunv("xmake", {"create", "--list"})
+ t:require(out:find(name, 1, true))
- -- we can create a new project from it
- local projectdir = os.tmpfile() .. ".addon-project"
- os.tryrm(projectdir)
- os.runv("xmake", {"create", "-l", "c", "-t", name, "-P", projectdir})
- t:require(os.isfile(path.join(projectdir, "xmake.lua")))
- t:require(os.isfile(path.join(projectdir, "src", "main.c")))
+ -- we can create a new project from it
+ local projectdir = os.tmpfile() .. ".addon-project"
+ os.tryrm(projectdir)
+ os.runv("xmake", {"create", "-l", "c", "-t", name, "-P", projectdir})
+ t:require(os.isfile(path.join(projectdir, "xmake.lua")))
+ t:require(os.isfile(path.join(projectdir, "src", "main.c")))
- os.tryrm(projectdir)
- os.runv("xmake", {"addon", "--remove", name})
- cleanup()
+ os.tryrm(projectdir)
+ os.runv("xmake", {"addon", "--remove", name})
+ end)
end
-- install an addon from a local directory, then remove it
@@ -140,24 +159,39 @@ function test_install_from_local(t)
os.tryrm(path.directory(dir))
end
--- --list shows the installed and available addons
+-- --list shows the installed addons and their payloads
function test_list(t)
- local _, names, cleanup = _mock_repo({"hello", "world"})
+ _with_repo({"hello", "world"}, function (_, names)
+
+ -- install the first addon, leave the second only available
+ os.runv("xmake", {"addon", "--install", "-y", names[1]})
+ local out = os.iorunv("xmake", {"addon", "--list"})
+ t:require(out:find("the installed addons:", 1, true))
+ t:require(out:find(names[1], 1, true))
- -- install the first addon, leave the second only available
- os.runv("xmake", {"addon", "--install", "-y", names[1]})
- local out = os.iorunv("xmake", {"addon", "--list"})
- t:require(out:find("the installed addons:", 1, true))
- t:require(out:find(names[1], 1, true))
- t:require(out:find(names[2], 1, true))
- t:require(out:find("xmake addon --install " .. names[2], 1, true))
+ -- the payloads of the installed addon should be shown, e.g. (plugins, templates)
+ t:require(out:find("plugins", 1, true))
+ t:require(out:find("templates", 1, true))
+
+ -- the addon which is not installed should be shown in the available addons
+ t:require(out:find("the available addons:", 1, true))
+ t:require(out:find(names[2], 1, true))
+
+ os.runv("xmake", {"addon", "--remove", names[1]})
+ end)
+end
- -- the payloads of the installed addon should be shown, e.g. (latest, plugins, templates)
- t:require(out:find("plugins", 1, true))
- t:require(out:find("templates", 1, true))
+-- --search finds the addons in the repositories, it reuses `xrepo search --addon`
+function test_search(t)
+ _with_repo({"hello"}, function (_, names)
+ local name = names[1]
+ local out = os.iorunv("xmake", {"addon", "--search", name})
+ t:require(out:find(name, 1, true))
- os.runv("xmake", {"addon", "--remove", names[1]})
- cleanup()
+ -- the addons should not be found by the package search
+ local packages_out = os.iorunv("xrepo", {"search", name})
+ t:require_not(packages_out:find(name, 1, true))
+ end)
end
-- invalid installs should fail