2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2015-03-25 05:14:47 -07:00
|
|
|
local thelpers = require('test.functional.terminal.helpers')
|
|
|
|
local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim
|
2020-10-19 11:17:51 -07:00
|
|
|
local poke_eventloop = helpers.poke_eventloop
|
2017-04-08 14:12:26 -07:00
|
|
|
local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source
|
2015-04-03 15:44:26 -07:00
|
|
|
local eq, neq = helpers.eq, helpers.neq
|
2017-03-04 12:12:57 -07:00
|
|
|
local write_file = helpers.write_file
|
2019-11-28 21:09:03 -07:00
|
|
|
local command= helpers.command
|
2020-03-10 17:59:13 -07:00
|
|
|
local exc_exec = helpers.exc_exec
|
2021-08-16 20:06:49 -07:00
|
|
|
local matches = helpers.matches
|
2015-03-25 05:14:47 -07:00
|
|
|
|
2018-04-28 16:39:21 -07:00
|
|
|
describe(':terminal buffer', function()
|
2015-03-25 05:14:47 -07:00
|
|
|
local screen
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('set modifiable swapfile undolevels=20')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2015-03-25 05:14:47 -07:00
|
|
|
screen = thelpers.screen_setup()
|
|
|
|
end)
|
|
|
|
|
2020-05-04 21:04:47 -07:00
|
|
|
it('terminal-mode forces various options', function()
|
|
|
|
feed([[<C-\><C-N>]])
|
|
|
|
command('setlocal cursorline cursorcolumn scrolloff=4 sidescrolloff=7')
|
|
|
|
eq({ 1, 1, 4, 7 }, eval('[&l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]'))
|
|
|
|
eq('n', eval('mode()'))
|
|
|
|
|
|
|
|
-- Enter terminal-mode ("insert" mode in :terminal).
|
|
|
|
feed('i')
|
|
|
|
eq('t', eval('mode()'))
|
|
|
|
eq({ 0, 0, 0, 0 }, eval('[&l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]'))
|
|
|
|
end)
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
describe('when a new file is edited', function()
|
|
|
|
before_each(function()
|
|
|
|
feed('<c-\\><c-n>:set bufhidden=wipe<cr>:enew<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2016-08-09 08:01:56 -07:00
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
2015-03-25 05:14:47 -07:00
|
|
|
:enew |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('will hide the buffer, ignoring the bufhidden option', function()
|
|
|
|
feed(':bnext:l<esc>')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2016-08-09 08:01:56 -07:00
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
2015-03-25 05:14:47 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('swap and undo', function()
|
|
|
|
before_each(function()
|
|
|
|
feed('<c-\\><c-n>')
|
|
|
|
screen:expect([[
|
|
|
|
tty ready |
|
2017-02-26 19:10:55 -07:00
|
|
|
{2:^ } |
|
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('does not create swap files', function()
|
2019-12-01 23:43:16 -07:00
|
|
|
local swapfile = nvim('exec', 'swapname', true):gsub('\n', '')
|
2015-03-25 05:14:47 -07:00
|
|
|
eq(nil, io.open(swapfile))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('does not create undofiles files', function()
|
|
|
|
local undofile = nvim('eval', 'undofile(bufname("%"))')
|
|
|
|
eq(nil, io.open(undofile))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('cannot be modified directly', function()
|
|
|
|
feed('<c-\\><c-n>dd')
|
|
|
|
screen:expect([[
|
|
|
|
tty ready |
|
2017-02-26 19:10:55 -07:00
|
|
|
{2:^ } |
|
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-09 08:01:56 -07:00
|
|
|
{8:E21: Cannot make changes, 'modifiable' is off} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('sends data to the terminal when the "put" operator is used', function()
|
|
|
|
feed('<c-\\><c-n>gg"ayj')
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('let @a = "appended " . @a')
|
2015-03-25 05:14:47 -07:00
|
|
|
feed('"ap"ap')
|
|
|
|
screen:expect([[
|
|
|
|
^tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
{2: } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:let @a = "appended " . @a |
|
|
|
|
]])
|
|
|
|
-- operator count is also taken into consideration
|
|
|
|
feed('3"ap')
|
|
|
|
screen:expect([[
|
|
|
|
^tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
:let @a = "appended " . @a |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('sends data to the terminal when the ":put" command is used', function()
|
|
|
|
feed('<c-\\><c-n>gg"ayj')
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('let @a = "appended " . @a')
|
|
|
|
feed_command('put a')
|
2015-03-25 05:14:47 -07:00
|
|
|
screen:expect([[
|
|
|
|
^tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
{2: } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:put a |
|
|
|
|
]])
|
|
|
|
-- line argument is only used to move the cursor
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('6put a')
|
2015-03-25 05:14:47 -07:00
|
|
|
screen:expect([[
|
|
|
|
tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
appended tty ready |
|
|
|
|
{2: } |
|
|
|
|
|
|
|
|
|
^ |
|
|
|
|
:6put a |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('can be deleted', function()
|
|
|
|
feed('<c-\\><c-n>:bd!<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2016-08-09 08:01:56 -07:00
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
2015-03-25 05:14:47 -07:00
|
|
|
:bd! |
|
|
|
|
]])
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('bnext')
|
2015-03-25 05:14:47 -07:00
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2016-08-09 08:01:56 -07:00
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
2015-03-25 05:14:47 -07:00
|
|
|
:bnext |
|
|
|
|
]])
|
|
|
|
end)
|
2015-04-03 15:44:26 -07:00
|
|
|
|
|
|
|
it('handles loss of focus gracefully', function()
|
2016-05-14 19:56:11 -07:00
|
|
|
-- Change the statusline to avoid printing the file name, which varies.
|
2015-04-03 15:44:26 -07:00
|
|
|
nvim('set_option', 'statusline', '==========')
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('set laststatus=0')
|
2015-04-03 15:44:26 -07:00
|
|
|
|
|
|
|
-- Save the buffer number of the terminal for later testing.
|
|
|
|
local tbuf = eval('bufnr("%")')
|
2019-08-11 05:28:19 -07:00
|
|
|
local exitcmd = helpers.iswin()
|
|
|
|
and "['cmd', '/c', 'exit']"
|
|
|
|
or "['sh', '-c', 'exit']"
|
2015-04-03 15:44:26 -07:00
|
|
|
source([[
|
2016-11-11 13:13:55 -07:00
|
|
|
function! SplitWindow(id, data, event)
|
2015-04-03 15:44:26 -07:00
|
|
|
new
|
2015-04-05 10:20:08 -07:00
|
|
|
call feedkeys("iabc\<Esc>")
|
2015-04-03 15:44:26 -07:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
startinsert
|
2019-08-11 05:28:19 -07:00
|
|
|
call jobstart(]]..exitcmd..[[, {'on_exit': function("SplitWindow")})
|
2015-04-05 10:20:08 -07:00
|
|
|
call feedkeys("\<C-\>", 't') " vim will expect <C-n>, but be exited out of
|
|
|
|
" the terminal before it can be entered.
|
2015-04-03 15:44:26 -07:00
|
|
|
]])
|
|
|
|
|
|
|
|
-- We should be in a new buffer now.
|
|
|
|
screen:expect([[
|
2015-04-05 10:20:08 -07:00
|
|
|
ab^c |
|
2016-08-09 08:01:56 -07:00
|
|
|
{4:~ }|
|
|
|
|
{5:========== }|
|
2015-04-03 15:44:26 -07:00
|
|
|
rows: 2, cols: 50 |
|
|
|
|
{2: } |
|
|
|
|
{1:========== }|
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
|
|
|
|
neq(tbuf, eval('bufnr("%")'))
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('quit!') -- Should exit the new window, not the terminal.
|
2015-04-03 15:44:26 -07:00
|
|
|
eq(tbuf, eval('bufnr("%")'))
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('set laststatus=1') -- Restore laststatus to the default.
|
2015-04-03 15:44:26 -07:00
|
|
|
end)
|
2016-05-14 19:56:11 -07:00
|
|
|
|
|
|
|
it('term_close() use-after-free #4393', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('terminal yes')
|
2016-05-14 19:56:11 -07:00
|
|
|
feed([[<C-\><C-n>]])
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('bdelete!')
|
2016-05-14 19:56:11 -07:00
|
|
|
end)
|
2018-07-12 05:57:20 -07:00
|
|
|
|
|
|
|
describe('handles confirmations', function()
|
|
|
|
it('with :confirm', function()
|
|
|
|
feed_command('terminal')
|
|
|
|
feed('<c-\\><c-n>')
|
|
|
|
feed_command('confirm bdelete')
|
2019-10-12 04:29:51 -07:00
|
|
|
screen:expect{any='Close "term://'}
|
2018-07-12 05:57:20 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('with &confirm', function()
|
|
|
|
feed_command('terminal')
|
|
|
|
feed('<c-\\><c-n>')
|
|
|
|
feed_command('bdelete')
|
2019-10-12 04:29:51 -07:00
|
|
|
screen:expect{any='E89'}
|
2018-07-12 05:57:20 -07:00
|
|
|
feed('<cr>')
|
|
|
|
eq('terminal', eval('&buftype'))
|
|
|
|
feed_command('set confirm | bdelete')
|
2019-10-12 04:29:51 -07:00
|
|
|
screen:expect{any='Close "term://'}
|
2018-07-12 05:57:20 -07:00
|
|
|
feed('y')
|
|
|
|
neq('terminal', eval('&buftype'))
|
|
|
|
end)
|
|
|
|
end)
|
2019-11-28 21:09:03 -07:00
|
|
|
|
|
|
|
it('it works with set rightleft #11438', function()
|
|
|
|
local columns = eval('&columns')
|
|
|
|
feed(string.rep('a', columns))
|
|
|
|
command('set rightleft')
|
|
|
|
screen:expect([[
|
|
|
|
ydaer ytt|
|
|
|
|
{1:a}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]])
|
|
|
|
command('bdelete!')
|
|
|
|
end)
|
2020-03-10 17:59:13 -07:00
|
|
|
|
2021-08-28 08:58:27 -07:00
|
|
|
it('requires bang (!) to close a running job #15402', function()
|
2020-03-10 17:59:13 -07:00
|
|
|
eq('Vim(wqall):E948: Job still running', exc_exec('wqall'))
|
2021-08-28 08:58:27 -07:00
|
|
|
for _, cmd in ipairs({ 'bdelete', '%bdelete', 'bwipeout', 'bunload' }) do
|
|
|
|
matches('^Vim%('..cmd:gsub('%%', '')..'%):E89: term://.*tty%-test.* will be killed %(add %! to override%)$',
|
|
|
|
exc_exec(cmd))
|
|
|
|
end
|
2021-08-16 20:06:49 -07:00
|
|
|
command('call jobstop(&channel)')
|
2021-08-28 08:58:27 -07:00
|
|
|
assert(0 >= eval('jobwait([&channel], 1000)[0]'))
|
2021-08-16 20:06:49 -07:00
|
|
|
command('bdelete')
|
2020-03-10 17:59:13 -07:00
|
|
|
end)
|
2021-02-26 18:55:32 -07:00
|
|
|
|
2021-08-28 08:58:27 -07:00
|
|
|
it('stops running jobs with :quit', function()
|
|
|
|
-- Open in a new window to avoid terminating the nvim instance
|
|
|
|
command('split')
|
|
|
|
command('terminal')
|
|
|
|
command('set nohidden')
|
|
|
|
command('quit')
|
|
|
|
end)
|
|
|
|
|
2021-02-26 18:55:32 -07:00
|
|
|
it('does not segfault when pasting empty buffer #13955', function()
|
|
|
|
feed_command('terminal')
|
|
|
|
feed('<c-\\><c-n>')
|
|
|
|
feed_command('put a') -- buffer a is empty
|
2021-02-27 08:38:38 -07:00
|
|
|
helpers.assert_alive()
|
2021-02-26 18:55:32 -07:00
|
|
|
end)
|
2015-03-25 05:14:47 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-04 12:12:57 -07:00
|
|
|
describe('No heap-buffer-overflow when using', function()
|
|
|
|
local testfilename = 'Xtestfile-functional-terminal-buffers_spec'
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
write_file(testfilename, "aaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
os.remove(testfilename)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('termopen(echo) #3161', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('edit ' .. testfilename)
|
2017-03-04 12:12:57 -07:00
|
|
|
-- Move cursor away from the beginning of the line
|
|
|
|
feed('$')
|
|
|
|
-- Let termopen() modify the buffer
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('call termopen("echo")')
|
2021-02-27 09:02:56 -07:00
|
|
|
eq(2, eval('1+1')) -- check nvim still running
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('bdelete!')
|
2017-03-04 12:12:57 -07:00
|
|
|
end)
|
|
|
|
end)
|
2020-07-27 08:51:41 -07:00
|
|
|
|
|
|
|
describe('No heap-buffer-overflow when', function()
|
|
|
|
it('set nowrap and send long line #11548', function()
|
|
|
|
feed_command('set nowrap')
|
|
|
|
feed_command('autocmd TermOpen * startinsert')
|
|
|
|
feed_command('call feedkeys("4000ai\\<esc>:terminal!\\<cr>")')
|
2021-02-27 09:02:56 -07:00
|
|
|
eq(2, eval('1+1'))
|
2020-07-27 08:51:41 -07:00
|
|
|
end)
|
|
|
|
end)
|