Skip to content

Commit

Permalink
tests: runner: do recursive remove on tmp
Browse files Browse the repository at this point in the history
do recursive remove on tmp so we can have sub directories for readdir
test.
  • Loading branch information
Brandon Philips committed Aug 14, 2012
1 parent 76809b3 commit e1e8377
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions tests/runner.lua
Expand Up @@ -100,18 +100,42 @@ local function run(callback)
end

local tmp_dir = path.join(__dirname, 'tmp')
local function remove_tmp(callback)
fs.readdir(tmp_dir, function(err, files)
if (files ~= nil) then
for i, v in ipairs(files) do
fs.unlinkSync(path.join(tmp_dir, v))
end

local remove_recursive
remove_recursive = function(dir, done)
fs.readdir(dir, function(err, files)
if files == nil then
done()
return
end

if err then
done(err)
return
end

for i, v in ipairs(files) do
local file = path.join(dir, v)
fs.stat(file, function(err, stat)
if err then
done(err)
return
end

if stat.is_directory then
remove_recursive(file, function(err)
fs.rmdir(file, function() end)
end)
elseif stat.is_file then
fs.unlink(file, function() end)
end
end)
end
fs.rmdir(tmp_dir, callback)
done()
end)
end

remove_tmp(function ()
remove_recursive(tmp_dir, function ()
fs.mkdir(tmp_dir, "0755", function()
run(remove_tmp)
end)
Expand Down

0 comments on commit e1e8377

Please sign in to comment.