robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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