aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/ex_cmds/sign_spec.lua25
-rw-r--r--test/functional/helpers.lua108
-rw-r--r--test/functional/job/job_spec.lua59
-rw-r--r--test/functional/shell/viml_system_spec.lua4
4 files changed, 146 insertions, 50 deletions
diff --git a/test/functional/ex_cmds/sign_spec.lua b/test/functional/ex_cmds/sign_spec.lua
new file mode 100644
index 0000000000..74e1aa4702
--- /dev/null
+++ b/test/functional/ex_cmds/sign_spec.lua
@@ -0,0 +1,25 @@
+local helpers = require('test.functional.helpers')
+local clear, nvim, buffer, curbuf, curwin, eq, ok =
+ helpers.clear, helpers.nvim, helpers.buffer, helpers.curbuf, helpers.curwin,
+ helpers.eq, helpers.ok
+
+describe('sign', function()
+ describe('unplace {id}', function()
+ describe('without specifying buffer', function()
+ it('deletes the sign from all buffers', function()
+ -- place a sign with id 34 to first buffer
+ nvim('command', 'sign define Foo text=+ texthl=Delimiter linehl=Comment')
+ local buf1 = nvim('eval', 'bufnr("%")')
+ nvim('command', 'sign place 34 line=3 name=Foo buffer='..buf1)
+ -- create a second buffer and place the sign on it as well
+ nvim('command', 'new')
+ local buf2 = nvim('eval', 'bufnr("%")')
+ nvim('command', 'sign place 34 line=3 name=Foo buffer='..buf2)
+ -- now unplace without specifying a buffer
+ nvim('command', 'sign unplace 34')
+ eq("\n--- Signs ---\n", nvim('command_output', 'sign place buffer='..buf1))
+ eq("\n--- Signs ---\n", nvim('command_output', 'sign place buffer='..buf2))
+ end)
+ end)
+ end)
+end)
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 324af6a232..d9107543ea 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -25,19 +25,63 @@ 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
+ endfunction
+ ]])
end
-restart()
+
+local loop_running, last_error
local function request(method, ...)
local status, rv = session:request(method, ...)
if not status then
- error(rv[2])
+ if loop_running then
+ last_error = rv[2]
+ session:stop()
+ else
+ error(rv[2])
+ end
end
return rv
end
@@ -47,7 +91,14 @@ local function next_message()
end
local function run(request_cb, notification_cb, setup_cb)
+ loop_running = true
session:run(request_cb, notification_cb, setup_cb)
+ loop_running = false
+ if last_error then
+ local err = last_error
+ last_error = nil
+ error(err)
+ end
end
local function stop()
@@ -115,7 +166,7 @@ local function feed(...)
end
end
-local function rawfeed(...)
+function rawfeed(...)
for _, v in ipairs({...}) do
nvim_feed(dedent(v), 'nt')
end
@@ -138,14 +189,6 @@ local function execute(...)
end
end
-local function eval(expr)
- local status, result = pcall(function() return nvim_eval(expr) end)
- if not status then
- error('Failed to evaluate expression "' .. expr .. '"')
- end
- return result
-end
-
local function eq(expected, actual)
return assert.are.same(expected, actual)
end
@@ -158,44 +201,6 @@ local function expect(contents, first, last, buffer_index)
return eq(dedent(contents), buffer_slice(first, last, buffer_index))
end
-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
-endfunction
-]])
-
local function ok(expr)
assert.is_true(expr)
@@ -245,6 +250,8 @@ local function curtab(method, ...)
return tabpage(method, tab, ...)
end
+restart()
+
return {
clear = clear,
restart = restart,
@@ -252,7 +259,8 @@ return {
insert = insert,
feed = feed,
execute = execute,
- eval = eval,
+ eval = nvim_eval,
+ command = nvim_command,
request = request,
next_message = next_message,
run = run,
diff --git a/test/functional/job/job_spec.lua b/test/functional/job/job_spec.lua
new file mode 100644
index 0000000000..b2a65f8269
--- /dev/null
+++ b/test/functional/job/job_spec.lua
@@ -0,0 +1,59 @@
+
+local helpers = require('test.functional.helpers')
+local clear, nvim, eq, neq, ok, expect, eval, next_message, 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 channel = nvim('get_api_info')[1]
+
+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..")"
+ end
+
+ it('returns 0 when it fails to start', function()
+ local status, rv = pcall(eval, "jobstart('', '')")
+ eq(false, status)
+ ok(rv ~= nil)
+ end)
+
+ it('calls JobActivity when the job writes and exits', function()
+ nvim('command', notify_str('v:job_data[1]'))
+ nvim('command', "call jobstart('xxx', 'echo')")
+ eq({'notification', 'stdout', {}}, next_message())
+ eq({'notification', 'exit', {}}, next_message())
+ end)
+
+ it('allows interactive commands', function()
+ nvim('command', notify_str('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', notify_str('v:job_data[1])'))
+ nvim('command', "call jobstop(j)")
+ eq({'notification', 'exit', {}}, 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')"))
+ end)
+
+ it('will not allow jobstop twice on the same job', function()
+ nvim('command', "let j = jobstart('xxx', 'cat', ['-'])")
+ neq(0, eval('j'))
+ eq(true, pcall(eval, "jobstop(j)"))
+ eq(false, pcall(eval, "jobstop(j)"))
+ end)
+
+ it('will not cause a memory leak if we leave a job running', function()
+ nvim('command', "call jobstart('xxx', 'cat', ['-'])")
+ end)
+end)
diff --git a/test/functional/shell/viml_system_spec.lua b/test/functional/shell/viml_system_spec.lua
index 9ed1016f73..a8bab8e26e 100644
--- a/test/functional/shell/viml_system_spec.lua
+++ b/test/functional/shell/viml_system_spec.lua
@@ -39,6 +39,8 @@ describe('system()', function()
eq(1, eval('v:shell_error'))
eval([[system("sh -c 'exit 5'")]])
eq(5, eval('v:shell_error'))
+ eval([[system('this-should-not-exist')]])
+ eq(127, eval('v:shell_error'))
end)
describe('passing no input', function()
@@ -117,6 +119,8 @@ describe('systemlist()', function()
eq(1, eval('v:shell_error'))
eval([[systemlist("sh -c 'exit 5'")]])
eq(5, eval('v:shell_error'))
+ eval([[systemlist('this-should-not-exist')]])
+ eq(127, eval('v:shell_error'))
end)
describe('passing string with linefeed characters as input', function()