mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-18 20:36:45 +00:00
fix(spec): allow a spec module to be on the rtp and not only in config
This commit is contained in:
parent
963e6f72a7
commit
51c23b661e
5 changed files with 131 additions and 19 deletions
40
tests/core/util_spec.lua
Normal file
40
tests/core/util_spec.lua
Normal file
|
@ -0,0 +1,40 @@
|
|||
local Util = require("lazy.util")
|
||||
local Cache = require("lazy.core.cache")
|
||||
local Helpers = require("tests.helpers")
|
||||
|
||||
describe("util", function()
|
||||
before_each(function()
|
||||
Helpers.fs_rm("")
|
||||
end)
|
||||
|
||||
it("lsmod lists all mods in dir", function()
|
||||
local tests = {
|
||||
{
|
||||
files = { "lua/foo/one.lua", "lua/foo/two.lua", "lua/foo/init.lua" },
|
||||
mods = { "foo", "foo.one", "foo.two" },
|
||||
},
|
||||
{
|
||||
files = { "lua/foo/one.lua", "lua/foo/two.lua", "lua/foo.lua" },
|
||||
mods = { "foo", "foo.one", "foo.two" },
|
||||
},
|
||||
{
|
||||
files = { "lua/foo/one.lua", "lua/foo/two.lua" },
|
||||
mods = { "foo.one", "foo.two" },
|
||||
},
|
||||
}
|
||||
|
||||
vim.opt.rtp:append(Helpers.path(""))
|
||||
for _, test in ipairs(tests) do
|
||||
Cache.cache = {}
|
||||
table.sort(test.mods)
|
||||
Helpers.fs_rm("")
|
||||
Helpers.fs_create(test.files)
|
||||
local mods = {}
|
||||
Util.lsmod("foo", function(modname, modpath)
|
||||
mods[#mods + 1] = modname
|
||||
end)
|
||||
table.sort(mods)
|
||||
assert.same(test.mods, mods)
|
||||
end
|
||||
end)
|
||||
end)
|
37
tests/helpers.lua
Normal file
37
tests/helpers.lua
Normal file
|
@ -0,0 +1,37 @@
|
|||
local Util = require("lazy.util")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.fs_root = vim.fn.fnamemodify("./.tests/fs", ":p")
|
||||
|
||||
function M.path(path)
|
||||
return Util.norm(M.fs_root .. "/" .. path)
|
||||
end
|
||||
|
||||
---@param files string[]
|
||||
function M.fs_create(files)
|
||||
---@type string[]
|
||||
local ret = {}
|
||||
|
||||
for _, file in ipairs(files) do
|
||||
ret[#ret + 1] = Util.norm(M.fs_root .. "/" .. file)
|
||||
local parent = vim.fn.fnamemodify(ret[#ret], ":h:p")
|
||||
vim.fn.mkdir(parent, "p")
|
||||
Util.write_file(ret[#ret], "")
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
function M.fs_rm(dir)
|
||||
dir = Util.norm(M.fs_root .. dir)
|
||||
Util.walk(dir, function(path, _, type)
|
||||
if type == "directory" then
|
||||
vim.loop.fs_rmdir(path)
|
||||
else
|
||||
vim.loop.fs_unlink(path)
|
||||
end
|
||||
end)
|
||||
vim.loop.fs_rmdir(dir)
|
||||
end
|
||||
|
||||
return M
|
Loading…
Add table
Add a link
Reference in a new issue