aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/vim_spec.lua6
-rw-r--r--test/functional/ex_cmds/sign_spec.lua25
-rw-r--r--test/functional/ex_cmds/wundo_spec.lua20
-rw-r--r--test/functional/helpers.lua108
-rw-r--r--test/functional/job/job_spec.lua59
-rw-r--r--test/functional/legacy/035_increment_and_decrement_spec.lua44
-rw-r--r--test/functional/shell/viml_system_spec.lua51
7 files changed, 263 insertions, 50 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 6a61607d2e..abf9c9efcd 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -105,4 +105,10 @@ describe('vim_* functions', function()
eq(nvim('get_windows')[2], nvim('get_current_window'))
end)
end)
+
+ it('can throw exceptions', function()
+ local status, err = pcall(nvim, 'get_option', 'invalid-option')
+ eq(false, status)
+ ok(err:match('Invalid option name') ~= nil)
+ end)
end)
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/ex_cmds/wundo_spec.lua b/test/functional/ex_cmds/wundo_spec.lua
new file mode 100644
index 0000000000..d8bd8a7031
--- /dev/null
+++ b/test/functional/ex_cmds/wundo_spec.lua
@@ -0,0 +1,20 @@
+-- Specs for
+-- :wundo
+
+local helpers = require('test.functional.helpers')
+local execute, eq, clear, eval, feed =
+ helpers.execute, helpers.eq, helpers.clear, helpers.eval, helpers.feed
+
+
+describe(':wundo', function()
+ before_each(clear)
+
+ it('safely fails on new, non-empty buffer', function()
+ feed('iabc<esc>')
+ execute('wundo foo') -- This should not segfault. #1027
+ --TODO: check messages for error message
+
+ os.remove(eval('getcwd()') .. '/foo') --cleanup
+ 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/legacy/035_increment_and_decrement_spec.lua b/test/functional/legacy/035_increment_and_decrement_spec.lua
new file mode 100644
index 0000000000..20c0cc4206
--- /dev/null
+++ b/test/functional/legacy/035_increment_and_decrement_spec.lua
@@ -0,0 +1,44 @@
+-- Test Ctrl-A and Ctrl-X, which increment and decrement decimal, hexadecimal,
+-- and octal numbers.
+
+local helpers = require('test.functional.helpers')
+local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
+local execute, expect = helpers.execute, helpers.expect
+
+describe('increment and decrement commands', function()
+ setup(clear)
+
+ it('should work', function()
+ -- Insert some numbers in various bases.
+ insert([[
+ 100 0x100 077 0
+ 100 0x100 077
+ 100 0x100 077 0xfF 0xFf
+ 100 0x100 077]])
+
+ -- Increment and decrement numbers in the first row, interpreting the
+ -- numbers as decimal, octal or hexadecimal.
+ execute('set nrformats=octal,hex', '1')
+ feed('102ll64128$')
+
+ -- For the second row, treat the numbers as decimal or octal.
+ -- 0x100 should be interpreted as decimal 0, the character x, and decimal 100.
+ execute('set nrformats=octal', '2')
+ feed('0102l2w65129blx6lD')
+
+ -- For the third row, treat the numbers as decimal or hexadecimal.
+ -- 077 should be interpreted as decimal 77.
+ execute('set nrformats=hex', '3')
+ feed('0101l257Txldt   ')
+
+ -- For the last row, interpret all numbers as decimal.
+ execute('set nrformats=', '4')
+ feed('0200l100w78')
+
+ expect([[
+ 0 0x0ff 0000 -1
+ 0 1x100 0777777
+ -1 0x0 078 0xFE 0xfe
+ -100 -100x100 000]])
+ end)
+end)
diff --git a/test/functional/shell/viml_system_spec.lua b/test/functional/shell/viml_system_spec.lua
index effabe715c..a8bab8e26e 100644
--- a/test/functional/shell/viml_system_spec.lua
+++ b/test/functional/shell/viml_system_spec.lua
@@ -19,10 +19,30 @@ local function delete_file(name)
end
end
+-- Some tests require the xclip program and a x server.
+local xclip = nil
+do
+ if os.getenv('DISPLAY') then
+ local proc = io.popen('which xclip')
+ xclip = proc:read()
+ proc:close()
+ end
+end
describe('system()', function()
before_each(clear)
+ it('sets the v:shell_error variable', function()
+ eval([[system("sh -c 'exit'")]])
+ eq(0, eval('v:shell_error'))
+ eval([[system("sh -c 'exit 1'")]])
+ 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()
it('returns the program output', function()
eq("echoed", eval('system("echo -n echoed")'))
@@ -76,6 +96,15 @@ describe('system()', function()
end)
end)
end)
+
+ if xclip then
+ describe("with a program that doesn't close stdout", function()
+ it('will exit properly after passing input', function()
+ eq(nil, eval([[system('xclip -i -selection clipboard', 'clip-data')]]))
+ eq('clip-data', eval([[system('xclip -o -selection clipboard')]]))
+ end)
+ end)
+ end
end)
describe('systemlist()', function()
@@ -83,6 +112,17 @@ describe('systemlist()', function()
-- string.
before_each(clear)
+ it('sets the v:shell_error variable', function()
+ eval([[systemlist("sh -c 'exit'")]])
+ eq(0, eval('v:shell_error'))
+ eval([[systemlist("sh -c 'exit 1'")]])
+ 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()
it('splits the output on linefeed characters', function()
eq({'abc', 'def', 'ghi'}, eval([[systemlist("cat -", "abc\ndef\nghi")]]))
@@ -122,4 +162,15 @@ describe('systemlist()', function()
end)
end)
end)
+
+ if xclip then
+ describe("with a program that doesn't close stdout", function()
+ it('will exit properly after passing input', function()
+ eq(nil, eval(
+ "systemlist('xclip -i -selection clipboard', ['clip', 'data'])"))
+ eq({'clip', 'data'}, eval(
+ "systemlist('xclip -o -selection clipboard')"))
+ end)
+ end)
+ end
end)