aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/system_spec.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-09-04 11:30:16 +0100
committerLewis Russell <lewis6991@gmail.com>2023-09-05 17:10:01 +0100
commit6d5f12efd286c684de8608c07bb0f76a9d594b5b (patch)
treeaaf460e24971f3b03d29e20b965cfebc18b17fad /test/functional/lua/system_spec.lua
parenta44521f46e6f79171d034e5cce1a4dc266d23e49 (diff)
downloadrneovim-6d5f12efd286c684de8608c07bb0f76a9d594b5b.tar.gz
rneovim-6d5f12efd286c684de8608c07bb0f76a9d594b5b.tar.bz2
rneovim-6d5f12efd286c684de8608c07bb0f76a9d594b5b.zip
fix(vim.system): make timeout work properly
Mimic the behaviour of timeout(1) from coreutils.
Diffstat (limited to 'test/functional/lua/system_spec.lua')
-rw-r--r--test/functional/lua/system_spec.lua40
1 files changed, 26 insertions, 14 deletions
diff --git a/test/functional/lua/system_spec.lua b/test/functional/lua/system_spec.lua
index 35b9d5cc37..9321468f84 100644
--- a/test/functional/lua/system_spec.lua
+++ b/test/functional/lua/system_spec.lua
@@ -5,27 +5,39 @@ local eq = helpers.eq
local function system_sync(cmd, opts)
return exec_lua([[
- return vim.system(...):wait()
+ local obj = vim.system(...)
+ local pid = obj.pid
+ 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')
+
+ return res
]], cmd, opts)
end
local function system_async(cmd, opts)
- exec_lua([[
+ return exec_lua([[
local cmd, opts = ...
_G.done = false
- vim.system(cmd, opts, function(obj)
+ local obj = vim.system(cmd, opts, function(obj)
_G.done = true
_G.ret = obj
end)
- ]], cmd, opts)
- while true do
- if exec_lua[[return _G.done]] then
- break
- end
- end
+ local done = vim.wait(10000, function()
+ return _G.done
+ end)
+
+ assert(done, 'process did not exit')
- return exec_lua[[return _G.ret]]
+ -- Check the process is no longer running
+ vim.fn.systemlist({'ps', 'p', tostring(obj.pid)})
+ assert(vim.v.shell_error == 1, 'process still exists')
+
+ return _G.ret
+ ]], cmd, opts)
end
describe('vim.system', function()
@@ -43,12 +55,12 @@ describe('vim.system', function()
eq('hellocat', system({ 'cat' }, { stdin = 'hellocat', text = true }).stdout)
end)
- it ('supports timeout', function()
+ it('supports timeout', function()
eq({
- code = 0,
- signal = 2,
+ code = 124,
+ signal = 15,
stdout = '',
- stderr = "Command timed out: 'sleep 10'"
+ stderr = ''
}, system({ 'sleep', '10' }, { timeout = 1 }))
end)
end)