commit 673ee213e9d0900b1fa2638dc5373ee8167ed4fa
parent 0c89854da1893c9d9d5da1994bea69df31fc2a6f
Author: Gregory Anders <greg@gpanders.com>
Date: Sat, 4 Sep 2021 15:28:08 -0600
test: update tests for auto-closing :term buffers
The terminal buffer closes automatically when using `:terminal` and the
command exits without an error. This messes up some tests that expect
the terminal buffer to still be open. We can force the buffer not to
close by passing an argument to `:terminal`. This can be anything, since
the shell-test stub simply prints whatever argument it's given.
Diffstat:
4 files changed, 30 insertions(+), 20 deletions(-)
diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua
@@ -103,12 +103,13 @@ describe('autocmd TermClose', function()
it('reports the correct <abuf>', function()
command('set hidden')
+ command('set shellcmdflag=EXE')
command('autocmd TermClose * let g:abuf = expand("<abuf>")')
command('edit foo')
command('edit bar')
eq(2, eval('bufnr("%")'))
- command('terminal')
+ command('terminal ls')
retry(nil, nil, function() eq(3, eval('bufnr("%")')) end)
command('buffer 1')
diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua
@@ -137,23 +137,29 @@ describe(':terminal (with fake shell)', function()
-- shell-test.c is a fake shell that prints its arguments and exits.
nvim('set_option_value', 'shell', testprg('shell-test'), {})
nvim('set_option_value', 'shellcmdflag', 'EXE', {})
+ nvim('set_option_value', 'shellxquote', '', {})
end)
-- Invokes `:terminal {cmd}` using a fake shell (shell-test.c) which prints
- -- the {cmd} and exits immediately .
+ -- the {cmd} and exits immediately.
+ -- When no argument is given and the exit code is zero, the terminal buffer
+ -- closes automatically.
local function terminal_with_fake_shell(cmd)
feed_command("terminal "..(cmd and cmd or ""))
end
it('with no argument, acts like termopen()', function()
skip(is_os('win'))
- terminal_with_fake_shell()
+ -- Use the EXIT subcommand to end the process with a non-zero exit code to
+ -- prevent the buffer from closing automatically
+ nvim('set_option_value', 'shellcmdflag', 'EXIT', {})
+ terminal_with_fake_shell(1)
retry(nil, 4 * screen.timeout, function()
screen:expect([[
- ^ready $ |
- [Process exited 0] |
+ ^ |
+ [Process exited 1] |
|
- :terminal |
+ :terminal 1 |
]])
end)
end)
@@ -245,12 +251,13 @@ describe(':terminal (with fake shell)', function()
it('works with :find', function()
skip(is_os('win'))
- terminal_with_fake_shell()
+ nvim('set_option_value', 'shellcmdflag', 'EXIT', {})
+ terminal_with_fake_shell(1)
screen:expect([[
- ^ready $ |
- [Process exited 0] |
+ ^ |
+ [Process exited 1] |
|
- :terminal |
+ :terminal 1 |
]])
eq('term://', string.match(eval('bufname("%")'), "^term://"))
feed([[<C-\><C-N>]])
diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua
@@ -514,7 +514,9 @@ describe("'scrollback' option", function()
-- _Global_ scrollback=-1 defaults :terminal to 10_000.
command('setglobal scrollback=-1')
- command('terminal')
+ -- Pass a command to prevent the terminal buffer from automatically
+ -- closing. The ':' command is just a no-op.
+ command('terminal :')
eq(10000, meths.get_option_value('scrollback', {}))
-- _Local_ scrollback=-1 in :terminal forces the _maximum_.
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
@@ -2075,26 +2075,26 @@ describe('TUI FocusGained/FocusLost', function()
end)
it('in terminal-mode', function()
- feed_data(':set shell='..testprg('shell-test')..'\n')
+ feed_data(':set shell='..testprg('shell-test')..' shellcmdflag=EXE\n')
feed_data(':set noshowmode laststatus=0\n')
- feed_data(':terminal\n')
+ feed_data(':terminal zia\n')
-- Wait for terminal to be ready.
screen:expect{grid=[[
- {1:r}eady $ |
- [Process exited 0] |
+ {1:r}eady $ zia |
|
+ [Process exited 0] |
|
|
- :terminal |
+ :terminal zia |
{3:-- TERMINAL --} |
]]}
feed_data('\027[I')
screen:expect{grid=[[
- {1:r}eady $ |
- [Process exited 0] |
+ {1:r}eady $ zia |
|
+ [Process exited 0] |
|
|
gained |
@@ -2103,9 +2103,9 @@ describe('TUI FocusGained/FocusLost', function()
feed_data('\027[O')
screen:expect([[
- {1:r}eady $ |
- [Process exited 0] |
+ {1:r}eady $ zia |
|
+ [Process exited 0] |
|
|
lost |