test: :terminal should not interrupt Press-ENTER

References #2748
This commit is contained in:
Justin M. Keyes 2016-10-20 22:51:46 +02:00
parent 5bcb7aa8bf
commit 6636e2a259
2 changed files with 46 additions and 10 deletions

View File

@ -121,14 +121,14 @@ describe('jobs', function()
eq({'notification', 'exit', {0, 0}}, next_msg())
end)
it('can preserve newlines', function()
it('preserves newlines', function()
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobsend(j, "a\\n\\nc\\n\\n\\n\\nb\\n\\n")')
eq({'notification', 'stdout',
{0, {'a', '', 'c', '', '', '', 'b', '', ''}}}, next_msg())
end)
it('can preserve NULs', function()
it('preserves NULs', function()
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobsend(j, ["\n123\n", "abc\\nxyz\n", ""])')
eq({'notification', 'stdout', {0, {'\n123\n', 'abc\nxyz\n', ''}}},
@ -137,7 +137,7 @@ describe('jobs', function()
eq({'notification', 'exit', {0, 0}}, next_msg())
end)
it('can avoid sending final newline', function()
it('avoids sending final newline', function()
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobsend(j, ["some data", "without\nfinal nl"])')
eq({'notification', 'stdout', {0, {'some data', 'without\nfinal nl'}}},
@ -146,7 +146,7 @@ describe('jobs', function()
eq({'notification', 'exit', {0, 0}}, next_msg())
end)
it('can close the job streams with jobclose', function()
it('closes the job streams with jobclose', function()
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobclose(j, "stdin")')
eq({'notification', 'exit', {0, 0}}, next_msg())

View File

@ -9,6 +9,42 @@ if helpers.pending_win32(pending) then return end
describe(':terminal', function()
local screen
before_each(function()
clear()
screen = Screen.new(50, 4)
screen:attach({rgb=false})
end)
it("does not interrupt Press-ENTER prompt #2748", function()
-- Ensure that :messages shows Press-ENTER.
source([[
echomsg "msg1"
echomsg "msg2"
]])
-- Invoke a command that emits frequent terminal activity.
execute([[terminal while true; do echo X; done]])
helpers.feed([[<C-\><C-N>]])
screen:expect([[
X |
X |
^X |
|
]])
helpers.sleep(10) -- Let some terminal activity happen.
execute("messages")
screen:expect([[
X |
msg1 |
msg2 |
Press ENTER or type command to continue^ |
]])
end)
end)
describe(':terminal (with fake shell)', function()
local screen
before_each(function()
clear()
screen = Screen.new(50, 4)
@ -20,12 +56,12 @@ describe(':terminal', function()
-- Invokes `:terminal {cmd}` using a fake shell (shell-test.c) which prints
-- the {cmd} and exits immediately .
local function terminal_run_fake_shell_cmd(cmd)
local function terminal_with_fake_shell(cmd)
execute("terminal "..(cmd and cmd or ""))
end
it('with no argument, acts like termopen()', function()
terminal_run_fake_shell_cmd()
terminal_with_fake_shell()
wait()
screen:expect([[
ready $ |
@ -36,7 +72,7 @@ describe(':terminal', function()
end)
it('executes a given command through the shell', function()
terminal_run_fake_shell_cmd('echo hi')
terminal_with_fake_shell('echo hi')
wait()
screen:expect([[
ready $ echo hi |
@ -47,7 +83,7 @@ describe(':terminal', function()
end)
it('allows quotes and slashes', function()
terminal_run_fake_shell_cmd([[echo 'hello' \ "world"]])
terminal_with_fake_shell([[echo 'hello' \ "world"]])
wait()
screen:expect([[
ready $ echo 'hello' \ "world" |
@ -66,14 +102,14 @@ describe(':terminal', function()
end)
it('ignores writes if the backing stream closes', function()
terminal_run_fake_shell_cmd()
terminal_with_fake_shell()
helpers.feed('iiXXXXXXX')
wait()
-- Race: Though the shell exited (and streams were closed by SIGCHLD
-- handler), :terminal cleanup is pending on the main-loop.
-- This write should be ignored (not crash, #5445).
helpers.feed('iiYYYYYYY')
wait()
eq(2, eval("1+1")) -- Still alive?
end)
end)