diff options
Diffstat (limited to 'test/functional/core/exit_spec.lua')
| -rw-r--r-- | test/functional/core/exit_spec.lua | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/test/functional/core/exit_spec.lua b/test/functional/core/exit_spec.lua index 3500cd2919..852d9fd1a2 100644 --- a/test/functional/core/exit_spec.lua +++ b/test/functional/core/exit_spec.lua @@ -12,7 +12,7 @@ local pcall_err = t.pcall_err local exec_capture = n.exec_capture local poke_eventloop = n.poke_eventloop -describe('v:exiting', function() +describe('exit:', function() local cid before_each(function() @@ -20,39 +20,51 @@ describe('v:exiting', function() cid = n.api.nvim_get_chan_info(0).id end) - it('defaults to v:null', function() + it('v:exiting defaults to v:null', function() eq(1, eval('v:exiting is v:null')) + eq('', eval('v:exitreason')) end) local function test_exiting(setup_fn) local function on_setup() - command('autocmd VimLeavePre * call rpcrequest(' .. cid .. ', "exit", "VimLeavePre")') - command('autocmd VimLeave * call rpcrequest(' .. cid .. ', "exit", "VimLeave")') + command(('autocmd QuitPre * call rpcrequest(%d, "exit", "QuitPre")'):format(cid)) + command(('autocmd ExitPre * call rpcrequest(%d, "exit", "ExitPre")'):format(cid)) + command(('autocmd VimLeavePre * call rpcrequest(%d, "exit", "VimLeavePre")'):format(cid)) + command(('autocmd VimLeave * call rpcrequest(%d, "exit", "VimLeave")'):format(cid)) setup_fn() end - local requests_args = {} + local received = {} local function on_request(name, args) eq('exit', name) - table.insert(requests_args, args) - eq(0, eval('v:exiting')) + table.insert(received, args) + eq('quit', eval('v:exitreason')) + if args[1] == 'VimLeavePre' or args[1] == 'VimLeave' then + eq(0, eval('v:exiting')) + end return '' end run(on_request, nil, on_setup) - eq({ { 'VimLeavePre' }, { 'VimLeave' } }, requests_args) + eq({ { 'QuitPre' }, { 'ExitPre' }, { 'VimLeavePre' }, { 'VimLeave' } }, received) end - it('is 0 on normal exit', function() + it('v:exiting=0, v:exitreason=quit on normal exit', function() test_exiting(function() command('quit') end) end) - it('is 0 on exit from Ex mode involving try-catch vim-patch:8.0.0184', function() + it('v:exiting=0, v:exitreason=quit on exit from Ex mode try-catch vim-patch:8.0.0184', function() test_exiting(function() feed('gQ') feed_command('try', 'call NoFunction()', 'catch', 'echo "bye"', 'endtry', 'quit') end) end) + + it('resets v:exitreason if quit is cancelled', function() + n.api.nvim_buf_set_lines(0, 0, -1, true, { 'modified' }) + pcall_err(command, 'quit') + eq('', eval('v:exitreason')) + end) end) describe(':cquit', function() |
