diff options
Diffstat (limited to 'test/functional/terminal/ex_terminal_spec.lua')
-rw-r--r-- | test/functional/terminal/ex_terminal_spec.lua | 123 |
1 files changed, 103 insertions, 20 deletions
diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 4247be0417..7522f073c4 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -2,11 +2,11 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear, wait, nvim = helpers.clear, helpers.wait, helpers.nvim local nvim_dir, source, eq = helpers.nvim_dir, helpers.source, helpers.eq -local execute, eval = helpers.execute, helpers.eval - -if helpers.pending_win32(pending) then return end +local feed_command, eval = helpers.feed_command, helpers.eval +local iswin = helpers.iswin describe(':terminal', function() + if helpers.pending_win32(pending) then return end local screen before_each(function() @@ -20,26 +20,34 @@ describe(':terminal', function() source([[ echomsg "msg1" echomsg "msg2" + echomsg "msg3" ]]) -- Invoke a command that emits frequent terminal activity. - execute([[terminal while true; do echo X; done]]) + feed_command([[terminal while true; do echo X; done]]) helpers.feed([[<C-\><C-N>]]) + wait() + screen:sleep(10) -- Let some terminal activity happen. + feed_command("messages") screen:expect([[ - X | - X | - ^X | - | - ]]) - helpers.sleep(10) -- Let some terminal activity happen. - execute("messages") - screen:expect([[ - X | msg1 | msg2 | + msg3 | Press ENTER or type command to continue^ | ]]) end) + it("in normal-mode :split does not move cursor", function() + feed_command([[terminal while true; do echo foo; sleep .1; done]]) + helpers.feed([[<C-\><C-N>M]]) -- move cursor away from last line + wait() + eq(3, eval("line('$')")) -- window height + eq(2, eval("line('.')")) -- cursor is in the middle + feed_command('vsplit') + eq(2, eval("line('.')")) -- cursor stays where we put it + feed_command('split') + eq(2, eval("line('.')")) -- cursor stays where we put it + end) + end) describe(':terminal (with fake shell)', function() @@ -57,17 +65,41 @@ describe(':terminal (with fake shell)', function() -- Invokes `:terminal {cmd}` using a fake shell (shell-test.c) which prints -- the {cmd} and exits immediately . local function terminal_with_fake_shell(cmd) - execute("terminal "..(cmd and cmd or "")) + feed_command("terminal "..(cmd and cmd or "")) end it('with no argument, acts like termopen()', function() terminal_with_fake_shell() wait() screen:expect([[ - ready $ | + ^ready $ | + [Process exited 0] | + | + :terminal | + ]]) + end) + + it("with no argument, and 'shell' is set to empty string", function() + nvim('set_option', 'shell', '') + terminal_with_fake_shell() + wait() + screen:expect([[ + ^ | + ~ | + ~ | + E91: 'shell' option is empty | + ]]) + end) + + it("with no argument, but 'shell' has arguments, acts like termopen()", function() + nvim('set_option', 'shell', nvim_dir..'/shell-test -t jeff') + terminal_with_fake_shell() + wait() + screen:expect([[ + ^jeff $ | [Process exited 0] | | - -- TERMINAL -- | + :terminal | ]]) end) @@ -75,10 +107,22 @@ describe(':terminal (with fake shell)', function() terminal_with_fake_shell('echo hi') wait() screen:expect([[ - ready $ echo hi | + ^ready $ echo hi | + | + [Process exited 0] | + :terminal echo hi | + ]]) + end) + + it("executes a given command through the shell, when 'shell' has arguments", function() + nvim('set_option', 'shell', nvim_dir..'/shell-test -t jeff') + terminal_with_fake_shell('echo hi') + wait() + screen:expect([[ + ^jeff $ echo hi | | [Process exited 0] | - -- TERMINAL -- | + :terminal echo hi | ]]) end) @@ -86,10 +130,10 @@ describe(':terminal (with fake shell)', function() terminal_with_fake_shell([[echo 'hello' \ "world"]]) wait() screen:expect([[ - ready $ echo 'hello' \ "world" | + ^ready $ echo 'hello' \ "world" | | [Process exited 0] | - -- TERMINAL -- | + :terminal echo 'hello' \ "world" | ]]) end) @@ -112,4 +156,43 @@ describe(':terminal (with fake shell)', function() eq(2, eval("1+1")) -- Still alive? end) + it('works with findfile()', function() + feed_command('terminal') + eq('term://', string.match(eval('bufname("%")'), "^term://")) + eq('scripts/shadacat.py', eval('findfile("scripts/shadacat.py", ".")')) + end) + + it('works with :find', function() + terminal_with_fake_shell() + wait() + screen:expect([[ + ^ready $ | + [Process exited 0] | + | + :terminal | + ]]) + eq('term://', string.match(eval('bufname("%")'), "^term://")) + helpers.feed([[<C-\><C-N>]]) + feed_command([[find */shadacat.py]]) + if iswin() then + eq('scripts\\shadacat.py', eval('bufname("%")')) + else + eq('scripts/shadacat.py', eval('bufname("%")')) + end + end) + + it('works with gf', function() + terminal_with_fake_shell([[echo "scripts/shadacat.py"]]) + screen:expect([[ + ^ready $ echo "scripts/shadacat.py" | + | + [Process exited 0] | + :terminal echo "scripts/shadacat.py" | + ]]) + helpers.feed([[<C-\><C-N>]]) + eq('term://', string.match(eval('bufname("%")'), "^term://")) + helpers.feed([[ggf"lgf]]) + eq('scripts/shadacat.py', eval('bufname("%")')) + end) + end) |