diff options
author | Marco Hinz <mh.codebro@gmail.com> | 2015-07-20 16:51:53 +0200 |
---|---|---|
committer | Marco Hinz <mh.codebro@gmail.com> | 2015-07-20 22:19:07 +0200 |
commit | 0f34b256aa4c87ed7211275614618e741912a6ec (patch) | |
tree | 962f11c578137c0576f77563ee724b171f9e2548 /test/functional/helpers.lua | |
parent | 05bb841487dd085eb2140e18c5aa8a8b098244da (diff) | |
download | rneovim-0f34b256aa4c87ed7211275614618e741912a6ec.tar.gz rneovim-0f34b256aa4c87ed7211275614618e741912a6ec.tar.bz2 rneovim-0f34b256aa4c87ed7211275614618e741912a6ec.zip |
Test: add new helper function: rmdir()
- lfs.rmdir() only removes empty directories
- os.remove() supercedes lfs.rmdir(); removes files and empty directories
- helpers.rmdir() first removes all files within a directory, then the
directory itself
Diffstat (limited to 'test/functional/helpers.lua')
-rw-r--r-- | test/functional/helpers.lua | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 33d04616a0..d5c22c6f1c 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -290,6 +290,28 @@ local function expect(contents) return eq(dedent(contents), curbuf_contents()) end +local function rmdir(path) + if lfs.attributes(path, 'mode') ~= 'directory' then + return nil + end + for file in lfs.dir(path) do + if file == '.' or file == '..' then + goto continue + end + ret, err = os.remove(path..'/'..file) + if not ret then + error('os.remove: '..err) + return nil + end + ::continue:: + end + ret, err = os.remove(path) + if not ret then + error('os.remove: '..err) + end + return ret +end + return { clear = clear, spawn = spawn, @@ -321,5 +343,6 @@ return { curbuf_contents = curbuf_contents, wait = wait, set_session = set_session, - write_file = write_file + write_file = write_file, + rmdir = rmdir } |