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 assert_alive = n.assert_alive
|
||||||
local command = n.command
|
local command = n.command
|
||||||
local fn = n.fn
|
local fn = n.fn
|
||||||
local os_kill = n.os_kill
|
|
||||||
local retry = t.retry
|
local retry = t.retry
|
||||||
local api = n.api
|
local api = n.api
|
||||||
local NIL = vim.NIL
|
local NIL = vim.NIL
|
||||||
@@ -444,27 +443,23 @@ describe('jobs', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('disposed on Nvim exit', function()
|
it('disposed on Nvim exit', function()
|
||||||
-- use sleep, which doesn't die on stdin close
|
-- Start a child process which doesn't die on stdin close.
|
||||||
command(
|
local j = n.fn.jobstart({ n.nvim_prog, '--clean', '--headless' })
|
||||||
"let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)"
|
local pid = n.fn.jobpid(j)
|
||||||
)
|
eq('number', type(api.nvim_get_proc(pid).pid))
|
||||||
local pid = eval('jobpid(g:j)')
|
|
||||||
neq(NIL, api.nvim_get_proc(pid))
|
|
||||||
clear()
|
clear()
|
||||||
eq(NIL, api.nvim_get_proc(pid))
|
eq(NIL, api.nvim_get_proc(pid))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('can survive the exit of nvim with "detach"', function()
|
it('can survive Nvim exit with "detach"', function()
|
||||||
command('let g:job_opts.detach = 1')
|
local j = n.fn.jobstart({ n.nvim_prog, '--clean', '--headless' }, { detach = true })
|
||||||
command(
|
local pid = n.fn.jobpid(j)
|
||||||
"let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)"
|
eq('number', type(api.nvim_get_proc(pid).pid))
|
||||||
)
|
|
||||||
local pid = eval('jobpid(g:j)')
|
|
||||||
neq(NIL, api.nvim_get_proc(pid))
|
|
||||||
clear()
|
clear()
|
||||||
neq(NIL, api.nvim_get_proc(pid))
|
-- Still alive.
|
||||||
-- clean up after ourselves
|
eq('number', type(api.nvim_get_proc(pid).pid))
|
||||||
eq(0, os_kill(pid))
|
-- Clean up after ourselves.
|
||||||
|
eq(0, vim.uv.kill(pid, 'sigkill'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('can pass user data to the callback', function()
|
it('can pass user data to the callback', function()
|
||||||
|
@@ -14,7 +14,6 @@ local ok = t.ok
|
|||||||
local rmdir = n.rmdir
|
local rmdir = n.rmdir
|
||||||
local new_pipename = n.new_pipename
|
local new_pipename = n.new_pipename
|
||||||
local pesc = vim.pesc
|
local pesc = vim.pesc
|
||||||
local os_kill = n.os_kill
|
|
||||||
local set_session = n.set_session
|
local set_session = n.set_session
|
||||||
local async_meths = n.async_meths
|
local async_meths = n.async_meths
|
||||||
local expect_msg_seq = n.expect_msg_seq
|
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()
|
it('with :preserve and SIGKILL', function()
|
||||||
local swappath1 = setup_swapname()
|
local swappath1 = setup_swapname()
|
||||||
command('preserve')
|
command('preserve')
|
||||||
os_kill(eval('getpid()'))
|
eq(0, vim.uv.kill(eval('getpid()'), 'sigkill'))
|
||||||
test_recover(swappath1)
|
test_recover(swappath1)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@@ -978,18 +978,6 @@ function M.add_builddir_to_rtp()
|
|||||||
M.command(string.format([[set rtp+=%s/runtime]], t.paths.test_build_dir))
|
M.command(string.format([[set rtp+=%s/runtime]], t.paths.test_build_dir))
|
||||||
end
|
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
|
--- Create folder with non existing parents
|
||||||
--- @param path string
|
--- @param path string
|
||||||
--- @return boolean?
|
--- @return boolean?
|
||||||
|
@@ -12,7 +12,6 @@ local command = n.command
|
|||||||
local insert = n.insert
|
local insert = n.insert
|
||||||
local expect = n.expect
|
local expect = n.expect
|
||||||
local exc_exec = n.exc_exec
|
local exc_exec = n.exc_exec
|
||||||
local os_kill = n.os_kill
|
|
||||||
local pcall_err = t.pcall_err
|
local pcall_err = t.pcall_err
|
||||||
local is_os = t.is_os
|
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()
|
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')))
|
local out = eval(string.format("system('%s', 'clip-data')", testprg('streams-test')))
|
||||||
assert(out:sub(0, 5) == 'pid: ', out)
|
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)
|
||||||
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()
|
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')))
|
local out = eval(string.format("systemlist('%s', 'clip-data')", testprg('streams-test')))
|
||||||
assert(out[1]:sub(0, 5) == 'pid: ', out)
|
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)
|
end)
|
||||||
|
|
||||||
it('powershell w/ UTF-8 text #13713', function()
|
it('powershell w/ UTF-8 text #13713', function()
|
||||||
|
Reference in New Issue
Block a user