diff options
| author | b-r-o-c-k <brockmammen@gmail.com> | 2018-04-14 14:17:51 -0500 | 
|---|---|---|
| committer | b-r-o-c-k <brockmammen@gmail.com> | 2018-04-14 14:17:51 -0500 | 
| commit | ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f (patch) | |
| tree | 92de2079e80f5f289dd87a54af123cb7d90c3058 /test/functional/api/proc_spec.lua | |
| parent | 78bc52ea5397c092d01cd08296fe1dc85d998329 (diff) | |
| parent | ef4feab0e75be19c5f41d70a001db980b72090f5 (diff) | |
| download | rneovim-ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f.tar.gz rneovim-ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f.tar.bz2 rneovim-ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f.zip  | |
Merge branch 'master' into s-dash-stdin
Diffstat (limited to 'test/functional/api/proc_spec.lua')
| -rw-r--r-- | test/functional/api/proc_spec.lua | 81 | 
1 files changed, 81 insertions, 0 deletions
diff --git a/test/functional/api/proc_spec.lua b/test/functional/api/proc_spec.lua new file mode 100644 index 0000000000..d99c26b6c2 --- /dev/null +++ b/test/functional/api/proc_spec.lua @@ -0,0 +1,81 @@ +local helpers = require('test.functional.helpers')(after_each) + +local clear = helpers.clear +local eq = helpers.eq +local funcs = helpers.funcs +local iswin = helpers.iswin +local nvim_argv = helpers.nvim_argv +local ok = helpers.ok +local request = helpers.request +local retry = helpers.retry +local NIL = helpers.NIL + +describe('api', function() +  before_each(clear) + +  describe('nvim_get_proc_children', function() +    it('returns child process ids', function() +      local this_pid = funcs.getpid() + +      local job1 = funcs.jobstart(nvim_argv) +      retry(nil, nil, function() +        eq(1, #request('nvim_get_proc_children', this_pid)) +      end) + +      local job2 = funcs.jobstart(nvim_argv) +      retry(nil, nil, function() +        eq(2, #request('nvim_get_proc_children', this_pid)) +      end) + +      funcs.jobstop(job1) +      retry(nil, nil, function() +        eq(1, #request('nvim_get_proc_children', this_pid)) +      end) + +      funcs.jobstop(job2) +      retry(nil, nil, function() +        eq(0, #request('nvim_get_proc_children', this_pid)) +      end) +    end) + +    it('validates input', function() +      local status, rv = pcall(request, "nvim_get_proc_children", -1) +      eq(false, status) +      eq("Invalid pid: -1", string.match(rv, "Invalid.*")) + +      status, rv = pcall(request, "nvim_get_proc_children", 0) +      eq(false, status) +      eq("Invalid pid: 0", string.match(rv, "Invalid.*")) + +      -- Assume PID 99999 does not exist. +      status, rv = pcall(request, "nvim_get_proc_children", 99999) +      eq(true, status) +      eq({}, rv) +    end) +  end) + +  describe('nvim_get_proc', function() +    it('returns process info', function() +      local pid = funcs.getpid() +      local pinfo = request('nvim_get_proc', pid) +      eq((iswin() and 'nvim.exe' or 'nvim'), pinfo.name) +      ok(pinfo.pid == pid) +      ok(type(pinfo.ppid) == 'number' and pinfo.ppid ~= pid) +    end) + +    it('validates input', function() +      local status, rv = pcall(request, "nvim_get_proc", -1) +      eq(false, status) +      eq("Invalid pid: -1", string.match(rv, "Invalid.*")) + +      status, rv = pcall(request, "nvim_get_proc", 0) +      eq(false, status) +      eq("Invalid pid: 0", string.match(rv, "Invalid.*")) + +      -- Assume PID 99999 does not exist. +      status, rv = pcall(request, "nvim_get_proc", 99999) +      eq(true, status) +      eq(NIL, rv) +    end) +  end) +end)  | 
