Files
arti-pack/tests/hermetic_spec.lua
unkin-agent 1568334840
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
Load the working tree, not an installed arti-pack
Neovim's runtimepath searcher outranks package.path, so `make test` on a
machine with arti-pack installed tests the installed copy.

- Give the repository the first package loader slot in the test harness
- Run the suite under `nvim --clean` so site packages stay off the rtp
- Assert modules resolve inside the repository, even with a copy on the rtp
2026-09-12 12:52:55 +10:00

50 lines
1.5 KiB
Lua

local t = require('tests.harness')
local hermetic = require('tests.hermetic')
local MODULES = {
'arti-pack',
'arti-pack.spec',
'arti-pack.fs',
'arti-pack.archive',
'arti-pack.lock',
'arti-pack.installer',
}
local function shadow_plugin()
local dir = vim.fn.tempname()
vim.fn.mkdir(dir .. '/lua/arti-pack', 'p')
vim.fn.writefile({ 'return { shadowed = true }' }, dir .. '/lua/arti-pack/spec.lua')
vim.fn.writefile({ 'return { shadowed = true }' }, dir .. '/lua/arti-pack/init.lua')
return dir
end
t.describe('test harness', function()
t.it('loads every module from the repository', function()
for _, name in ipairs(MODULES) do
require(name)
local source = hermetic.sources[name]
t.truthy(source, name .. ' was not resolved by the repository loader')
t.eq(hermetic.root, source:sub(1, #hermetic.root), name .. ' resolved outside the repository')
end
end)
t.it('outranks an arti-pack installed on the runtimepath', function()
local dir = shadow_plugin()
vim.opt.runtimepath:prepend(dir)
local ok, err = pcall(function()
t.eq(dir .. '/lua/arti-pack/spec.lua', vim.api.nvim_get_runtime_file('lua/arti-pack/spec.lua', false)[1])
for _, name in ipairs({ 'arti-pack', 'arti-pack.spec' }) do
package.loaded[name] = nil
t.falsy(require(name).shadowed, name .. ' came from the runtimepath copy')
t.eq(hermetic.root, hermetic.sources[name]:sub(1, #hermetic.root))
end
end)
vim.opt.runtimepath:remove(dir)
vim.fn.delete(dir, 'rf')
assert(ok, err)
end)
end)