mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
refactor(tests): drop os_kill #32401
Also change job tests to use `nvim` instead of random programs like `ping`.
This commit is contained in:
@@ -21,7 +21,6 @@ local rmdir = n.rmdir
|
||||
local assert_alive = n.assert_alive
|
||||
local command = n.command
|
||||
local fn = n.fn
|
||||
local os_kill = n.os_kill
|
||||
local retry = t.retry
|
||||
local api = n.api
|
||||
local NIL = vim.NIL
|
||||
@@ -444,27 +443,23 @@ describe('jobs', function()
|
||||
end)
|
||||
|
||||
it('disposed on Nvim exit', function()
|
||||
-- use sleep, which doesn't die on stdin close
|
||||
command(
|
||||
"let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)"
|
||||
)
|
||||
local pid = eval('jobpid(g:j)')
|
||||
neq(NIL, api.nvim_get_proc(pid))
|
||||
-- Start a child process which doesn't die on stdin close.
|
||||
local j = n.fn.jobstart({ n.nvim_prog, '--clean', '--headless' })
|
||||
local pid = n.fn.jobpid(j)
|
||||
eq('number', type(api.nvim_get_proc(pid).pid))
|
||||
clear()
|
||||
eq(NIL, api.nvim_get_proc(pid))
|
||||
end)
|
||||
|
||||
it('can survive the exit of nvim with "detach"', function()
|
||||
command('let g:job_opts.detach = 1')
|
||||
command(
|
||||
"let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)"
|
||||
)
|
||||
local pid = eval('jobpid(g:j)')
|
||||
neq(NIL, api.nvim_get_proc(pid))
|
||||
it('can survive Nvim exit with "detach"', function()
|
||||
local j = n.fn.jobstart({ n.nvim_prog, '--clean', '--headless' }, { detach = true })
|
||||
local pid = n.fn.jobpid(j)
|
||||
eq('number', type(api.nvim_get_proc(pid).pid))
|
||||
clear()
|
||||
neq(NIL, api.nvim_get_proc(pid))
|
||||
-- clean up after ourselves
|
||||
eq(0, os_kill(pid))
|
||||
-- Still alive.
|
||||
eq('number', type(api.nvim_get_proc(pid).pid))
|
||||
-- Clean up after ourselves.
|
||||
eq(0, vim.uv.kill(pid, 'sigkill'))
|
||||
end)
|
||||
|
||||
it('can pass user data to the callback', function()
|
||||
|
@@ -14,7 +14,6 @@ local ok = t.ok
|
||||
local rmdir = n.rmdir
|
||||
local new_pipename = n.new_pipename
|
||||
local pesc = vim.pesc
|
||||
local os_kill = n.os_kill
|
||||
local set_session = n.set_session
|
||||
local async_meths = n.async_meths
|
||||
local expect_msg_seq = n.expect_msg_seq
|
||||
@@ -100,7 +99,7 @@ describe("preserve and (R)ecover with custom 'directory'", function()
|
||||
it('with :preserve and SIGKILL', function()
|
||||
local swappath1 = setup_swapname()
|
||||
command('preserve')
|
||||
os_kill(eval('getpid()'))
|
||||
eq(0, vim.uv.kill(eval('getpid()'), 'sigkill'))
|
||||
test_recover(swappath1)
|
||||
end)
|
||||
|
||||
|
@@ -978,18 +978,6 @@ function M.add_builddir_to_rtp()
|
||||
M.command(string.format([[set rtp+=%s/runtime]], t.paths.test_build_dir))
|
||||
end
|
||||
|
||||
--- Kill (reap) a process by PID.
|
||||
--- @param pid string
|
||||
--- @return boolean?
|
||||
function M.os_kill(pid)
|
||||
return os.execute(
|
||||
(
|
||||
is_os('win') and 'taskkill /f /t /pid ' .. pid .. ' > nul'
|
||||
or 'kill -9 ' .. pid .. ' > /dev/null'
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
--- Create folder with non existing parents
|
||||
--- @param path string
|
||||
--- @return boolean?
|
||||
|
@@ -12,7 +12,6 @@ local command = n.command
|
||||
local insert = n.insert
|
||||
local expect = n.expect
|
||||
local exc_exec = n.exc_exec
|
||||
local os_kill = n.os_kill
|
||||
local pcall_err = t.pcall_err
|
||||
local is_os = t.is_os
|
||||
|
||||
@@ -394,7 +393,7 @@ describe('system()', function()
|
||||
it("with a program that doesn't close stdout will exit properly after passing input", function()
|
||||
local out = eval(string.format("system('%s', 'clip-data')", testprg('streams-test')))
|
||||
assert(out:sub(0, 5) == 'pid: ', out)
|
||||
os_kill(out:match('%d+'))
|
||||
eq(0, vim.uv.kill(assert(tonumber(out:match('%d+'))), 'sigkill'))
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -538,7 +537,7 @@ describe('systemlist()', function()
|
||||
it("with a program that doesn't close stdout will exit properly after passing input", function()
|
||||
local out = eval(string.format("systemlist('%s', 'clip-data')", testprg('streams-test')))
|
||||
assert(out[1]:sub(0, 5) == 'pid: ', out)
|
||||
os_kill(out[1]:match('%d+'))
|
||||
eq(0, vim.uv.kill(assert(tonumber(out[1]:match('%d+'))), 'sigkill'))
|
||||
end)
|
||||
|
||||
it('powershell w/ UTF-8 text #13713', function()
|
||||
|
Reference in New Issue
Block a user