From ad00eb1be2f79da81924e01f3804ea24caa75f82 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 7 Jan 2023 22:52:49 +0100 Subject: [PATCH] test: fixed helper function to delete test directory --- lua/lazy/core/cache.lua | 4 ++-- tests/core/util_spec.lua | 9 +++++---- tests/helpers.lua | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lua/lazy/core/cache.lua b/lua/lazy/core/cache.lua index 709e321..09792bc 100644 --- a/lua/lazy/core/cache.lua +++ b/lua/lazy/core/cache.lua @@ -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$", "") diff --git a/tests/core/util_spec.lua b/tests/core/util_spec.lua index 53566a3..7349c68 100644 --- a/tests/core/util_spec.lua +++ b/tests/core/util_spec.lua @@ -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 = {} diff --git a/tests/helpers.lua b/tests/helpers.lua index c6174a8..48d84f9 100644 --- a/tests/helpers.lua +++ b/tests/helpers.lua @@ -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)