summaryrefslogtreecommitdiff
path: root/tests/actions/addon
diff options
context:
space:
mode:
authorruki <[email protected]>2026-08-11 00:46:53 +0800
committerruki <[email protected]>2026-08-11 00:46:53 +0800
commitd699ee8188196a7e77bc1e2912f9b5dc6bd47416 (patch)
tree6a56f694b067bca75f32da15ac853e17e226d563 /tests/actions/addon
parent06a00d75a9574bba124877432553e5cc61f0ba99 (diff)
add addon.lua
Diffstat (limited to 'tests/actions/addon')
-rw-r--r--tests/actions/addon/demo-addon-dep/addon.lua3
-rw-r--r--tests/actions/addon/demo-addon/addon.lua3
-rw-r--r--tests/actions/addon/demo-addon/src/rules/app/xmake.lua5
-rw-r--r--tests/actions/addon/test.lua21
4 files changed, 26 insertions, 6 deletions
diff --git a/tests/actions/addon/demo-addon-dep/addon.lua b/tests/actions/addon/demo-addon-dep/addon.lua
new file mode 100644
index 000000000..2cc460768
--- /dev/null
+++ b/tests/actions/addon/demo-addon-dep/addon.lua
@@ -0,0 +1,3 @@
+addon("demo-addon-dep")
+ set_description("the demo addon which depends on the other addon")
+ add_deps("demo-addon")
diff --git a/tests/actions/addon/demo-addon/addon.lua b/tests/actions/addon/demo-addon/addon.lua
new file mode 100644
index 000000000..b676f95ba
--- /dev/null
+++ b/tests/actions/addon/demo-addon/addon.lua
@@ -0,0 +1,3 @@
+addon("demo-addon")
+ set_description("the demo addon of the tests")
+ set_srcdir("src")
diff --git a/tests/actions/addon/demo-addon/src/rules/app/xmake.lua b/tests/actions/addon/demo-addon/src/rules/app/xmake.lua
index ff54eb85a..b6236bc28 100644
--- a/tests/actions/addon/demo-addon/src/rules/app/xmake.lua
+++ b/tests/actions/addon/demo-addon/src/rules/app/xmake.lua
@@ -2,5 +2,8 @@ rule("app")
add_deps("@self/base")
on_load(function (target)
import("@self.greeting")
- print("demo-addon: rule app is loaded, " .. greeting(target:name()))
+ import("core.package.addon")
+ -- the addon code should never hardcode its own name, it can always ask for it
+ local addonname = addon.owner()
+ print("demo-addon: rule app is loaded by the addon(%s), %s", addonname, greeting(target:name()))
end)
diff --git a/tests/actions/addon/test.lua b/tests/actions/addon/test.lua
index 6a65d233c..3929ebb73 100644
--- a/tests/actions/addon/test.lua
+++ b/tests/actions/addon/test.lua
@@ -52,12 +52,16 @@ function _with_repo(func)
local reponame = "addon-test-repo-" .. suffix
local repodir = os.tmpfile() .. ".addon-repo"
local recipes = {
- -- the addon itself
- [ADDON] = ("set_sourcedir(%q)"):format(path.join(_addondir(ADDON), "src")),
+ -- the addon itself, its manifest sets the payload root directory, e.g. set_srcdir("src")
+ [ADDON] = ("set_sourcedir(%q)"):format(_addondir(ADDON)),
-- the addon which depends on the addon above
[ADDON_DEP] = ("set_sourcedir(%q)\n add_deps(%q, {kind = \"addon\"})"):format(_addondir(ADDON_DEP), ADDON),
-- the addon which provides the same plugin and template names as demo-addon
- ["demo-addon-clone"] = ("set_sourcedir(%q)"):format(path.join(_addondir(ADDON), "src"))
+ --
+ -- @note it points at the payloads directly, so it has no manifest and no name conflict
+ ["demo-addon-clone"] = ("set_sourcedir(%q)"):format(path.join(_addondir(ADDON), "src")),
+ -- the addon whose package name does not match the name in its manifest
+ ["demo-addon-badname"] = ("set_sourcedir(%q)"):format(_addondir(ADDON))
}
for name, body in pairs(recipes) do
io.writefile(path.join(repodir, "addons", name:sub(1, 1), name, "xmake.lua"),
@@ -130,7 +134,8 @@ function test_install(t)
for _, ourfile in ipairs({"src", "tests"}) do
t:require_not(os.exists(path.join(installdir, ourfile)))
end
- t:require(os.iorunv("xmake", {"addon", "--list"}):find(ADDON, 1, true))
+ -- the addon describes itself, we should get its description from the manifest
+ t:require(os.iorunv("xmake", {"addon", "--list"}):find("the demo addon of the tests", 1, true))
end)
-- it should not be runnable after removing it
@@ -170,7 +175,7 @@ target("test")
]])
t:require(out:find("demo-addon: includes check is loaded", 1, true))
t:require(out:find("demo-addon: rule base is loaded", 1, true))
- t:require(out:find("demo-addon: rule app is loaded, hello from demo-addon: test", 1, true))
+ t:require(out:find("demo-addon: rule app is loaded by the addon(demo-addon), hello from demo-addon: test", 1, true))
end)
end
@@ -229,6 +234,12 @@ end
-- the invalid installs should fail, and the `addon` name is reserved for the addon references
function test_invalid(t)
t:require_not(try { function () os.runv("xmake", {"addon", "--install", "-y", "addon-test-missing"}); return true end })
+
+ -- the addon name in its manifest must match the package name which distributes it
+ _with_repo(function ()
+ t:require_not(try { function () os.runv("xmake", {"addon", "--install", "-y", "demo-addon-badname"}); return true end })
+ end)
+
t:require_not(try { function () os.runv("xmake", {"addon", "--install", "-y", "somerepo@.."}); return true end })
t:require_not(try { function () _config_project([[
add_requires("addon")