proc_spec.lua (2588B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 4 local clear = n.clear 5 local eq = t.eq 6 local fn = n.fn 7 local neq = t.neq 8 local nvim_argv = n.nvim_argv 9 local request = n.request 10 local retry = t.retry 11 local NIL = vim.NIL 12 local is_os = t.is_os 13 14 describe('API', function() 15 before_each(clear) 16 17 describe('nvim_get_proc_children', function() 18 it('returns child process ids', function() 19 local this_pid = fn.getpid() 20 21 -- Might be non-zero already (left-over from some other test?), 22 -- but this is not what is tested here. 23 local initial_children = request('nvim_get_proc_children', this_pid) 24 25 local job1 = fn.jobstart(nvim_argv) 26 retry(nil, nil, function() 27 eq(#initial_children + 1, #request('nvim_get_proc_children', this_pid)) 28 end) 29 30 local job2 = fn.jobstart(nvim_argv) 31 retry(nil, nil, function() 32 eq(#initial_children + 2, #request('nvim_get_proc_children', this_pid)) 33 end) 34 35 fn.jobstop(job1) 36 retry(nil, nil, function() 37 eq(#initial_children + 1, #request('nvim_get_proc_children', this_pid)) 38 end) 39 40 fn.jobstop(job2) 41 retry(nil, nil, function() 42 eq(#initial_children, #request('nvim_get_proc_children', this_pid)) 43 end) 44 end) 45 46 it('validation', function() 47 local status, rv = pcall(request, 'nvim_get_proc_children', -1) 48 eq(false, status) 49 eq("Invalid 'pid': -1", string.match(rv, 'Invalid.*')) 50 51 status, rv = pcall(request, 'nvim_get_proc_children', 0) 52 eq(false, status) 53 eq("Invalid 'pid': 0", string.match(rv, 'Invalid.*')) 54 55 -- Assume PID 99999 does not exist. 56 status, rv = pcall(request, 'nvim_get_proc_children', 99999) 57 eq(true, status) 58 eq({}, rv) 59 end) 60 end) 61 62 describe('nvim_get_proc', function() 63 it('returns process info', function() 64 local pid = fn.getpid() 65 local pinfo = request('nvim_get_proc', pid) 66 eq((is_os('win') and 'nvim.exe' or 'nvim'), pinfo.name) 67 eq(pid, pinfo.pid) 68 eq('number', type(pinfo.ppid)) 69 neq(pid, pinfo.ppid) 70 end) 71 72 it('validation', function() 73 local status, rv = pcall(request, 'nvim_get_proc', -1) 74 eq(false, status) 75 eq("Invalid 'pid': -1", string.match(rv, 'Invalid.*')) 76 77 status, rv = pcall(request, 'nvim_get_proc', 0) 78 eq(false, status) 79 eq("Invalid 'pid': 0", string.match(rv, 'Invalid.*')) 80 81 -- Assume PID 99999 does not exist. 82 status, rv = pcall(request, 'nvim_get_proc', 99999) 83 eq(true, status) 84 eq(NIL, rv) 85 end) 86 end) 87 end)