proc_spec.lua 2.5 KB

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