mirror of https://github.com/folke/lazy.nvim.git
test: fixed helper function to delete test directory
This commit is contained in:
parent
d34c85d580
commit
ad00eb1be2
|
@ -262,7 +262,7 @@ function M.find_root(modname)
|
||||||
if M.cache[modname] then
|
if M.cache[modname] then
|
||||||
-- check if modname is in cache
|
-- check if modname is in cache
|
||||||
local modpath = M.cache[modname].modpath
|
local modpath = M.cache[modname].modpath
|
||||||
if M.check_path(modname, modpath) and vim.loop.fs_stat(modpath) then
|
if M.check_path(modname, modpath) and uv.fs_stat(modpath) then
|
||||||
local root = modpath:gsub("/init%.lua$", ""):gsub("%.lua$", "")
|
local root = modpath:gsub("/init%.lua$", ""):gsub("%.lua$", "")
|
||||||
return root
|
return root
|
||||||
end
|
end
|
||||||
|
@ -271,7 +271,7 @@ function M.find_root(modname)
|
||||||
-- check for any children in the cache
|
-- check for any children in the cache
|
||||||
for child, entry in pairs(M.cache) do
|
for child, entry in pairs(M.cache) do
|
||||||
if child:find(modname, 1, true) == 1 then
|
if child:find(modname, 1, true) == 1 then
|
||||||
if M.check_path(child, entry.modpath) and vim.loop.fs_stat(entry.modpath) then
|
if M.check_path(child, entry.modpath) and uv.fs_stat(entry.modpath) then
|
||||||
local basename = modname:gsub("%.", "/")
|
local basename = modname:gsub("%.", "/")
|
||||||
local childbase = child:gsub("%.", "/")
|
local childbase = child:gsub("%.", "/")
|
||||||
local ret = entry.modpath:gsub("/init%.lua$", ""):gsub("%.lua$", "")
|
local ret = entry.modpath:gsub("/init%.lua$", ""):gsub("%.lua$", "")
|
||||||
|
|
|
@ -12,6 +12,7 @@ describe("util", function()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Helpers.fs_rm("")
|
Helpers.fs_rm("")
|
||||||
|
assert(not vim.loop.fs_stat(Helpers.path("")), "fs root should be deleted")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("lsmod lists all mods in dir", function()
|
it("lsmod lists all mods in dir", function()
|
||||||
|
@ -88,12 +89,13 @@ describe("util", function()
|
||||||
Cache.indexed_rtp = false
|
Cache.indexed_rtp = false
|
||||||
vim.opt.rtp:append(Helpers.path("old"))
|
vim.opt.rtp:append(Helpers.path("old"))
|
||||||
Helpers.fs_create({ "old/lua/foobar/init.lua" })
|
Helpers.fs_create({ "old/lua/foobar/init.lua" })
|
||||||
require("foobar")
|
Cache.cache["foobar"] = { modpath = Helpers.path("old/lua/foobar/init.lua") }
|
||||||
local root = Cache.find_root("foobar")
|
local root = Cache.find_root("foobar")
|
||||||
assert(root, "foobar root not found")
|
assert(root, "foobar root not found")
|
||||||
assert.same(Helpers.path("old/lua/foobar"), root)
|
assert.same(Helpers.path("old/lua/foobar"), root)
|
||||||
|
|
||||||
Helpers.fs_rm("old/")
|
Helpers.fs_rm("old")
|
||||||
|
assert(not vim.loop.fs_stat(Helpers.path("old/lua/foobar")), "old/lua/foobar should not exist")
|
||||||
|
|
||||||
-- vim.opt.rtp = rtp
|
-- vim.opt.rtp = rtp
|
||||||
Cache.indexed = {}
|
Cache.indexed = {}
|
||||||
|
@ -109,7 +111,6 @@ describe("util", function()
|
||||||
Cache.cache = {}
|
Cache.cache = {}
|
||||||
Cache.indexed = {}
|
Cache.indexed = {}
|
||||||
Cache.indexed_rtp = false
|
Cache.indexed_rtp = false
|
||||||
Cache.topmods = {}
|
|
||||||
Cache.enabled = true
|
Cache.enabled = true
|
||||||
vim.opt.rtp:append(Helpers.path("old"))
|
vim.opt.rtp:append(Helpers.path("old"))
|
||||||
Helpers.fs_create({ "old/lua/foobar/test.lua" })
|
Helpers.fs_create({ "old/lua/foobar/test.lua" })
|
||||||
|
@ -120,7 +121,7 @@ describe("util", function()
|
||||||
assert(not Cache.cache["foobar"], "foobar should not be in cache")
|
assert(not Cache.cache["foobar"], "foobar should not be in cache")
|
||||||
assert(Cache.cache["foobar.test"], "foobar.test not found in cache")
|
assert(Cache.cache["foobar.test"], "foobar.test not found in cache")
|
||||||
|
|
||||||
Helpers.fs_rm("old/")
|
Helpers.fs_rm("old")
|
||||||
|
|
||||||
-- vim.opt.rtp = rtp
|
-- vim.opt.rtp = rtp
|
||||||
Cache.indexed = {}
|
Cache.indexed = {}
|
||||||
|
|
|
@ -23,7 +23,7 @@ function M.fs_create(files)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.fs_rm(dir)
|
function M.fs_rm(dir)
|
||||||
dir = Util.norm(M.fs_root .. dir)
|
dir = Util.norm(M.fs_root .. "/" .. dir)
|
||||||
Util.walk(dir, function(path, _, type)
|
Util.walk(dir, function(path, _, type)
|
||||||
if type == "directory" then
|
if type == "directory" then
|
||||||
vim.loop.fs_rmdir(path)
|
vim.loop.fs_rmdir(path)
|
||||||
|
|
Loading…
Reference in New Issue