tests: Use new write_file() function in tests.

This commit is contained in:
Lucas Hoffmann 2015-06-30 14:16:22 +02:00
parent 652ee0348c
commit 8f4e3a68a8
6 changed files with 23 additions and 39 deletions

View File

@ -1,7 +1,7 @@
local helpers, lfs = require('test.functional.helpers'), require('lfs')
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
local clear, execute, eq, neq, spawn, nvim_prog, set_session, wait, write_file
= helpers.clear, helpers.execute, helpers.eq, helpers.neq, helpers.spawn,
helpers.nvim_prog, helpers.set_session, helpers.wait, helpers.write_file
describe(':wviminfo', function()
local viminfo_file = 'wviminfo_test'
@ -33,10 +33,7 @@ describe(':wviminfo', function()
local text = 'wviminfo test'
-- Create a dummy file
local fp = io.open(viminfo_file, 'w')
fp:write(text)
fp:flush()
fp:close()
write_file(viminfo_file, text)
-- sanity check
eq(text, io.open(viminfo_file):read())

View File

@ -1,11 +1,11 @@
local helpers = require('test.functional.helpers')
local clear, nvim, eq, neq, ok, expect, eval, next_msg, run, stop, session
= helpers.clear, helpers.nvim, helpers.eq, helpers.neq, helpers.ok,
helpers.expect, helpers.eval, helpers.next_message, helpers.run,
helpers.stop, helpers.session
local nvim_dir, insert, feed = helpers.nvim_dir, helpers.insert, helpers.feed
local source, execute, wait = helpers.source, helpers.execute, helpers.wait
local clear, eq, eval, execute, expect, feed, insert, neq, next_msg, nvim,
nvim_dir, ok, run, session, source, stop, wait, write_file = helpers.clear,
helpers.eq, helpers.eval, helpers.execute, helpers.expect, helpers.feed,
helpers.insert, helpers.neq, helpers.next_message, helpers.nvim,
helpers.nvim_dir, helpers.ok, helpers.run, helpers.session, helpers.source,
helpers.stop, helpers.wait, helpers.write_file
describe('jobs', function()
@ -64,9 +64,7 @@ describe('jobs', function()
it('preserves NULs', function()
-- Make a file with NULs in it.
local filename = os.tmpname()
local file = io.open(filename, "w")
file:write("abc\0def\n")
file:close()
write_file(filename, "abc\0def\n")
nvim('command', "let j = jobstart(['cat', '"..filename.."'], g:job_opts)")
eq({'notification', 'stdout', {0, {'abc\ndef', ''}}}, next_msg())

View File

@ -3,6 +3,7 @@
local helpers = require('test.functional.helpers')
local feed, insert, source = helpers.feed, helpers.insert, helpers.source
local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect
local write_file = helpers.write_file
local os = require('os')
describe('exists() and has() functions', function()
@ -11,8 +12,7 @@ describe('exists() and has() functions', function()
it('is working', function()
-- Create a temporary script needed for the test.
local script = io.open('test60.vim', 'w')
script:write(helpers.dedent([=[
write_file('test60.vim', [=[
" Vim script for exists() function test
" Script-local variables are checked here
@ -110,9 +110,7 @@ describe('exists() and has() functions', function()
echo "FAILED"
endif
unlet str
]=]))
script:flush()
script:close()
]=])
source([=[
" Add the special directory with test scripts to &rtp

View File

@ -1,9 +1,10 @@
-- Tests for undo tree and :earlier and :later.
local helpers = require('test.functional.helpers')
local feed, insert, source, eq, eval, clear, execute, expect, wait =
helpers.feed, helpers.insert, helpers.source, helpers.eq, helpers.eval,
helpers.clear, helpers.execute, helpers.expect, helpers.wait
local feed, insert, source, eq, eval, clear, execute, expect, wait, write_file
= helpers.feed, helpers.insert, helpers.source, helpers.eq, helpers.eval,
helpers.clear, helpers.execute, helpers.expect, helpers.wait,
helpers.write_file
local function expect_empty_buffer()
-- The space will be removed by helpers.dedent but is needed because dedent
@ -13,12 +14,6 @@ end
local function expect_line(line)
return eq(line, eval('getline(".")'))
end
local function write_file(name, text)
local file = io.open(name, 'w')
file:write(text)
file:flush()
file:close()
end
describe('undo tree:', function()
before_each(clear)
@ -40,7 +35,7 @@ describe('undo tree:', function()
write_file('Xtest', '\n123456789\n')
-- `:earlier` and `:later` are (obviously) time-sensitive, so this test
-- sometimes fails if the system is under load. It is wrapped in a local
-- sometimes fails if the system is under load. It is wrapped in a local
-- function to allow multiple attempts.
local function test_earlier_later()
clear()

View File

@ -11,7 +11,7 @@ end
local helpers = require('test.functional.helpers')
local eval, command, feed = helpers.eval, helpers.command, helpers.feed
local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert
local expect = helpers.expect
local expect, write_file = helpers.expect, helpers.write_file
describe('python3 commands and functions', function()
@ -46,9 +46,7 @@ describe('python3 commands and functions', function()
it('py3file', function()
local fname = 'py3file.py'
local F = io.open(fname, 'w')
F:write('vim.command("let set_by_py3file = 123")')
F:close()
write_file(fname, 'vim.command("let set_by_py3file = 123")')
command('py3file py3file.py')
eq(123, eval('g:set_by_py3file'))
os.remove(fname)

View File

@ -11,7 +11,7 @@ end
local helpers = require('test.functional.helpers')
local eval, command, feed = helpers.eval, helpers.command, helpers.feed
local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert
local expect = helpers.expect
local expect, write_file = helpers.expect, helpers.write_file
describe('python commands and functions', function()
@ -46,9 +46,7 @@ describe('python commands and functions', function()
it('pyfile', function()
local fname = 'pyfile.py'
local F = io.open(fname, 'w')
F:write('vim.command("let set_by_pyfile = 123")')
F:close()
write_file(fname, 'vim.command("let set_by_pyfile = 123")')
command('pyfile pyfile.py')
eq(123, eval('g:set_by_pyfile'))
os.remove(fname)