mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
tests: fix system_spec when run with clipboard manager (#10956)
* tests: move os_kill to functional helpers * tests: fix system_spec when run with clipboard manager Replaces "xclip" with a dedicated helper program. Fixes: https://github.com/neovim/neovim/issues/4900#issuecomment-501866842
This commit is contained in:
@@ -560,7 +560,7 @@ if(BUSTED_PRG)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(UNITTEST_PREREQS nvim-test unittest-headers)
|
set(UNITTEST_PREREQS nvim-test unittest-headers)
|
||||||
set(FUNCTIONALTEST_PREREQS nvim printargs-test shell-test ${GENERATED_HELP_TAGS})
|
set(FUNCTIONALTEST_PREREQS nvim printargs-test shell-test streams-test ${GENERATED_HELP_TAGS})
|
||||||
if(NOT WIN32)
|
if(NOT WIN32)
|
||||||
list(APPEND FUNCTIONALTEST_PREREQS tty-test)
|
list(APPEND FUNCTIONALTEST_PREREQS tty-test)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ local clear, eq, eval, exc_exec, feed_command, feed, insert, neq, next_msg, nvim
|
|||||||
helpers.write_file, helpers.mkdir, helpers.rmdir
|
helpers.write_file, helpers.mkdir, helpers.rmdir
|
||||||
local command = helpers.command
|
local command = helpers.command
|
||||||
local funcs = helpers.funcs
|
local funcs = helpers.funcs
|
||||||
|
local os_kill = helpers.os_kill
|
||||||
local retry = helpers.retry
|
local retry = helpers.retry
|
||||||
local meths = helpers.meths
|
local meths = helpers.meths
|
||||||
local NIL = helpers.NIL
|
local NIL = helpers.NIL
|
||||||
@@ -20,13 +21,6 @@ local expect_msg_seq = helpers.expect_msg_seq
|
|||||||
local pcall_err = helpers.pcall_err
|
local pcall_err = helpers.pcall_err
|
||||||
local Screen = require('test.functional.ui.screen')
|
local Screen = require('test.functional.ui.screen')
|
||||||
|
|
||||||
-- Kill process with given pid
|
|
||||||
local function os_kill(pid)
|
|
||||||
return os.execute((iswin()
|
|
||||||
and 'taskkill /f /t /pid '..pid..' > nul'
|
|
||||||
or 'kill -9 '..pid..' > /dev/null'))
|
|
||||||
end
|
|
||||||
|
|
||||||
describe('jobs', function()
|
describe('jobs', function()
|
||||||
local channel
|
local channel
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ local eq, call, clear, eval, feed_command, feed, nvim =
|
|||||||
local command = helpers.command
|
local command = helpers.command
|
||||||
local exc_exec = helpers.exc_exec
|
local exc_exec = helpers.exc_exec
|
||||||
local iswin = helpers.iswin
|
local iswin = helpers.iswin
|
||||||
|
local os_kill = helpers.os_kill
|
||||||
|
|
||||||
local Screen = require('test.functional.ui.screen')
|
local Screen = require('test.functional.ui.screen')
|
||||||
|
|
||||||
@@ -23,14 +24,6 @@ local function delete_file(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Some tests require the xclip program and a x server.
|
|
||||||
local xclip = nil
|
|
||||||
do
|
|
||||||
if os.getenv('DISPLAY') then
|
|
||||||
xclip = (os.execute('command -v xclip > /dev/null 2>&1') == 0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe('system()', function()
|
describe('system()', function()
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
@@ -378,15 +371,10 @@ describe('system()', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("with a program that doesn't close stdout", function()
|
it("with a program that doesn't close stdout will exit properly after passing input", function()
|
||||||
if not xclip then
|
local out = eval(string.format("system('%s', 'clip-data')", nvim_dir..'/streams-test'))
|
||||||
pending('missing `xclip`', function() end)
|
assert(out:sub(0, 5) == 'pid: ', out)
|
||||||
else
|
os_kill(out:match("%d+"))
|
||||||
it('will exit properly after passing input', function()
|
|
||||||
eq('', eval([[system('xclip -i -loops 1 -selection clipboard', 'clip-data')]]))
|
|
||||||
eq('clip-data', eval([[system('xclip -o -selection clipboard')]]))
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -562,16 +550,9 @@ describe('systemlist()', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("with a program that doesn't close stdout", function()
|
it("with a program that doesn't close stdout will exit properly after passing input", function()
|
||||||
if not xclip then
|
local out = eval(string.format("systemlist('%s', 'clip-data')", nvim_dir..'/streams-test'))
|
||||||
pending('missing `xclip`', function() end)
|
assert(out[1]:sub(0, 5) == 'pid: ', out)
|
||||||
else
|
os_kill(out[1]:match("%d+"))
|
||||||
it('will exit properly after passing input', function()
|
|
||||||
eq({}, eval(
|
|
||||||
"systemlist('xclip -i -loops 1 -selection clipboard', ['clip', 'data'])"))
|
|
||||||
eq({'clip', 'data'}, eval(
|
|
||||||
"systemlist('xclip -o -selection clipboard')"))
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -7,3 +7,6 @@ add_executable(printenv-test printenv-test.c)
|
|||||||
if(WIN32)
|
if(WIN32)
|
||||||
set_target_properties(printenv-test PROPERTIES LINK_FLAGS -municode)
|
set_target_properties(printenv-test PROPERTIES LINK_FLAGS -municode)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
add_executable(streams-test streams-test.c)
|
||||||
|
target_link_libraries(streams-test ${LIBUV_LIBRARIES})
|
||||||
|
|||||||
33
test/functional/fixtures/streams-test.c
Normal file
33
test/functional/fixtures/streams-test.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/// Helper program to exit and keep stdout open (like "xclip -i -loops 1").
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <uv.h>
|
||||||
|
|
||||||
|
uv_loop_t *loop;
|
||||||
|
uv_process_t child_req;
|
||||||
|
uv_process_options_t options;
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
loop = uv_default_loop();
|
||||||
|
|
||||||
|
char * args[3];
|
||||||
|
args[0] = "sleep";
|
||||||
|
args[1] = "10";
|
||||||
|
args[2] = NULL;
|
||||||
|
|
||||||
|
options.exit_cb = NULL;
|
||||||
|
options.file = "sleep";
|
||||||
|
options.args = args;
|
||||||
|
options.flags = UV_PROCESS_DETACHED;
|
||||||
|
|
||||||
|
int r;
|
||||||
|
if ((r = uv_spawn(loop, &child_req, &options))) {
|
||||||
|
fprintf(stderr, "%s\n", uv_strerror(r));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fprintf(stderr, "pid: %d\n", child_req.pid);
|
||||||
|
uv_unref((uv_handle_t *)&child_req);
|
||||||
|
|
||||||
|
return uv_run(loop, UV_RUN_DEFAULT);
|
||||||
|
}
|
||||||
@@ -796,6 +796,13 @@ function module.add_builddir_to_rtp()
|
|||||||
module.command(string.format([[set rtp+=%s/runtime]], module.test_build_dir))
|
module.command(string.format([[set rtp+=%s/runtime]], module.test_build_dir))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Kill process with given pid
|
||||||
|
function module.os_kill(pid)
|
||||||
|
return os.execute((iswin()
|
||||||
|
and 'taskkill /f /t /pid '..pid..' > nul'
|
||||||
|
or 'kill -9 '..pid..' > /dev/null'))
|
||||||
|
end
|
||||||
|
|
||||||
module = global_helpers.tbl_extend('error', module, global_helpers)
|
module = global_helpers.tbl_extend('error', module, global_helpers)
|
||||||
|
|
||||||
return function(after_each)
|
return function(after_each)
|
||||||
|
|||||||
Reference in New Issue
Block a user