aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/server_requests_spec.lua4
-rw-r--r--test/functional/helpers.lua120
-rw-r--r--test/functional/job/job_spec.lua65
-rw-r--r--test/functional/legacy/006_argument_list_spec.lua2
-rw-r--r--test/functional/legacy/007_ball_buffer_list_spec.lua2
-rw-r--r--test/functional/legacy/021_control_wi_spec.lua2
-rw-r--r--test/functional/legacy/023_edit_arguments_spec.lua4
-rw-r--r--test/functional/legacy/041_writing_and_reading_hundred_kbyte_spec.lua2
-rw-r--r--test/functional/legacy/options_spec.lua3
9 files changed, 107 insertions, 97 deletions
diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua
index 916bdfd9f0..a37c41294b 100644
--- a/test/functional/api/server_requests_spec.lua
+++ b/test/functional/api/server_requests_spec.lua
@@ -4,7 +4,6 @@
local helpers = require('test.functional.helpers')
local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval
local eq, run, stop = helpers.eq, helpers.run, helpers.stop
-local restart = helpers.restart
@@ -15,7 +14,6 @@ describe('server -> client', function()
clear()
cid = nvim('get_api_info')[1]
end)
- teardown(restart)
describe('simple call', function()
it('works', function()
@@ -110,7 +108,7 @@ describe('server -> client', function()
return
end
notified = notified + 1
- eq('notified', eval('rpcrequest('..cid..', "notify")'))
+ eq('notified!', eval('rpcrequest('..cid..', "notify")'))
end
run(on_request, on_notification, on_setup)
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 70f4fcf9e5..bf6e3dd38a 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -1,15 +1,17 @@
+require('coxpcall')
local Loop = require('nvim.loop')
local MsgpackStream = require('nvim.msgpack_stream')
local AsyncSession = require('nvim.async_session')
local Session = require('nvim.session')
local nvim_prog = os.getenv('NVIM_PROG') or 'build/bin/nvim'
-local nvim_argv = {nvim_prog, '-u', 'NONE', '-N', '--embed'}
+local nvim_argv = {nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N', '--embed'}
if os.getenv('VALGRIND') then
local log_file = os.getenv('VALGRIND_LOG') or 'valgrind-%p.log'
local valgrind_argv = {'valgrind', '-q', '--tool=memcheck',
'--leak-check=yes', '--track-origins=yes',
+ '--show-possibly-lost=no',
'--suppressions=.valgrind.supp',
'--log-file='..log_file}
if os.getenv('VALGRIND_GDB') then
@@ -23,74 +25,7 @@ if os.getenv('VALGRIND') then
nvim_argv = valgrind_argv
end
-local session
-
-local rawfeed
-local function restart()
- local loop = Loop.new()
- local msgpack_stream = MsgpackStream.new(loop)
- local async_session = AsyncSession.new(msgpack_stream)
- session = Session.new(async_session)
- loop:spawn(nvim_argv)
- rawfeed([[:function BeforeEachTest()
- set all&
- redir => groups
- silent augroup
- redir END
- for group in split(groups)
- exe 'augroup '.group
- autocmd!
- augroup END
- endfor
- autocmd!
- tabnew
- let curbufnum = eval(bufnr('%'))
- redir => buflist
- silent ls!
- redir END
- let bufnums = []
- for buf in split(buflist, '\n')
- let bufnum = eval(split(buf, '[ u]')[0])
- if bufnum != curbufnum
- call add(bufnums, bufnum)
- endif
- endfor
- if len(bufnums) > 0
- exe 'silent bwipeout! '.join(bufnums, ' ')
- endif
- silent tabonly
- for k in keys(g:)
- exe 'unlet g:'.k
- endfor
- filetype plugin indent off
- mapclear
- mapclear!
- abclear
- comclear
- let regs = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-"'
- let i = 0
- while i < strlen(regs)
- call setreg(regs[i], '')
- let i = i+1
- endwhile
- redir => funcs
- silent! function
- redir END
- for fname in split(funcs, '\n')
- let matches = matchlist(fname, '\v^function ([^()<>]+)')
- if type([]) == type(matches) && matches[1] !~ 'BeforeEachTest'
- exe 'silent! delfunc '.matches[1]
- endif
- endfor
- let options = ['shell', 'fileignorecase']
- for option in options
- exe 'set '.option.'&'
- endfor
- endfunction
- ]])
-end
-
-local loop_running, last_error
+local session, loop_running, last_error
local function request(method, ...)
local status, rv = session:request(method, ...)
@@ -112,9 +47,32 @@ local function next_message()
return session:next_message()
end
+local function call_and_stop_on_error(...)
+ local status, result = copcall(...)
+ if not status then
+ session:stop()
+ last_error = result
+ return ''
+ end
+ return result
+end
+
local function run(request_cb, notification_cb, setup_cb)
+
+ local function on_request(method, args)
+ return call_and_stop_on_error(request_cb, method, args)
+ end
+
+ local function on_notification(method, args)
+ call_and_stop_on_error(notification_cb, method, args)
+ end
+
+ local function on_setup()
+ call_and_stop_on_error(setup_cb)
+ end
+
loop_running = true
- session:run(request_cb, notification_cb, setup_cb)
+ session:run(on_request, on_notification, on_setup)
loop_running = false
if last_error then
local err = last_error
@@ -153,7 +111,7 @@ local function buffer_slice(start, stop, buffer_idx)
end
local function nvim_replace_termcodes(input)
- return request('vim_replace_termcodes', input, false, true, true )
+ return request('vim_replace_termcodes', input, false, true, true)
end
local function dedent(str)
@@ -178,22 +136,29 @@ local function dedent(str)
return str
end
-local function clear()
- nvim_command('call BeforeEachTest()')
-end
-
local function feed(...)
for _, v in ipairs({...}) do
nvim_feed(nvim_replace_termcodes(dedent(v)))
end
end
-function rawfeed(...)
+local function rawfeed(...)
for _, v in ipairs({...}) do
nvim_feed(dedent(v), 'nt')
end
end
+local function clear()
+ if session then
+ session:request('vim_command', 'qa!')
+ end
+ local loop = Loop.new()
+ local msgpack_stream = MsgpackStream.new(loop)
+ local async_session = AsyncSession.new(msgpack_stream)
+ session = Session.new(async_session)
+ loop:spawn(nvim_argv)
+end
+
local function insert(...)
nvim_feed('i', 'nt')
rawfeed(...)
@@ -271,12 +236,11 @@ local function curtab(method, ...)
return tabpage(method, tab, ...)
end
-restart()
+clear()
return {
clear = clear,
dedent = dedent,
- restart = restart,
rawfeed = rawfeed,
insert = insert,
feed = feed,
diff --git a/test/functional/job/job_spec.lua b/test/functional/job/job_spec.lua
index b2a65f8269..85a1e92e38 100644
--- a/test/functional/job/job_spec.lua
+++ b/test/functional/job/job_spec.lua
@@ -11,8 +11,16 @@ describe('jobs', function()
before_each(clear)
-- Creates the string to make an autocmd to notify us.
- local notify_str = function(expr)
- return "au! JobActivity xxx call rpcnotify("..channel..", "..expr..")"
+ local notify_str = function(expr1, expr2)
+ local str = "au! JobActivity xxx call rpcnotify("..channel..", "..expr1
+ if expr2 ~= nil then
+ str = str..", "..expr2
+ end
+ return str..")"
+ end
+
+ local notify_job = function()
+ return "au! JobActivity xxx call rpcnotify("..channel..", 'j', v:job_data)"
end
it('returns 0 when it fails to start', function()
@@ -29,21 +37,52 @@ describe('jobs', function()
end)
it('allows interactive commands', function()
- nvim('command', notify_str('v:job_data[2]'))
+ nvim('command', notify_str('v:job_data[1]', 'v:job_data[2]'))
nvim('command', "let j = jobstart('xxx', 'cat', ['-'])")
neq(0, eval('j'))
- nvim('command', "call jobsend(j, 'abc')")
- eq({'notification', 'abc', {}}, next_message())
- nvim('command', "call jobsend(j, '123')")
- eq({'notification', '123', {}}, next_message())
+ nvim('command', 'call jobsend(j, "abc\\n")')
+ eq({'notification', 'stdout', {{'abc'}}}, next_message())
+ nvim('command', 'call jobsend(j, "123\\nxyz\\n")')
+ eq({'notification', 'stdout', {{'123', 'xyz'}}}, next_message())
+ nvim('command', 'call jobsend(j, [123, "xyz"])')
+ eq({'notification', 'stdout', {{'123', 'xyz'}}}, next_message())
nvim('command', notify_str('v:job_data[1])'))
nvim('command', "call jobstop(j)")
eq({'notification', 'exit', {}}, next_message())
end)
+ 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()
+
+ -- v:job_data preserves NULs.
+ nvim('command', notify_str('v:job_data[1]', 'v:job_data[2]'))
+ nvim('command', "let j = jobstart('xxx', 'cat', ['"..filename.."'])")
+ eq({'notification', 'stdout', {{'abc\ndef'}}}, next_message())
+ os.remove(filename)
+
+ -- jobsend() preserves NULs.
+ nvim('command', "let j = jobstart('xxx', 'cat', ['-'])")
+ nvim('command', [[call jobsend(j, ["123\n456"])]])
+ eq({'notification', 'stdout', {{'123\n456'}}}, next_message())
+ nvim('command', "call jobstop(j)")
+ end)
+
+ it('will hold data if it does not end in a newline', function()
+ nvim('command', notify_str('v:job_data[1]', 'v:job_data[2]'))
+ nvim('command', "let j = jobstart('xxx', 'cat', ['-'])")
+ nvim('command', 'call jobsend(j, "abc\\nxyz")')
+ eq({'notification', 'stdout', {{'abc'}}}, next_message())
+ nvim('command', "call jobstop(j)")
+ eq({'notification', 'stdout', {{'xyz'}}}, next_message())
+ end)
+
it('will not allow jobsend/stop on a non-existent job', function()
eq(false, pcall(eval, "jobsend(-1, 'lol')"))
- eq(false, pcall(eval, "jobstop(-1, 'lol')"))
+ eq(false, pcall(eval, "jobstop(-1)"))
end)
it('will not allow jobstop twice on the same job', function()
@@ -56,4 +95,14 @@ describe('jobs', function()
it('will not cause a memory leak if we leave a job running', function()
nvim('command', "call jobstart('xxx', 'cat', ['-'])")
end)
+
+ it('will only emit the "exit" event after "stdout" and "stderr"', function()
+ nvim('command', notify_job())
+ nvim('command', "let j = jobstart('xxx', 'cat', ['-'])")
+ local jobid = nvim('eval', 'j')
+ nvim('eval', 'jobsend(j, "abcdef")')
+ nvim('eval', 'jobstop(j)')
+ eq({'notification', 'j', {{jobid, 'stdout', {'abcdef'}}}}, next_message())
+ eq({'notification', 'j', {{jobid, 'exit'}}}, next_message())
+ end)
end)
diff --git a/test/functional/legacy/006_argument_list_spec.lua b/test/functional/legacy/006_argument_list_spec.lua
index 30fb9a55ff..1266a876d4 100644
--- a/test/functional/legacy/006_argument_list_spec.lua
+++ b/test/functional/legacy/006_argument_list_spec.lua
@@ -50,7 +50,7 @@ describe('argument list', function()
execute('%d')
execute('0put=@a')
- execute('1d | $d')
+ execute('$d')
eq(dedent([[
start of test file Xxx1
diff --git a/test/functional/legacy/007_ball_buffer_list_spec.lua b/test/functional/legacy/007_ball_buffer_list_spec.lua
index 6d89323215..295f63f044 100644
--- a/test/functional/legacy/007_ball_buffer_list_spec.lua
+++ b/test/functional/legacy/007_ball_buffer_list_spec.lua
@@ -51,7 +51,7 @@ describe(':ball', function()
execute('bf')
execute('%d')
execute('0put=@a')
- execute('1d | $d')
+ execute('$d')
expect([[
start of test file Xxx4
diff --git a/test/functional/legacy/021_control_wi_spec.lua b/test/functional/legacy/021_control_wi_spec.lua
index f1f529e9a8..9fd83fec5f 100644
--- a/test/functional/legacy/021_control_wi_spec.lua
+++ b/test/functional/legacy/021_control_wi_spec.lua
@@ -31,7 +31,7 @@ describe('CTRL-W CTRL-I', function()
-- Clean buffer and put register
feed('ggdG"ap')
- execute('1,2d')
+ execute('1d')
-- The buffer should now contain:
expect([[
diff --git a/test/functional/legacy/023_edit_arguments_spec.lua b/test/functional/legacy/023_edit_arguments_spec.lua
index b5955c5987..e68af9758d 100644
--- a/test/functional/legacy/023_edit_arguments_spec.lua
+++ b/test/functional/legacy/023_edit_arguments_spec.lua
@@ -35,8 +35,8 @@ describe(':edit', function()
execute('%d')
execute('0put a')
- -- Remove empty lines
- execute('1d | $d')
+ -- Remove empty line
+ execute('$d')
-- The buffer should now contain
expect([[
diff --git a/test/functional/legacy/041_writing_and_reading_hundred_kbyte_spec.lua b/test/functional/legacy/041_writing_and_reading_hundred_kbyte_spec.lua
index ed1a914c0f..42fb5ed2b3 100644
--- a/test/functional/legacy/041_writing_and_reading_hundred_kbyte_spec.lua
+++ b/test/functional/legacy/041_writing_and_reading_hundred_kbyte_spec.lua
@@ -25,7 +25,7 @@ describe('writing and reading a file of over 100 Kbyte', function()
execute('6005yank A')
execute('%d')
execute('0put a')
- execute('1d | $d')
+ execute('$d')
execute('w!')
expect([[
diff --git a/test/functional/legacy/options_spec.lua b/test/functional/legacy/options_spec.lua
index 983d168609..773acb9663 100644
--- a/test/functional/legacy/options_spec.lua
+++ b/test/functional/legacy/options_spec.lua
@@ -2,11 +2,10 @@
-- other tests, so restart nvim in the teardown hook
local helpers = require('test.functional.helpers')
-local restart, command, clear = helpers.restart, helpers.command, helpers.clear
+local command, clear = helpers.command, helpers.clear
describe('options', function()
setup(clear)
- teardown(restart)
it('is working', function()
command('options')