test(ex_terminal_spec): match descriptions (#26314)

This commit is contained in:
zeertzjq 2023-11-30 08:56:21 +08:00 committed by GitHub
parent 463b577afb
commit 62dff43947
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -159,32 +159,22 @@ local function test_terminal_with_fake_shell(backslash)
nvim('set_option_value', 'shellxquote', '', {}) nvim('set_option_value', 'shellxquote', '', {})
end) end)
-- Invokes `:terminal {cmd}` using a fake shell (shell-test.c) which prints
-- 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() it('with no argument, acts like termopen()', function()
-- Use the EXIT subcommand to end the process with a non-zero exit code to command('autocmd! nvim_terminal TermClose')
-- prevent the buffer from closing automatically feed_command('terminal')
nvim('set_option_value', 'shellcmdflag', 'EXIT', {})
terminal_with_fake_shell(1)
retry(nil, 4 * screen.timeout, function() retry(nil, 4 * screen.timeout, function()
screen:expect([[ screen:expect([[
^ | ^ready $ |
[Process exited 1] | [Process exited 0] |
| |
:terminal 1 | :terminal |
]]) ]])
end) end)
end) end)
it("with no argument, and 'shell' is set to empty string", function() it("with no argument, and 'shell' is set to empty string", function()
nvim('set_option_value', 'shell', '', {}) nvim('set_option_value', 'shell', '', {})
terminal_with_fake_shell() feed_command('terminal')
screen:expect([[ screen:expect([[
^ | ^ |
~ | ~ |
@ -194,11 +184,11 @@ local function test_terminal_with_fake_shell(backslash)
end) end)
it("with no argument, but 'shell' has arguments, acts like termopen()", function() it("with no argument, but 'shell' has arguments, acts like termopen()", function()
nvim('set_option_value', 'shell', shell_path ..' -t jeff', {}) nvim('set_option_value', 'shell', shell_path ..' INTERACT', {})
terminal_with_fake_shell() feed_command('terminal')
screen:expect([[ screen:expect([[
^jeff $ | ^interact $ |
[Process exited 0] | |
| |
:terminal | :terminal |
]]) ]])
@ -206,7 +196,7 @@ local function test_terminal_with_fake_shell(backslash)
it('executes a given command through the shell', function() it('executes a given command through the shell', function()
command('set shellxquote=') -- win: avoid extra quotes command('set shellxquote=') -- win: avoid extra quotes
terminal_with_fake_shell('echo hi') feed_command('terminal echo hi')
screen:expect([[ screen:expect([[
^ready $ echo hi | ^ready $ echo hi |
| |
@ -218,7 +208,7 @@ local function test_terminal_with_fake_shell(backslash)
it("executes a given command through the shell, when 'shell' has arguments", function() it("executes a given command through the shell, when 'shell' has arguments", function()
nvim('set_option_value', 'shell', shell_path ..' -t jeff', {}) nvim('set_option_value', 'shell', shell_path ..' -t jeff', {})
command('set shellxquote=') -- win: avoid extra quotes command('set shellxquote=') -- win: avoid extra quotes
terminal_with_fake_shell('echo hi') feed_command('terminal echo hi')
screen:expect([[ screen:expect([[
^jeff $ echo hi | ^jeff $ echo hi |
| |
@ -229,7 +219,7 @@ local function test_terminal_with_fake_shell(backslash)
it('allows quotes and slashes', function() it('allows quotes and slashes', function()
command('set shellxquote=') -- win: avoid extra quotes command('set shellxquote=') -- win: avoid extra quotes
terminal_with_fake_shell([[echo 'hello' \ "world"]]) feed_command([[terminal echo 'hello' \ "world"]])
screen:expect([[ screen:expect([[
^ready $ echo 'hello' \ "world" | ^ready $ echo 'hello' \ "world" |
| |
@ -247,7 +237,8 @@ local function test_terminal_with_fake_shell(backslash)
end) end)
it('ignores writes if the backing stream closes', function() it('ignores writes if the backing stream closes', function()
terminal_with_fake_shell() command('autocmd! nvim_terminal TermClose')
feed_command('terminal')
feed('iiXXXXXXX') feed('iiXXXXXXX')
poke_eventloop() poke_eventloop()
-- Race: Though the shell exited (and streams were closed by SIGCHLD -- Race: Though the shell exited (and streams were closed by SIGCHLD
@ -258,19 +249,20 @@ local function test_terminal_with_fake_shell(backslash)
end) end)
it('works with findfile()', function() it('works with findfile()', function()
command('autocmd! nvim_terminal TermClose')
feed_command('terminal') feed_command('terminal')
eq('term://', string.match(eval('bufname("%")'), "^term://")) eq('term://', string.match(eval('bufname("%")'), "^term://"))
eq('scripts/shadacat.py', eval('findfile("scripts/shadacat.py", ".")')) eq('scripts/shadacat.py', eval('findfile("scripts/shadacat.py", ".")'))
end) end)
it('works with :find', function() it('works with :find', function()
nvim('set_option_value', 'shellcmdflag', 'EXIT', {}) command('autocmd! nvim_terminal TermClose')
terminal_with_fake_shell(1) feed_command('terminal')
screen:expect([[ screen:expect([[
^ | ^ready $ |
[Process exited 1] | [Process exited 0] |
| |
:terminal 1 | :terminal |
]]) ]])
eq('term://', string.match(eval('bufname("%")'), "^term://")) eq('term://', string.match(eval('bufname("%")'), "^term://"))
feed([[<C-\><C-N>]]) feed([[<C-\><C-N>]])
@ -284,7 +276,7 @@ local function test_terminal_with_fake_shell(backslash)
it('works with gf', function() it('works with gf', function()
command('set shellxquote=') -- win: avoid extra quotes command('set shellxquote=') -- win: avoid extra quotes
terminal_with_fake_shell([[echo "scripts/shadacat.py"]]) feed_command([[terminal echo "scripts/shadacat.py"]])
retry(nil, 4 * screen.timeout, function() retry(nil, 4 * screen.timeout, function()
screen:expect([[ screen:expect([[
^ready $ echo "scripts/shadacat.py" | ^ready $ echo "scripts/shadacat.py" |