Skip to content

Commit

Permalink
rewrite filewatch test
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Feb 13, 2024
1 parent 750ded9 commit f136afa
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions test/test_filewatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,19 @@ end

function test_fw:test_2()
test(function (fw, root)
fs.create_directories(root / "test1")
create_file(root / "test1.txt")
fs.rename(root / "test1.txt", root / "test2.txt")
fs.remove(root / "test2.txt")
fs.create_directories(root / "dir")
create_file(root / "file_1")
fs.rename(root / "file_1", root / "file_2")
fs.remove(root / "file_2")

local list = {}
local n = 100
while true do
local w, v = fw:select()
if w then
n = 100
if type(v) == "userdata" or type(v) == "table" then
if list[#list] ~= v then
list[#list+1] = v
else
list[#list+1] = fs.path(v)
end
else
n = n - 1
Expand All @@ -60,17 +58,11 @@ function test_fw:test_2()
thread.sleep(0.001)
end
end
local function assertHas(path)
for _, v in ipairs(list) do
if v == path then
return
end
end
lt.assertEquals(path, nil)
end
assertHas(root / "test1")
assertHas(root / "test1.txt")
assertHas(root / "test2.txt")
lt.assertEquals(list, {
(root / "dir"):string(),
(root / "file_1"):string(),
(root / "file_2"):string(),
})
end)
end

Expand Down

0 comments on commit f136afa

Please sign in to comment.