diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2016-10-11 23:14:18 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2016-10-12 04:33:53 +0200 |
commit | ef4676ed5bd18fc2d5fb52b52304d59d94e9e806 (patch) | |
tree | 5fcd8d88f328e72b65b17fec35af3720371e1bee | |
parent | 1dde512498d2fa9f3427861b5d4f894c778f992b (diff) | |
download | rneovim-ef4676ed5bd18fc2d5fb52b52304d59d94e9e806.tar.gz rneovim-ef4676ed5bd18fc2d5fb52b52304d59d94e9e806.tar.bz2 rneovim-ef4676ed5bd18fc2d5fb52b52304d59d94e9e806.zip |
test/terminal: Cover race when :term shell process exits.
References #5445
See https://github.com/neovim/neovim/pull/5445#issuecomment-252529766
-rw-r--r-- | src/nvim/terminal.c | 2 | ||||
-rw-r--r-- | test/functional/terminal/ex_terminal_spec.lua | 26 |
2 files changed, 23 insertions, 5 deletions
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 8401343d7a..499716a7a8 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -366,10 +366,10 @@ void terminal_resize(Terminal *term, uint16_t width, uint16_t height) void terminal_enter(void) { buf_T *buf = curbuf; + assert(buf->terminal); // Should only be called when curbuf has a terminal. TerminalState state, *s = &state; memset(s, 0, sizeof(TerminalState)); s->term = buf->terminal; - assert(s->term && "should only be called when curbuf has a terminal"); // Ensure the terminal is properly sized. terminal_resize(s->term, 0, 0); diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 6f929f17e4..09b4eaa8d5 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -13,13 +13,19 @@ describe(':terminal', function() clear() screen = Screen.new(50, 4) screen:attach({rgb=false}) + -- shell-test.c is a fake shell that prints its arguments and exits. nvim('set_option', 'shell', nvim_dir..'/shell-test') nvim('set_option', 'shellcmdflag', 'EXE') - end) + -- 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) + execute("terminal "..(cmd and cmd or "")) + end + it('with no argument, acts like termopen()', function() - execute('terminal') + terminal_run_fake_shell_cmd() wait() screen:expect([[ ready $ | @@ -30,7 +36,7 @@ describe(':terminal', function() end) it('executes a given command through the shell', function() - execute('terminal echo hi') + terminal_run_fake_shell_cmd('echo hi') wait() screen:expect([[ ready $ echo hi | @@ -41,7 +47,7 @@ describe(':terminal', function() end) it('allows quotes and slashes', function() - execute([[terminal echo 'hello' \ "world"]]) + terminal_run_fake_shell_cmd([[echo 'hello' \ "world"]]) wait() screen:expect([[ ready $ echo 'hello' \ "world" | @@ -58,4 +64,16 @@ describe(':terminal', function() -- Verify that BufNew actually fired (else the test is invalid). eq('foo', eval('&shell')) end) + + it('ignores writes if the backing stream closes', function() + terminal_run_fake_shell_cmd() + 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() + end) + end) |