aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/system_spec.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-09-04 12:03:03 +0100
committerLewis Russell <lewis6991@gmail.com>2023-09-05 17:10:04 +0100
commit80d1333b7317460c562a982ac21f900d9fbd89f6 (patch)
treec6e2cbf8fd95806045b5f96991306a5a482231cd /test/functional/lua/system_spec.lua
parent6d5f12efd286c684de8608c07bb0f76a9d594b5b (diff)
downloadrneovim-80d1333b7317460c562a982ac21f900d9fbd89f6.tar.gz
rneovim-80d1333b7317460c562a982ac21f900d9fbd89f6.tar.bz2
rneovim-80d1333b7317460c562a982ac21f900d9fbd89f6.zip
refactor(vim.system): factor out on_exit handling
Diffstat (limited to 'test/functional/lua/system_spec.lua')
-rw-r--r--test/functional/lua/system_spec.lua27
1 files changed, 17 insertions, 10 deletions
diff --git a/test/functional/lua/system_spec.lua b/test/functional/lua/system_spec.lua
index 9321468f84..a988d3f0d7 100644
--- a/test/functional/lua/system_spec.lua
+++ b/test/functional/lua/system_spec.lua
@@ -5,13 +5,20 @@ local eq = helpers.eq
local function system_sync(cmd, opts)
return exec_lua([[
+ local cmd, opts = ...
local obj = vim.system(...)
- local pid = obj.pid
+
+ if opts.timeout then
+ -- Minor delay before calling wait() so the timeout uv timer can have a headstart over the
+ -- internal call to vim.wait() in wait().
+ vim.wait(10)
+ end
+
local res = obj:wait()
-- Check the process is no longer running
- vim.fn.systemlist({'ps', 'p', tostring(pid)})
- assert(vim.v.shell_error == 1, 'process still exists')
+ local proc = vim.api.nvim_get_proc(obj.pid)
+ assert(not proc, 'process still exists')
return res
]], cmd, opts)
@@ -26,15 +33,15 @@ local function system_async(cmd, opts)
_G.ret = obj
end)
- local done = vim.wait(10000, function()
+ local ok = vim.wait(10000, function()
return _G.done
end)
- assert(done, 'process did not exit')
+ assert(ok, 'process did not exit')
-- Check the process is no longer running
- vim.fn.systemlist({'ps', 'p', tostring(obj.pid)})
- assert(vim.v.shell_error == 1, 'process still exists')
+ local proc = vim.api.nvim_get_proc(obj.pid)
+ assert(not proc, 'process still exists')
return _G.ret
]], cmd, opts)
@@ -61,7 +68,7 @@ describe('vim.system', function()
signal = 15,
stdout = '',
stderr = ''
- }, system({ 'sleep', '10' }, { timeout = 1 }))
+ }, system({ 'sleep', '10' }, { timeout = 1000 }))
end)
end)
end
@@ -83,8 +90,8 @@ describe('vim.system', function()
assert(done, 'process did not exit')
-- Check the process is no longer running
- vim.fn.systemlist({'ps', 'p', tostring(cmd.pid)})
- assert(vim.v.shell_error == 1, 'dwqdqd '..vim.v.shell_error)
+ local proc = vim.api.nvim_get_proc(cmd.pid)
+ assert(not proc, 'process still exists')
assert(signal == 2)
]])