test: fixed helper function to delete test directory

This commit is contained in:
Folke Lemaitre 2023-01-07 22:52:49 +01:00
parent d34c85d580
commit ad00eb1be2
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
3 changed files with 8 additions and 7 deletions

View File

@ -262,7 +262,7 @@ function M.find_root(modname)
if M.cache[modname] then
-- check if modname is in cache
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$", "")
return root
end
@ -271,7 +271,7 @@ function M.find_root(modname)
-- check for any children in the cache
for child, entry in pairs(M.cache) do
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 childbase = child:gsub("%.", "/")
local ret = entry.modpath:gsub("/init%.lua$", ""):gsub("%.lua$", "")

View File

@ -12,6 +12,7 @@ describe("util", function()
end
end
Helpers.fs_rm("")
assert(not vim.loop.fs_stat(Helpers.path("")), "fs root should be deleted")
end)
it("lsmod lists all mods in dir", function()
@ -88,12 +89,13 @@ describe("util", function()
Cache.indexed_rtp = false
vim.opt.rtp:append(Helpers.path("old"))
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")
assert(root, "foobar root not found")
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
Cache.indexed = {}
@ -109,7 +111,6 @@ describe("util", function()
Cache.cache = {}
Cache.indexed = {}
Cache.indexed_rtp = false
Cache.topmods = {}
Cache.enabled = true
vim.opt.rtp:append(Helpers.path("old"))
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(Cache.cache["foobar.test"], "foobar.test not found in cache")
Helpers.fs_rm("old/")
Helpers.fs_rm("old")
-- vim.opt.rtp = rtp
Cache.indexed = {}

View File

@ -23,7 +23,7 @@ function M.fs_create(files)
end
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)
if type == "directory" then
vim.loop.fs_rmdir(path)