diff options
Diffstat (limited to 'test/functional/lua/system_spec.lua')
-rw-r--r-- | test/functional/lua/system_spec.lua | 40 |
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) |