Skip to content

Commit ad00eb1

Browse files
committed
test: fixed helper function to delete test directory
1 parent d34c85d commit ad00eb1

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

Diff for: lua/lazy/core/cache.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ function M.find_root(modname)
262262
if M.cache[modname] then
263263
-- check if modname is in cache
264264
local modpath = M.cache[modname].modpath
265-
if M.check_path(modname, modpath) and vim.loop.fs_stat(modpath) then
265+
if M.check_path(modname, modpath) and uv.fs_stat(modpath) then
266266
local root = modpath:gsub("/init%.lua$", ""):gsub("%.lua$", "")
267267
return root
268268
end
@@ -271,7 +271,7 @@ function M.find_root(modname)
271271
-- check for any children in the cache
272272
for child, entry in pairs(M.cache) do
273273
if child:find(modname, 1, true) == 1 then
274-
if M.check_path(child, entry.modpath) and vim.loop.fs_stat(entry.modpath) then
274+
if M.check_path(child, entry.modpath) and uv.fs_stat(entry.modpath) then
275275
local basename = modname:gsub("%.", "/")
276276
local childbase = child:gsub("%.", "/")
277277
local ret = entry.modpath:gsub("/init%.lua$", ""):gsub("%.lua$", "")

Diff for: tests/core/util_spec.lua

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe("util", function()
1212
end
1313
end
1414
Helpers.fs_rm("")
15+
assert(not vim.loop.fs_stat(Helpers.path("")), "fs root should be deleted")
1516
end)
1617

1718
it("lsmod lists all mods in dir", function()
@@ -88,12 +89,13 @@ describe("util", function()
8889
Cache.indexed_rtp = false
8990
vim.opt.rtp:append(Helpers.path("old"))
9091
Helpers.fs_create({ "old/lua/foobar/init.lua" })
91-
require("foobar")
92+
Cache.cache["foobar"] = { modpath = Helpers.path("old/lua/foobar/init.lua") }
9293
local root = Cache.find_root("foobar")
9394
assert(root, "foobar root not found")
9495
assert.same(Helpers.path("old/lua/foobar"), root)
9596

96-
Helpers.fs_rm("old/")
97+
Helpers.fs_rm("old")
98+
assert(not vim.loop.fs_stat(Helpers.path("old/lua/foobar")), "old/lua/foobar should not exist")
9799

98100
-- vim.opt.rtp = rtp
99101
Cache.indexed = {}
@@ -109,7 +111,6 @@ describe("util", function()
109111
Cache.cache = {}
110112
Cache.indexed = {}
111113
Cache.indexed_rtp = false
112-
Cache.topmods = {}
113114
Cache.enabled = true
114115
vim.opt.rtp:append(Helpers.path("old"))
115116
Helpers.fs_create({ "old/lua/foobar/test.lua" })
@@ -120,7 +121,7 @@ describe("util", function()
120121
assert(not Cache.cache["foobar"], "foobar should not be in cache")
121122
assert(Cache.cache["foobar.test"], "foobar.test not found in cache")
122123

123-
Helpers.fs_rm("old/")
124+
Helpers.fs_rm("old")
124125

125126
-- vim.opt.rtp = rtp
126127
Cache.indexed = {}

Diff for: tests/helpers.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function M.fs_create(files)
2323
end
2424

2525
function M.fs_rm(dir)
26-
dir = Util.norm(M.fs_root .. dir)
26+
dir = Util.norm(M.fs_root .. "/" .. dir)
2727
Util.walk(dir, function(path, _, type)
2828
if type == "directory" then
2929
vim.loop.fs_rmdir(path)

0 commit comments

Comments
 (0)