mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #1448 from tarruda/shell-systemlist-test-fixes
Fixes to shell.c, systemlist and functional tests
This commit is contained in:
commit
3080672650
@ -14492,6 +14492,11 @@ static void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv,
|
|||||||
set_vim_var_nr(VV_SHELL_ERROR, (long) status);
|
set_vim_var_nr(VV_SHELL_ERROR, (long) status);
|
||||||
|
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
|
if (retlist) {
|
||||||
|
// return an empty list when there's no output
|
||||||
|
rettv->v_type = VAR_LIST;
|
||||||
|
rettv->vval.v_list = list_alloc();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,6 +244,9 @@ static int shell(const char *cmd,
|
|||||||
job_stop(job);
|
job_stop(job);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
// close the input stream after everything is written
|
||||||
|
job_write_cb(job, shell_write_cb);
|
||||||
|
} else {
|
||||||
// close the input stream, let the process know that no more input is
|
// close the input stream, let the process know that no more input is
|
||||||
// coming
|
// coming
|
||||||
job_close_in(job);
|
job_close_in(job);
|
||||||
@ -447,3 +450,9 @@ static void write_output(char *output, size_t remaining)
|
|||||||
curbuf->b_no_eol_lnum = 0;
|
curbuf->b_no_eol_lnum = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void shell_write_cb(WStream *wstream, void *data, int status)
|
||||||
|
{
|
||||||
|
Job *job = data;
|
||||||
|
job_close_in(job);
|
||||||
|
}
|
||||||
|
@ -25,7 +25,7 @@ if os.getenv('VALGRIND') then
|
|||||||
nvim_argv = valgrind_argv
|
nvim_argv = valgrind_argv
|
||||||
end
|
end
|
||||||
|
|
||||||
local session, loop_running, last_error
|
local session, loop_running, loop_stopped, last_error
|
||||||
|
|
||||||
local function request(method, ...)
|
local function request(method, ...)
|
||||||
local status, rv = session:request(method, ...)
|
local status, rv = session:request(method, ...)
|
||||||
@ -39,7 +39,11 @@ local function request(method, ...)
|
|||||||
end
|
end
|
||||||
-- Make sure this will only return after all buffered characters have been
|
-- Make sure this will only return after all buffered characters have been
|
||||||
-- processed
|
-- processed
|
||||||
|
if not loop_stopped then
|
||||||
|
-- Except when the loop has been stopped by a notification triggered
|
||||||
|
-- by the initial request, for example.
|
||||||
session:request('vim_eval', '1')
|
session:request('vim_eval', '1')
|
||||||
|
end
|
||||||
return rv
|
return rv
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -71,6 +75,7 @@ local function run(request_cb, notification_cb, setup_cb)
|
|||||||
call_and_stop_on_error(setup_cb)
|
call_and_stop_on_error(setup_cb)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
loop_stopped = false
|
||||||
loop_running = true
|
loop_running = true
|
||||||
session:run(on_request, on_notification, on_setup)
|
session:run(on_request, on_notification, on_setup)
|
||||||
loop_running = false
|
loop_running = false
|
||||||
@ -82,6 +87,7 @@ local function run(request_cb, notification_cb, setup_cb)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function stop()
|
local function stop()
|
||||||
|
loop_stopped = true
|
||||||
session:stop()
|
session:stop()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
-- - `systemlist()`
|
-- - `systemlist()`
|
||||||
|
|
||||||
local helpers = require('test.functional.helpers')
|
local helpers = require('test.functional.helpers')
|
||||||
local eq, clear, eval, feed =
|
local eq, clear, eval, feed, nvim =
|
||||||
helpers.eq, helpers.clear, helpers.eval, helpers.feed
|
helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.nvim
|
||||||
|
|
||||||
|
|
||||||
local function create_file_with_nuls(name)
|
local function create_file_with_nuls(name)
|
||||||
@ -55,6 +55,21 @@ describe('system()', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('passing a lot of input', function()
|
||||||
|
it('returns the program output', function()
|
||||||
|
local input = {}
|
||||||
|
-- write more than 1mb of data, which should be enough to overcome
|
||||||
|
-- the os buffer limit and force multiple event loop iterations to write
|
||||||
|
-- everything
|
||||||
|
for i = 1, 0xffff do
|
||||||
|
input[#input + 1] = '01234567890ABCDEFabcdef'
|
||||||
|
end
|
||||||
|
input = table.concat(input, '\n')
|
||||||
|
nvim('set_var', 'input', input)
|
||||||
|
eq(input, eval('system("cat -", g:input)'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
describe('passing number as input', function()
|
describe('passing number as input', function()
|
||||||
it('stringifies the input', function()
|
it('stringifies the input', function()
|
||||||
eq('1', eval('system("cat", 1)'))
|
eq('1', eval('system("cat", 1)'))
|
||||||
@ -129,6 +144,17 @@ describe('systemlist()', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('passing a lot of input', function()
|
||||||
|
it('returns the program output', function()
|
||||||
|
local input = {}
|
||||||
|
for i = 1, 0xffff do
|
||||||
|
input[#input + 1] = '01234567890ABCDEFabcdef'
|
||||||
|
end
|
||||||
|
nvim('set_var', 'input', input)
|
||||||
|
eq(input, eval('systemlist("cat -", g:input)'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
describe('with output containing NULs', function()
|
describe('with output containing NULs', function()
|
||||||
local fname = 'Xtest'
|
local fname = 'Xtest'
|
||||||
|
|
||||||
@ -166,7 +192,7 @@ describe('systemlist()', function()
|
|||||||
if xclip then
|
if xclip then
|
||||||
describe("with a program that doesn't close stdout", function()
|
describe("with a program that doesn't close stdout", function()
|
||||||
it('will exit properly after passing input', function()
|
it('will exit properly after passing input', function()
|
||||||
eq(nil, eval(
|
eq({}, eval(
|
||||||
"systemlist('xclip -i -selection clipboard', ['clip', 'data'])"))
|
"systemlist('xclip -i -selection clipboard', ['clip', 'data'])"))
|
||||||
eq({'clip', 'data'}, eval(
|
eq({'clip', 'data'}, eval(
|
||||||
"systemlist('xclip -o -selection clipboard')"))
|
"systemlist('xclip -o -selection clipboard')"))
|
||||||
|
Loading…
Reference in New Issue
Block a user