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
|
2015-04-03 15:44:26 -07:00
|
|
|
local wait = helpers.wait
|
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
|
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')
|
2015-03-25 05:14:47 -07:00
|
|
|
wait()
|
|
|
|
screen = thelpers.screen_setup()
|
|
|
|
end)
|
|
|
|
|
|
|
|
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()
|
|
|
|
local swapfile = nvim('command_output', 'swapname'):gsub('\n', '')
|
|
|
|
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)
|
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")')
|
2018-08-20 09:51:25 -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)
|