diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/fixtures/CMakeLists.txt (renamed from test/functional/job/CMakeLists.txt) | 2 | ||||
-rw-r--r-- | test/functional/fixtures/shell-test.c | 25 | ||||
-rw-r--r-- | test/functional/fixtures/tty-test.c (renamed from test/functional/job/tty-test.c) | 0 | ||||
-rw-r--r-- | test/functional/job/job_spec.lua | 7 | ||||
-rw-r--r-- | test/functional/shell/viml_system_spec.lua | 9 | ||||
-rw-r--r-- | test/functional/terminal/cursor_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/terminal/ex_terminal_spec.lua | 61 | ||||
-rw-r--r-- | test/functional/terminal/helpers.lua | 2 | ||||
-rw-r--r-- | test/functional/terminal/highlight_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/terminal/scrollback_spec.lua | 2 | ||||
-rw-r--r-- | test/unit/os/shell_spec.lua | 4 |
11 files changed, 111 insertions, 7 deletions
diff --git a/test/functional/job/CMakeLists.txt b/test/functional/fixtures/CMakeLists.txt index 14ec287816..70aee6efa9 100644 --- a/test/functional/job/CMakeLists.txt +++ b/test/functional/fixtures/CMakeLists.txt @@ -1,2 +1,4 @@ add_executable(tty-test tty-test.c) target_link_libraries(tty-test ${LIBUV_LIBRARIES}) + +add_executable(shell-test shell-test.c) diff --git a/test/functional/fixtures/shell-test.c b/test/functional/fixtures/shell-test.c new file mode 100644 index 0000000000..5fa8a58049 --- /dev/null +++ b/test/functional/fixtures/shell-test.c @@ -0,0 +1,25 @@ +// A simple implementation of a shell for testing +// `termopen([&sh, &shcf, '{cmd'}])` and `termopen([&sh])`. +// +// If launched with no arguments, prints "ready $ ", otherwise prints +// "ready $ {cmd}\n". + +#include <stdio.h> +#include <string.h> + +int main(int argc, char **argv) +{ + fprintf(stderr, "ready $ "); + + if (argc == 3) { + // argv should be {"terminal-test", "EXE", "prog args..."} + if (strcmp(argv[1], "EXE") != 0) { + fprintf(stderr, "first argument must be 'EXE'\n"); + return 2; + } + + fprintf(stderr, "%s\n", argv[2]); + } + + return 0; +} diff --git a/test/functional/job/tty-test.c b/test/functional/fixtures/tty-test.c index 40ba131003..40ba131003 100644 --- a/test/functional/job/tty-test.c +++ b/test/functional/fixtures/tty-test.c diff --git a/test/functional/job/job_spec.lua b/test/functional/job/job_spec.lua index df989b3ef9..259fa52443 100644 --- a/test/functional/job/job_spec.lua +++ b/test/functional/job/job_spec.lua @@ -29,6 +29,13 @@ describe('jobs', function() ]]) end) + it('uses &shell and &shellcmdflag if passed a string', function() + nvim('command', "let $VAR = 'abc'") + nvim('command', "let j = jobstart('echo $VAR', g:job_opts)") + eq({'notification', 'stdout', {0, {'abc', ''}}}, next_msg()) + eq({'notification', 'exit', {0, 0}}, next_msg()) + end) + it('returns 0 when it fails to start', function() local status, rv = pcall(eval, "jobstart([])") eq(false, status) diff --git a/test/functional/shell/viml_system_spec.lua b/test/functional/shell/viml_system_spec.lua index 922770ad42..bd47d31a14 100644 --- a/test/functional/shell/viml_system_spec.lua +++ b/test/functional/shell/viml_system_spec.lua @@ -44,7 +44,7 @@ describe('system()', function() eq(127, eval('v:shell_error')) end) - describe('executes shell function', function() + describe('executes shell function if passed a string', function() local screen before_each(function() @@ -192,6 +192,13 @@ describe('system()', function() end) end) end + + describe('command passed as a list', function() + it('does not execute &shell', function() + eq('* $NOTHING ~/file', + eval("system(['echo', '-n', '*', '$NOTHING', '~/file'])")) + end) + end) end) describe('systemlist()', function() diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua index cecb33de7c..29225f968f 100644 --- a/test/functional/terminal/cursor_spec.lua +++ b/test/functional/terminal/cursor_spec.lua @@ -144,7 +144,7 @@ describe('cursor with customized highlighting', function() [6] = {foreground = 130}, }) screen:attach(false) - execute('term "' ..nvim_dir.. '/tty-test"') + execute('call termopen(["'..nvim_dir..'/tty-test"]) | startinsert') end) it('overrides the default highlighting', function() diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua new file mode 100644 index 0000000000..3855cf4b65 --- /dev/null +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -0,0 +1,61 @@ +local helpers = require('test.functional.helpers') +local Screen = require('test.functional.ui.screen') +local clear, wait, nvim = helpers.clear, helpers.wait, helpers.nvim +local nvim_dir = helpers.nvim_dir +local execute, source = helpers.execute, helpers.source +local eq, neq = helpers.eq, helpers.neq + +describe(':terminal', function() + local screen + + before_each(function() + clear() + screen = Screen.new(50, 7) + screen:attach(false) + nvim('set_option', 'shell', nvim_dir..'/shell-test') + nvim('set_option', 'shellcmdflag', 'EXE') + + end) + + it('with no argument, acts like termopen()', function() + execute('terminal') + wait() + screen:expect([[ + ready $ | + [Program exited, press any key to close] | + | + | + | + | + -- TERMINAL -- | + ]]) + end) + + it('executes a given command through the shell', function() + execute('terminal echo hi') + wait() + screen:expect([[ + ready $ echo hi | + | + [Program exited, press any key to close] | + | + | + | + -- TERMINAL -- | + ]]) + end) + + it('allows quotes and slashes', function() + execute([[terminal echo 'hello' \ "world"]]) + wait() + screen:expect([[ + ready $ echo 'hello' \ "world" | + | + [Program exited, press any key to close] | + | + | + | + -- TERMINAL -- | + ]]) + end) +end) diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua index 1bc6057a0b..e488495139 100644 --- a/test/functional/terminal/helpers.lua +++ b/test/functional/terminal/helpers.lua @@ -56,7 +56,7 @@ local function screen_setup(extra_height) -- tty-test puts the terminal into raw mode and echoes all input. tests are -- done by feeding it with terminfo codes to control the display and -- verifying output with screen:expect. - execute('term ' ..nvim_dir.. '/tty-test') + execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert') -- wait for "tty ready" to be printed before each test or the terminal may -- still be in canonical mode(will echo characters for example) -- diff --git a/test/functional/terminal/highlight_spec.lua b/test/functional/terminal/highlight_spec.lua index 59b0d2c19d..b72527e7b6 100644 --- a/test/functional/terminal/highlight_spec.lua +++ b/test/functional/terminal/highlight_spec.lua @@ -27,7 +27,7 @@ describe('terminal window highlighting', function() [8] = {background = 11} }) screen:attach(false) - execute('term "' ..nvim_dir.. '/tty-test"') + execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert') screen:expect([[ tty ready | | @@ -133,7 +133,7 @@ describe('terminal window highlighting with custom palette', function() }) screen:attach(true) nvim('set_var', 'terminal_color_3', '#123456') - execute('term "' ..nvim_dir.. '/tty-test"') + execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert') screen:expect([[ tty ready | | diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index d9b7534fac..f2381631a9 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -332,7 +332,7 @@ describe('terminal prints more lines than the screen height and exits', function clear() local screen = Screen.new(50, 7) screen:attach(false) - execute('term ' ..nvim_dir.. '/tty-test 10') + execute('call termopen(["'..nvim_dir..'/tty-test", "10"]) | startinsert') wait() screen:expect([[ line6 | diff --git a/test/unit/os/shell_spec.lua b/test/unit/os/shell_spec.lua index 03aafe7e3c..91d807da0b 100644 --- a/test/unit/os/shell_spec.lua +++ b/test/unit/os/shell_spec.lua @@ -40,7 +40,9 @@ describe('shell functions', function() local output = ffi.new('char *[1]') local nread = ffi.new('size_t[1]') - local status = shell.os_system(to_cstr(cmd), input_or, input_len, output, nread) + local argv = ffi.cast('char**', + shell.shell_build_argv(to_cstr(cmd), nil)) + local status = shell.os_system(argv, input_or, input_len, output, nread) return status, intern(output[0], nread[0]) end |