diff options
Diffstat (limited to 'test/functional/shell')
-rw-r--r-- | test/functional/shell/viml_system_spec.lua | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/functional/shell/viml_system_spec.lua b/test/functional/shell/viml_system_spec.lua index effabe715c..a8bab8e26e 100644 --- a/test/functional/shell/viml_system_spec.lua +++ b/test/functional/shell/viml_system_spec.lua @@ -19,10 +19,30 @@ local function delete_file(name) end end +-- Some tests require the xclip program and a x server. +local xclip = nil +do + if os.getenv('DISPLAY') then + local proc = io.popen('which xclip') + xclip = proc:read() + proc:close() + end +end describe('system()', function() before_each(clear) + it('sets the v:shell_error variable', function() + eval([[system("sh -c 'exit'")]]) + eq(0, eval('v:shell_error')) + eval([[system("sh -c 'exit 1'")]]) + eq(1, eval('v:shell_error')) + eval([[system("sh -c 'exit 5'")]]) + eq(5, eval('v:shell_error')) + eval([[system('this-should-not-exist')]]) + eq(127, eval('v:shell_error')) + end) + describe('passing no input', function() it('returns the program output', function() eq("echoed", eval('system("echo -n echoed")')) @@ -76,6 +96,15 @@ describe('system()', function() end) end) end) + + if xclip then + describe("with a program that doesn't close stdout", function() + it('will exit properly after passing input', function() + eq(nil, eval([[system('xclip -i -selection clipboard', 'clip-data')]])) + eq('clip-data', eval([[system('xclip -o -selection clipboard')]])) + end) + end) + end end) describe('systemlist()', function() @@ -83,6 +112,17 @@ describe('systemlist()', function() -- string. before_each(clear) + it('sets the v:shell_error variable', function() + eval([[systemlist("sh -c 'exit'")]]) + eq(0, eval('v:shell_error')) + eval([[systemlist("sh -c 'exit 1'")]]) + eq(1, eval('v:shell_error')) + eval([[systemlist("sh -c 'exit 5'")]]) + eq(5, eval('v:shell_error')) + eval([[systemlist('this-should-not-exist')]]) + eq(127, eval('v:shell_error')) + end) + describe('passing string with linefeed characters as input', function() it('splits the output on linefeed characters', function() eq({'abc', 'def', 'ghi'}, eval([[systemlist("cat -", "abc\ndef\nghi")]])) @@ -122,4 +162,15 @@ describe('systemlist()', function() end) end) end) + + if xclip then + describe("with a program that doesn't close stdout", function() + it('will exit properly after passing input', function() + eq(nil, eval( + "systemlist('xclip -i -selection clipboard', ['clip', 'data'])")) + eq({'clip', 'data'}, eval( + "systemlist('xclip -o -selection clipboard')")) + end) + end) + end end) |