aboutsummaryrefslogtreecommitdiff
path: root/test/functional/terminal/buffer_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/terminal/buffer_spec.lua')
-rw-r--r--test/functional/terminal/buffer_spec.lua130
1 files changed, 85 insertions, 45 deletions
diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua
index 8a535d6864..4d6b125f9f 100644
--- a/test/functional/terminal/buffer_spec.lua
+++ b/test/functional/terminal/buffer_spec.lua
@@ -2,16 +2,16 @@ local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers')
local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim
local wait = helpers.wait
-local eval, execute, source = helpers.eval, helpers.execute, helpers.source
+local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source
local eq, neq = helpers.eq, helpers.neq
-
+local write_file = helpers.write_file
describe('terminal buffer', function()
local screen
before_each(function()
clear()
- execute('set modifiable swapfile undolevels=20')
+ feed_command('set modifiable swapfile undolevels=20')
wait()
screen = thelpers.screen_setup()
end)
@@ -21,11 +21,11 @@ describe('terminal buffer', function()
feed('<c-\\><c-n>:set bufhidden=wipe<cr>:enew<cr>')
screen:expect([[
^ |
- ~ |
- ~ |
- ~ |
- ~ |
- ~ |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
:enew |
]])
end)
@@ -34,11 +34,11 @@ describe('terminal buffer', function()
feed(':bnext:l<esc>')
screen:expect([[
^ |
- ~ |
- ~ |
- ~ |
- ~ |
- ~ |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
|
]])
end)
@@ -49,11 +49,11 @@ describe('terminal buffer', function()
feed('<c-\\><c-n>')
screen:expect([[
tty ready |
- {2: } |
+ {2:^ } |
+ |
|
|
|
- ^ |
|
]])
end)
@@ -73,18 +73,18 @@ describe('terminal buffer', function()
feed('<c-\\><c-n>dd')
screen:expect([[
tty ready |
- {2: } |
+ {2:^ } |
|
|
|
- ^ |
- E21: Cannot make changes, 'modifiable' is off |
+ |
+ {8:E21: Cannot make changes, 'modifiable' is off} |
]])
end)
it('sends data to the terminal when the "put" operator is used', function()
feed('<c-\\><c-n>gg"ayj')
- execute('let @a = "appended " . @a')
+ feed_command('let @a = "appended " . @a')
feed('"ap"ap')
screen:expect([[
^tty ready |
@@ -110,8 +110,8 @@ describe('terminal buffer', function()
it('sends data to the terminal when the ":put" command is used', function()
feed('<c-\\><c-n>gg"ayj')
- execute('let @a = "appended " . @a')
- execute('put a')
+ feed_command('let @a = "appended " . @a')
+ feed_command('put a')
screen:expect([[
^tty ready |
appended tty ready |
@@ -122,7 +122,7 @@ describe('terminal buffer', function()
:put a |
]])
-- line argument is only used to move the cursor
- execute('6put a')
+ feed_command('6put a')
screen:expect([[
tty ready |
appended tty ready |
@@ -138,35 +138,36 @@ describe('terminal buffer', function()
feed('<c-\\><c-n>:bd!<cr>')
screen:expect([[
^ |
- ~ |
- ~ |
- ~ |
- ~ |
- ~ |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
:bd! |
]])
- execute('bnext')
+ feed_command('bnext')
screen:expect([[
^ |
- ~ |
- ~ |
- ~ |
- ~ |
- ~ |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
:bnext |
]])
end)
it('handles loss of focus gracefully', function()
+ if helpers.pending_win32(pending) then return end
-- Change the statusline to avoid printing the file name, which varies.
nvim('set_option', 'statusline', '==========')
- execute('set laststatus=0')
+ feed_command('set laststatus=0')
-- Save the buffer number of the terminal for later testing.
local tbuf = eval('bufnr("%")')
source([[
- function! SplitWindow()
+ function! SplitWindow(id, data, event)
new
call feedkeys("iabc\<Esc>")
endfunction
@@ -180,8 +181,8 @@ describe('terminal buffer', function()
-- We should be in a new buffer now.
screen:expect([[
ab^c |
- ~ |
- ========== |
+ {4:~ }|
+ {5:========== }|
rows: 2, cols: 50 |
{2: } |
{1:========== }|
@@ -189,20 +190,59 @@ describe('terminal buffer', function()
]])
neq(tbuf, eval('bufnr("%")'))
- execute('quit!') -- Should exit the new window, not the terminal.
+ feed_command('quit!') -- Should exit the new window, not the terminal.
eq(tbuf, eval('bufnr("%")'))
- execute('set laststatus=1') -- Restore laststatus to the default.
+ feed_command('set laststatus=1') -- Restore laststatus to the default.
end)
it('term_close() use-after-free #4393', function()
- if eval("executable('yes')") == 0 then
- pending('missing "yes" command')
- return
- end
- execute('terminal yes')
+ feed_command('terminal yes')
feed([[<C-\><C-n>]])
- execute('bdelete!')
+ feed_command('bdelete!')
+ end)
+
+ describe('handles confirmations', function()
+ it('with :confirm', function()
+ feed_command('terminal')
+ feed('<c-\\><c-n>')
+ feed_command('confirm bdelete')
+ screen:expect{any='Close "term://', attr_ignore=true}
+ end)
+
+ it('with &confirm', function()
+ feed_command('terminal')
+ feed('<c-\\><c-n>')
+ feed_command('bdelete')
+ screen:expect{any='E89', attr_ignore=true}
+ feed('<cr>')
+ eq('terminal', eval('&buftype'))
+ feed_command('set confirm | bdelete')
+ screen:expect{any='Close "term://', attr_ignore=true}
+ feed('y')
+ neq('terminal', eval('&buftype'))
+ end)
end)
end)
+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()
+ feed_command('edit ' .. testfilename)
+ -- Move cursor away from the beginning of the line
+ feed('$')
+ -- Let termopen() modify the buffer
+ feed_command('call termopen("echo")')
+ eq(2, eval('1+1')) -- check nvim still running
+ feed_command('bdelete!')
+ end)
+end)