proc_spec.lua 2.6 KB

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