aboutsummaryrefslogtreecommitdiff
path: root/test/functional/helpers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/helpers.lua')
-rw-r--r--test/functional/helpers.lua40
1 files changed, 34 insertions, 6 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 3d02aa7fdd..1159707282 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -6,7 +6,6 @@ local AsyncSession = require('nvim.async_session')
local Session = require('nvim.session')
local nvim_prog = os.getenv('NVIM_PROG') or 'build/bin/nvim'
---- FIXME: 'autoindent' messes up the insert() function
local nvim_argv = {nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N',
'--cmd', 'set shortmess+=I background=light noswapfile noautoindent',
'--embed'}
@@ -207,12 +206,17 @@ local function execute(...)
end
end
+-- Dedent the given text and write it to the file name.
+local function write_file(name, text)
+ local file = io.open(name, 'w')
+ file:write(dedent(text))
+ file:flush()
+ file:close()
+end
+
local function source(code)
local tmpname = os.tmpname()
- local tmpfile = io.open(tmpname, "w")
- tmpfile:write(code)
- tmpfile:flush()
- tmpfile:close()
+ write_file(tmpname, code)
nvim_command('source '..tmpname)
os.remove(tmpname)
end
@@ -285,6 +289,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,
@@ -315,5 +341,7 @@ return {
curtab = curtab,
curbuf_contents = curbuf_contents,
wait = wait,
- set_session = set_session
+ set_session = set_session,
+ write_file = write_file,
+ rmdir = rmdir
}