diff options
| author | ruki <[email protected]> | 2026-08-15 22:52:26 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-08-15 22:52:26 +0800 |
| commit | 2f9993a333a820006b4cf6a18f6dd753cfe48eec (patch) | |
| tree | 6cd8c1fdb40cb91ed23551943d6a35db0fd3a1b2 | |
| parent | 65854acd5e7080dae4cac3e3b3ec1ce01e902ae7 (diff) | |
add addon test
5 files changed, 32 insertions, 1 deletions
diff --git a/tests/actions/addon/projects/autofetch-lockmiss/xmake-addons.lock b/tests/actions/addon/projects/autofetch-lockmiss/xmake-addons.lock new file mode 100644 index 000000000..750a8e609 --- /dev/null +++ b/tests/actions/addon/projects/autofetch-lockmiss/xmake-addons.lock @@ -0,0 +1,9 @@ +{ + __meta__ = { + version = "1.0" + }, + -- this version is not installed, we only install `latest` from the local directory + ["custom-include"] = { + version = "v9.9.9" + } +} diff --git a/tests/actions/addon/projects/autofetch-lockmiss/xmake-addons.lua b/tests/actions/addon/projects/autofetch-lockmiss/xmake-addons.lua new file mode 100644 index 000000000..a85e0fe11 --- /dev/null +++ b/tests/actions/addon/projects/autofetch-lockmiss/xmake-addons.lua @@ -0,0 +1 @@ +add_addons("custom-include") diff --git a/tests/actions/addon/projects/autofetch-lockmiss/xmake.lua b/tests/actions/addon/projects/autofetch-lockmiss/xmake.lua new file mode 100644 index 000000000..0d94cf61c --- /dev/null +++ b/tests/actions/addon/projects/autofetch-lockmiss/xmake.lua @@ -0,0 +1,2 @@ +target("test") + set_kind("phony") diff --git a/tests/actions/addon/test.lua b/tests/actions/addon/test.lua index 192230b08..74b733b21 100644 --- a/tests/actions/addon/test.lua +++ b/tests/actions/addon/test.lua @@ -357,6 +357,20 @@ function test_autofetch_build(t) end) end +-- a locked version which is not installed must not hide the addon +-- +-- @note the auto-fetch installs the locked version, but the commands which do not load +-- the project content only pin it, e.g. `xmake lua`, @see project._pin_addons() +-- +function test_autofetch_lock_missing_version(t) + _with_addons({"custom-include"}, function () + _with_project("autofetch-lockmiss", function () + local script = "import(\"core.package.addon\"); print(addon.addons()[\"custom-include\"] ~= nil)" + t:require(os.iorunv("xmake", {"lua", "-c", script}):find("true", 1, true)) + end) + end) +end + -- the addons file only declares the addons, it cannot reference them function test_autofetch_invalid(t) for _, name in ipairs({"autofetch-badinclude", "autofetch-badname"}) do diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 4f82ccd53..0cda89db1 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -251,7 +251,12 @@ end -- function project._pin_addons() for name, lockinfo in pairs(addons.locked() or {}) do - if lockinfo.version then + -- @note we can only pin an installed version, otherwise this addon would be + -- invisible and every reference to it would just say `not found` + -- + -- the locked version is installed by the auto-fetch, @see addons.satisfied() + -- + if lockinfo.version and table.contains(addon.versions(name), lockinfo.version) then addon.pin(name, lockinfo.version) end end |
