aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2015-06-12 03:09:12 -0400
committerJustin M. Keyes <justinkz@gmail.com>2015-06-12 03:32:18 -0400
commit1f0830f7004c60f899fc169baecd68960f26ea70 (patch)
treeba7961e6df8af043905c2aefd2cfabaad7975c53
parentfa4b5211c63b4015df0b035bdda05379ea6ac897 (diff)
downloadrneovim-1f0830f7004c60f899fc169baecd68960f26ea70.tar.gz
rneovim-1f0830f7004c60f899fc169baecd68960f26ea70.tar.bz2
rneovim-1f0830f7004c60f899fc169baecd68960f26ea70.zip
tests: wviminfo_spec.lua: rework
074_global_var_in_viminfo_spec: remove some redundant sanity checks.
-rw-r--r--test/functional/ex_cmds/wviminfo_spec.lua73
-rw-r--r--test/functional/legacy/074_global_var_in_viminfo_spec.lua11
2 files changed, 39 insertions, 45 deletions
diff --git a/test/functional/ex_cmds/wviminfo_spec.lua b/test/functional/ex_cmds/wviminfo_spec.lua
index bff180521b..21176f1845 100644
--- a/test/functional/ex_cmds/wviminfo_spec.lua
+++ b/test/functional/ex_cmds/wviminfo_spec.lua
@@ -3,60 +3,55 @@ local clear, execute, eq, neq, spawn, nvim_prog, set_session, wait =
helpers.clear, helpers.execute, helpers.eq, helpers.neq, helpers.spawn,
helpers.nvim_prog, helpers.set_session, helpers.wait
--- Lua does not have a sleep function so we use the system command. If the
--- command does not support sub second precision we use math.floor() to get
--- full seconds.
-local sleep = function(millisec)
- local sec = millisec / 1000
- local round = math.floor(sec)
- if round == 0 then round = 1 end
- os.execute('sleep '..sec..' || sleep '..round)
-end
-
describe(':wviminfo', function()
- local file = 'foo'
+ local viminfo_file = 'wviminfo_test'
+ local session
+
before_each(function()
- clear()
- os.remove(file)
+ if session then
+ session:exit(0)
+ end
+
+ -- Override the default session because we need 'swapfile' for these tests.
+ local session = spawn({nvim_prog, '-u', 'NONE', '--embed',
+ '--cmd', 'set swapfile'})
+ set_session(session)
+
+ os.remove(viminfo_file)
end)
- it('creates a file', function()
- -- TODO
- -- Set up the nvim session to be able to write viminfo files. Is it
- -- possible to do this outside of the it() call?
- local nvim2 = spawn({nvim_prog, '-u', 'NONE', '--embed'})
- --local nvim2 = spawn({nvim_prog, '-u', 'NONE', '--embed', '--cmd', 'let hans=42' })
- set_session(nvim2)
- --eq(43, eval('hans'))
-
- -- Assert that the file does not exist.
- eq(nil, lfs.attributes(file))
- execute('wv! '..file)
+ it('creates a viminfo file', function()
+ -- file should _not_ exist
+ eq(nil, lfs.attributes(viminfo_file))
+ execute('wv! '..viminfo_file)
wait()
- -- Assert that the file does exist.
- neq(nil, lfs.attributes(file))
+ -- file _should_ exist
+ neq(nil, lfs.attributes(viminfo_file))
end)
it('overwrites existing files', function()
- -- TODO see above
- local nvim2 = spawn({nvim_prog, '-u', 'NONE', '--embed'})
- set_session(nvim2)
+ local text = 'wviminfo test'
- local text = 'foo test'
-
- local fp = io.open(file, 'w')
+ -- Create a dummy file
+ local fp = io.open(viminfo_file, 'w')
fp:write(text)
fp:flush()
fp:close()
- -- Assert that the file already exists.
- neq(nil, lfs.attributes(file))
- execute('wv! '..file)
+
+ -- sanity check
+ eq(text, io.open(viminfo_file):read())
+ neq(nil, lfs.attributes(viminfo_file))
+
+ execute('wv! '..viminfo_file)
wait()
- -- Assert that the contents of the file changed.
- neq(text, io.open(file):read())
+
+ -- File should have been overwritten with a viminfo file.
+ local line1 = io.lines(viminfo_file)()
+ assert(nil ~= string.find(line1, 'This viminfo file was generated by Nvim'),
+ viminfo_file..' should be a viminfo-formatted file')
end)
teardown(function()
- os.remove(file)
+ os.remove(viminfo_file)
end)
end)
diff --git a/test/functional/legacy/074_global_var_in_viminfo_spec.lua b/test/functional/legacy/074_global_var_in_viminfo_spec.lua
index 4f05db6a69..180071118a 100644
--- a/test/functional/legacy/074_global_var_in_viminfo_spec.lua
+++ b/test/functional/legacy/074_global_var_in_viminfo_spec.lua
@@ -34,21 +34,20 @@ describe('storing global variables in viminfo files', function()
)
eq(test_dict, eval('MY_GLOBAL_DICT'))
eq(test_list, eval('MY_GLOBAL_LIST'))
- -- Assert that the viminfo file does not exists.
- eq(nil, lfs.attributes('Xviminfo'))
+
execute('wv! Xviminfo')
wait()
+
-- Assert that the viminfo file exists.
neq(nil, lfs.attributes('Xviminfo'))
execute('unlet MY_GLOBAL_DICT',
- 'unlet MY_GLOBAL_LIST')
+ 'unlet MY_GLOBAL_LIST')
-- Assert that the variables where deleted.
eq(0, eval('exists("MY_GLOBAL_DICT")'))
eq(0, eval('exists("MY_GLOBAL_LIST")'))
+
execute('rv! Xviminfo')
- -- Assert that the variables where restored.
- eq(1, eval('exists("MY_GLOBAL_DICT")'))
- eq(1, eval('exists("MY_GLOBAL_LIST")'))
+
eq(test_list, eval('MY_GLOBAL_LIST'))
eq(test_dict, eval('MY_GLOBAL_DICT'))
end)