2016-11-29 12:55:41 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
|
2021-09-01 09:42:53 -07:00
|
|
|
local assert_alive = helpers.assert_alive
|
2016-11-29 12:55:41 -07:00
|
|
|
local command = helpers.command
|
2018-03-24 03:17:36 -07:00
|
|
|
local feed_command = helpers.feed_command
|
2022-08-11 18:04:08 -07:00
|
|
|
local feed = helpers.feed
|
2016-11-29 12:55:41 -07:00
|
|
|
local eval = helpers.eval
|
2017-09-28 08:12:56 -07:00
|
|
|
local eq = helpers.eq
|
2016-11-29 12:55:41 -07:00
|
|
|
local run = helpers.run
|
2017-09-28 08:12:56 -07:00
|
|
|
local funcs = helpers.funcs
|
|
|
|
local nvim_prog = helpers.nvim_prog
|
2021-09-19 02:29:37 -07:00
|
|
|
local pcall_err = helpers.pcall_err
|
|
|
|
local exec_capture = helpers.exec_capture
|
2020-10-19 11:17:51 -07:00
|
|
|
local poke_eventloop = helpers.poke_eventloop
|
2016-11-29 12:55:41 -07:00
|
|
|
|
|
|
|
describe('v:exiting', function()
|
|
|
|
local cid
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
helpers.clear()
|
|
|
|
cid = helpers.nvim('get_api_info')[1]
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('defaults to v:null', function()
|
|
|
|
eq(1, eval('v:exiting is v:null'))
|
|
|
|
end)
|
|
|
|
|
2023-02-09 04:48:17 -07:00
|
|
|
local function test_exiting(setup_fn)
|
2016-11-29 12:55:41 -07:00
|
|
|
local function on_setup()
|
2023-02-09 04:48:17 -07:00
|
|
|
command('autocmd VimLeavePre * call rpcrequest('..cid..', "exit", "VimLeavePre")')
|
|
|
|
command('autocmd VimLeave * call rpcrequest('..cid..', "exit", "VimLeave")')
|
|
|
|
setup_fn()
|
2016-11-29 12:55:41 -07:00
|
|
|
end
|
2023-02-09 04:48:17 -07:00
|
|
|
local requests_args = {}
|
|
|
|
local function on_request(name, args)
|
|
|
|
eq('exit', name)
|
|
|
|
table.insert(requests_args, args)
|
2016-11-29 12:55:41 -07:00
|
|
|
eq(0, eval('v:exiting'))
|
|
|
|
return ''
|
|
|
|
end
|
|
|
|
run(on_request, nil, on_setup)
|
2023-02-09 04:48:17 -07:00
|
|
|
eq({{'VimLeavePre'}, {'VimLeave'}}, requests_args)
|
|
|
|
end
|
|
|
|
|
|
|
|
it('is 0 on normal exit', function()
|
|
|
|
test_exiting(function()
|
|
|
|
command('quit')
|
|
|
|
end)
|
2016-11-29 12:55:41 -07:00
|
|
|
end)
|
2023-02-09 04:48:17 -07:00
|
|
|
|
2022-08-11 18:04:08 -07:00
|
|
|
it('is 0 on exit from Ex mode involving try-catch vim-patch:8.0.0184', function()
|
2023-02-09 04:48:17 -07:00
|
|
|
test_exiting(function()
|
2022-08-11 18:04:08 -07:00
|
|
|
feed('gQ')
|
|
|
|
feed_command('try', 'call NoFunction()', 'catch', 'echo "bye"', 'endtry', 'quit')
|
2023-02-09 04:48:17 -07:00
|
|
|
end)
|
2018-03-24 03:17:36 -07:00
|
|
|
end)
|
2017-09-28 08:12:56 -07:00
|
|
|
end)
|
2016-11-29 12:55:41 -07:00
|
|
|
|
2017-09-28 08:12:56 -07:00
|
|
|
describe(':cquit', function()
|
|
|
|
local function test_cq(cmdline, exit_code, redir_msg)
|
|
|
|
if redir_msg then
|
2021-09-19 02:29:37 -07:00
|
|
|
eq(redir_msg, pcall_err(function() return exec_capture(cmdline) end))
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2021-09-01 09:42:53 -07:00
|
|
|
assert_alive()
|
2017-09-28 08:12:56 -07:00
|
|
|
else
|
|
|
|
funcs.system({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '--cmd', cmdline})
|
|
|
|
eq(exit_code, eval('v:shell_error'))
|
2016-11-29 12:55:41 -07:00
|
|
|
end
|
2017-09-28 08:12:56 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
helpers.clear()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('exits with non-zero after :cquit', function()
|
|
|
|
test_cq('cquit', 1, nil)
|
2016-11-29 12:55:41 -07:00
|
|
|
end)
|
|
|
|
|
2017-09-28 08:12:56 -07:00
|
|
|
it('exits with non-zero after :cquit 123', function()
|
|
|
|
test_cq('cquit 123', 123, nil)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('exits with non-zero after :123 cquit', function()
|
|
|
|
test_cq('123 cquit', 123, nil)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('exits with 0 after :cquit 0', function()
|
|
|
|
test_cq('cquit 0', 0, nil)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('exits with 0 after :0 cquit', function()
|
|
|
|
test_cq('0 cquit', 0, nil)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('exits with redir msg for multiple exit codes after :cquit 1 2', function()
|
2023-03-25 09:58:48 -07:00
|
|
|
test_cq('cquit 1 2', nil, 'nvim_exec2(): Vim(cquit):E488: Trailing characters: 2: cquit 1 2')
|
2017-09-28 08:12:56 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('exits with redir msg for non-number exit code after :cquit X', function()
|
2023-03-25 09:58:48 -07:00
|
|
|
test_cq('cquit X', nil, 'nvim_exec2(): Vim(cquit):E488: Trailing characters: X: cquit X')
|
2017-09-28 08:12:56 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('exits with redir msg for negative exit code after :cquit -1', function()
|
2023-03-25 09:58:48 -07:00
|
|
|
test_cq('cquit -1', nil, 'nvim_exec2(): Vim(cquit):E488: Trailing characters: -1: cquit -1')
|
2017-09-28 08:12:56 -07:00
|
|
|
end)
|
2016-11-29 12:55:41 -07:00
|
|
|
end)
|