aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-04-10 19:12:56 +0200
committerJustin M. Keyes <justinkz@gmail.com>2017-04-10 22:59:30 +0200
commit0ce961891887acc7623162ac3db1fa00156dd2bb (patch)
tree8cd9f0e5204971013f82931d619692d5f779926f /test
parent9aface8c4d1edd25d4fed3e099e3c2c02b0a282a (diff)
downloadrneovim-0ce961891887acc7623162ac3db1fa00156dd2bb.tar.gz
rneovim-0ce961891887acc7623162ac3db1fa00156dd2bb.tar.bz2
rneovim-0ce961891887acc7623162ac3db1fa00156dd2bb.zip
test/rmdir(): Remove `readonly` attr on Windows.
Diffstat (limited to 'test')
-rw-r--r--test/functional/helpers.lua27
-rw-r--r--test/functional/spell/spellfile_spec.lua4
2 files changed, 28 insertions, 3 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 13b06e7f1b..a27b0e7783 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -428,6 +428,16 @@ local function expect_any(contents)
return ok(nil ~= string.find(curbuf_contents(), contents, 1, true))
end
+local function win_remove_readonly_attr(abspath)
+ assert(os_name() == "windows")
+ local cmd = 'attrib -h -r "'..abspath..'"'
+ -- TODO: Lua 5.2 io.popen():close() returns better info:
+ -- http://stackoverflow.com/a/14031974
+ -- https://www.lua.org/manual/5.2/manual.html#pdf-file:close
+ local exitcode = os.execute(cmd)
+ return (exitcode == 0), exitcode
+end
+
local function do_rmdir(path)
if lfs.attributes(path, 'mode') ~= 'directory' then
return nil
@@ -443,8 +453,21 @@ local function do_rmdir(path)
else
local ret, err = os.remove(abspath)
if not ret then
- error('os.remove: '..err)
- return nil
+ if os_name() == "windows" then
+ -- Remove `readonly` attribute (if any)...
+ local attr_status, attr_rv = win_remove_readonly_attr(abspath)
+ if not attr_status then
+ error('win_remove_readonly_attr: '..attr_rv)
+ return nil
+ end
+ -- ...then try again.
+ ret, err = os.remove(abspath)
+ end
+
+ if not ret then
+ error('os.remove: '..err)
+ return nil
+ end
end
end
end
diff --git a/test/functional/spell/spellfile_spec.lua b/test/functional/spell/spellfile_spec.lua
index e7cd10d2ac..afd2c1bce4 100644
--- a/test/functional/spell/spellfile_spec.lua
+++ b/test/functional/spell/spellfile_spec.lua
@@ -5,6 +5,7 @@ local eq = helpers.eq
local clear = helpers.clear
local meths = helpers.meths
local exc_exec = helpers.exc_exec
+local rmdir = helpers.rmdir
local write_file = helpers.write_file
local testdir = 'Xtest-functional-spell-spellfile.d'
@@ -12,11 +13,12 @@ local testdir = 'Xtest-functional-spell-spellfile.d'
describe('spellfile', function()
before_each(function()
clear()
+ rmdir(testdir)
lfs.mkdir(testdir)
lfs.mkdir(testdir .. '/spell')
end)
after_each(function()
- lfs.rmdir(testdir)
+ rmdir(testdir)
end)
-- ┌ Magic string (#VIMSPELLMAGIC)
-- │ ┌ Spell file version (#VIMSPELLVERSION)