mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #2932 from lucc/helpers/write_file
[RDY] tests: Add write_file helper function Reviewed-by: Florian Walch <florian@fwalch.com> Reviewed-by: Michael Reed <m.reed@mykolab.com>
This commit is contained in:
commit
1b78ad1c4d
@ -1,7 +1,7 @@
|
|||||||
local helpers, lfs = require('test.functional.helpers'), require('lfs')
|
local helpers, lfs = require('test.functional.helpers'), require('lfs')
|
||||||
local clear, execute, eq, neq, spawn, nvim_prog, set_session, 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.clear, helpers.execute, helpers.eq, helpers.neq, helpers.spawn,
|
||||||
helpers.nvim_prog, helpers.set_session, helpers.wait
|
helpers.nvim_prog, helpers.set_session, helpers.wait, helpers.write_file
|
||||||
|
|
||||||
describe(':wviminfo', function()
|
describe(':wviminfo', function()
|
||||||
local viminfo_file = 'wviminfo_test'
|
local viminfo_file = 'wviminfo_test'
|
||||||
@ -33,10 +33,7 @@ describe(':wviminfo', function()
|
|||||||
local text = 'wviminfo test'
|
local text = 'wviminfo test'
|
||||||
|
|
||||||
-- Create a dummy file
|
-- Create a dummy file
|
||||||
local fp = io.open(viminfo_file, 'w')
|
write_file(viminfo_file, text)
|
||||||
fp:write(text)
|
|
||||||
fp:flush()
|
|
||||||
fp:close()
|
|
||||||
|
|
||||||
-- sanity check
|
-- sanity check
|
||||||
eq(text, io.open(viminfo_file):read())
|
eq(text, io.open(viminfo_file):read())
|
||||||
|
@ -207,12 +207,17 @@ local function execute(...)
|
|||||||
end
|
end
|
||||||
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 function source(code)
|
||||||
local tmpname = os.tmpname()
|
local tmpname = os.tmpname()
|
||||||
local tmpfile = io.open(tmpname, "w")
|
write_file(tmpname, code)
|
||||||
tmpfile:write(code)
|
|
||||||
tmpfile:flush()
|
|
||||||
tmpfile:close()
|
|
||||||
nvim_command('source '..tmpname)
|
nvim_command('source '..tmpname)
|
||||||
os.remove(tmpname)
|
os.remove(tmpname)
|
||||||
end
|
end
|
||||||
@ -315,5 +320,6 @@ return {
|
|||||||
curtab = curtab,
|
curtab = curtab,
|
||||||
curbuf_contents = curbuf_contents,
|
curbuf_contents = curbuf_contents,
|
||||||
wait = wait,
|
wait = wait,
|
||||||
set_session = set_session
|
set_session = set_session,
|
||||||
|
write_file = write_file
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
local helpers = require('test.functional.helpers')
|
local helpers = require('test.functional.helpers')
|
||||||
local clear, nvim, eq, neq, ok, expect, eval, next_msg, run, stop, session
|
local clear, eq, eval, execute, expect, feed, insert, neq, next_msg, nvim,
|
||||||
= helpers.clear, helpers.nvim, helpers.eq, helpers.neq, helpers.ok,
|
nvim_dir, ok, run, session, source, stop, wait, write_file = helpers.clear,
|
||||||
helpers.expect, helpers.eval, helpers.next_message, helpers.run,
|
helpers.eq, helpers.eval, helpers.execute, helpers.expect, helpers.feed,
|
||||||
helpers.stop, helpers.session
|
helpers.insert, helpers.neq, helpers.next_message, helpers.nvim,
|
||||||
local nvim_dir, insert, feed = helpers.nvim_dir, helpers.insert, helpers.feed
|
helpers.nvim_dir, helpers.ok, helpers.run, helpers.session, helpers.source,
|
||||||
local source, execute, wait = helpers.source, helpers.execute, helpers.wait
|
helpers.stop, helpers.wait, helpers.write_file
|
||||||
|
|
||||||
|
|
||||||
describe('jobs', function()
|
describe('jobs', function()
|
||||||
@ -64,9 +64,7 @@ describe('jobs', function()
|
|||||||
it('preserves NULs', function()
|
it('preserves NULs', function()
|
||||||
-- Make a file with NULs in it.
|
-- Make a file with NULs in it.
|
||||||
local filename = os.tmpname()
|
local filename = os.tmpname()
|
||||||
local file = io.open(filename, "w")
|
write_file(filename, "abc\0def\n")
|
||||||
file:write("abc\0def\n")
|
|
||||||
file:close()
|
|
||||||
|
|
||||||
nvim('command', "let j = jobstart(['cat', '"..filename.."'], g:job_opts)")
|
nvim('command', "let j = jobstart(['cat', '"..filename.."'], g:job_opts)")
|
||||||
eq({'notification', 'stdout', {0, {'abc\ndef', ''}}}, next_msg())
|
eq({'notification', 'stdout', {0, {'abc\ndef', ''}}}, next_msg())
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
local helpers = require('test.functional.helpers')
|
local helpers = require('test.functional.helpers')
|
||||||
local feed, insert, source = helpers.feed, helpers.insert, helpers.source
|
local feed, insert, source = helpers.feed, helpers.insert, helpers.source
|
||||||
local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect
|
local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect
|
||||||
|
local write_file = helpers.write_file
|
||||||
local os = require('os')
|
local os = require('os')
|
||||||
|
|
||||||
describe('exists() and has() functions', function()
|
describe('exists() and has() functions', function()
|
||||||
@ -11,8 +12,7 @@ describe('exists() and has() functions', function()
|
|||||||
it('is working', function()
|
it('is working', function()
|
||||||
|
|
||||||
-- Create a temporary script needed for the test.
|
-- Create a temporary script needed for the test.
|
||||||
local script = io.open('test60.vim', 'w')
|
write_file('test60.vim', [=[
|
||||||
script:write(helpers.dedent([=[
|
|
||||||
" Vim script for exists() function test
|
" Vim script for exists() function test
|
||||||
" Script-local variables are checked here
|
" Script-local variables are checked here
|
||||||
|
|
||||||
@ -110,9 +110,7 @@ describe('exists() and has() functions', function()
|
|||||||
echo "FAILED"
|
echo "FAILED"
|
||||||
endif
|
endif
|
||||||
unlet str
|
unlet str
|
||||||
]=]))
|
]=])
|
||||||
script:flush()
|
|
||||||
script:close()
|
|
||||||
|
|
||||||
source([=[
|
source([=[
|
||||||
" Add the special directory with test scripts to &rtp
|
" Add the special directory with test scripts to &rtp
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
-- Tests for undo tree and :earlier and :later.
|
-- Tests for undo tree and :earlier and :later.
|
||||||
|
|
||||||
local helpers = require('test.functional.helpers')
|
local helpers = require('test.functional.helpers')
|
||||||
local feed, insert, source, eq, eval, clear, execute, expect, wait =
|
local feed, insert, source, eq, eval, clear, execute, expect, wait, write_file
|
||||||
helpers.feed, helpers.insert, helpers.source, helpers.eq, helpers.eval,
|
= helpers.feed, helpers.insert, helpers.source, helpers.eq, helpers.eval,
|
||||||
helpers.clear, helpers.execute, helpers.expect, helpers.wait
|
helpers.clear, helpers.execute, helpers.expect, helpers.wait,
|
||||||
|
helpers.write_file
|
||||||
|
|
||||||
local function expect_empty_buffer()
|
local function expect_empty_buffer()
|
||||||
-- The space will be removed by helpers.dedent but is needed because dedent
|
-- The space will be removed by helpers.dedent but is needed because dedent
|
||||||
@ -13,12 +14,6 @@ end
|
|||||||
local function expect_line(line)
|
local function expect_line(line)
|
||||||
return eq(line, eval('getline(".")'))
|
return eq(line, eval('getline(".")'))
|
||||||
end
|
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()
|
describe('undo tree:', function()
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
@ -40,7 +35,7 @@ describe('undo tree:', function()
|
|||||||
write_file('Xtest', '\n123456789\n')
|
write_file('Xtest', '\n123456789\n')
|
||||||
|
|
||||||
-- `:earlier` and `:later` are (obviously) time-sensitive, so this test
|
-- `: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.
|
-- function to allow multiple attempts.
|
||||||
local function test_earlier_later()
|
local function test_earlier_later()
|
||||||
clear()
|
clear()
|
||||||
|
@ -11,7 +11,7 @@ end
|
|||||||
local helpers = require('test.functional.helpers')
|
local helpers = require('test.functional.helpers')
|
||||||
local eval, command, feed = helpers.eval, helpers.command, helpers.feed
|
local eval, command, feed = helpers.eval, helpers.command, helpers.feed
|
||||||
local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert
|
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()
|
describe('python3 commands and functions', function()
|
||||||
@ -46,9 +46,7 @@ describe('python3 commands and functions', function()
|
|||||||
|
|
||||||
it('py3file', function()
|
it('py3file', function()
|
||||||
local fname = 'py3file.py'
|
local fname = 'py3file.py'
|
||||||
local F = io.open(fname, 'w')
|
write_file(fname, 'vim.command("let set_by_py3file = 123")')
|
||||||
F:write('vim.command("let set_by_py3file = 123")')
|
|
||||||
F:close()
|
|
||||||
command('py3file py3file.py')
|
command('py3file py3file.py')
|
||||||
eq(123, eval('g:set_by_py3file'))
|
eq(123, eval('g:set_by_py3file'))
|
||||||
os.remove(fname)
|
os.remove(fname)
|
||||||
|
@ -11,7 +11,7 @@ end
|
|||||||
local helpers = require('test.functional.helpers')
|
local helpers = require('test.functional.helpers')
|
||||||
local eval, command, feed = helpers.eval, helpers.command, helpers.feed
|
local eval, command, feed = helpers.eval, helpers.command, helpers.feed
|
||||||
local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert
|
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()
|
describe('python commands and functions', function()
|
||||||
@ -46,9 +46,7 @@ describe('python commands and functions', function()
|
|||||||
|
|
||||||
it('pyfile', function()
|
it('pyfile', function()
|
||||||
local fname = 'pyfile.py'
|
local fname = 'pyfile.py'
|
||||||
local F = io.open(fname, 'w')
|
write_file(fname, 'vim.command("let set_by_pyfile = 123")')
|
||||||
F:write('vim.command("let set_by_pyfile = 123")')
|
|
||||||
F:close()
|
|
||||||
command('pyfile pyfile.py')
|
command('pyfile pyfile.py')
|
||||||
eq(123, eval('g:set_by_pyfile'))
|
eq(123, eval('g:set_by_pyfile'))
|
||||||
os.remove(fname)
|
os.remove(fname)
|
||||||
|
Loading…
Reference in New Issue
Block a user