channel_spec.lua 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local Screen = require('test.functional.ui.screen')
  3. local clear = helpers.clear
  4. local eq = helpers.eq
  5. local eval = helpers.eval
  6. local command = helpers.command
  7. local pcall_err = helpers.pcall_err
  8. local feed = helpers.feed
  9. local poke_eventloop = helpers.poke_eventloop
  10. describe('terminal channel is closed and later released if', function()
  11. local screen
  12. before_each(function()
  13. clear()
  14. screen = Screen.new()
  15. screen:attach()
  16. end)
  17. it('opened by nvim_open_term() and deleted by :bdelete!', function()
  18. command([[let id = nvim_open_term(0, {})]])
  19. local chans = eval('len(nvim_list_chans())')
  20. -- channel hasn't been released yet
  21. eq("Vim(call):Can't send data to closed stream",
  22. pcall_err(command, [[bdelete! | call chansend(id, 'test')]]))
  23. -- channel has been released after one main loop iteration
  24. eq(chans - 1, eval('len(nvim_list_chans())'))
  25. end)
  26. it('opened by nvim_open_term(), closed by chanclose(), and deleted by pressing a key', function()
  27. command('let id = nvim_open_term(0, {})')
  28. local chans = eval('len(nvim_list_chans())')
  29. -- channel has been closed but not released
  30. eq("Vim(call):Can't send data to closed stream",
  31. pcall_err(command, [[call chanclose(id) | call chansend(id, 'test')]]))
  32. screen:expect({any='%[Terminal closed%]'})
  33. eq(chans, eval('len(nvim_list_chans())'))
  34. -- delete terminal
  35. feed('i<CR>')
  36. -- need to first process input
  37. poke_eventloop()
  38. -- channel has been released after another main loop iteration
  39. eq(chans - 1, eval('len(nvim_list_chans())'))
  40. end)
  41. it('opened by nvim_open_term(), closed by chanclose(), and deleted by :bdelete', function()
  42. command('let id = nvim_open_term(0, {})')
  43. local chans = eval('len(nvim_list_chans())')
  44. -- channel has been closed but not released
  45. eq("Vim(call):Can't send data to closed stream",
  46. pcall_err(command, [[call chanclose(id) | call chansend(id, 'test')]]))
  47. screen:expect({any='%[Terminal closed%]'})
  48. eq(chans, eval('len(nvim_list_chans())'))
  49. -- channel still hasn't been released yet
  50. eq("Vim(call):Can't send data to closed stream",
  51. pcall_err(command, [[bdelete | call chansend(id, 'test')]]))
  52. -- channel has been released after one main loop iteration
  53. eq(chans - 1, eval('len(nvim_list_chans())'))
  54. end)
  55. it('opened by termopen(), exited, and deleted by pressing a key', function()
  56. command([[let id = termopen('echo')]])
  57. local chans = eval('len(nvim_list_chans())')
  58. -- wait for process to exit
  59. screen:expect({any='%[Process exited 0%]'})
  60. -- process has exited but channel has't been released
  61. eq("Vim(call):Can't send data to closed stream",
  62. pcall_err(command, [[call chansend(id, 'test')]]))
  63. eq(chans, eval('len(nvim_list_chans())'))
  64. -- delete terminal
  65. feed('i<CR>')
  66. -- need to first process input
  67. poke_eventloop()
  68. -- channel has been released after another main loop iteration
  69. eq(chans - 1, eval('len(nvim_list_chans())'))
  70. end)
  71. -- This indirectly covers #16264
  72. it('opened by termopen(), exited, and deleted by :bdelete', function()
  73. command([[let id = termopen('echo')]])
  74. local chans = eval('len(nvim_list_chans())')
  75. -- wait for process to exit
  76. screen:expect({any='%[Process exited 0%]'})
  77. -- process has exited but channel hasn't been released
  78. eq("Vim(call):Can't send data to closed stream",
  79. pcall_err(command, [[call chansend(id, 'test')]]))
  80. eq(chans, eval('len(nvim_list_chans())'))
  81. -- channel still hasn't been released yet
  82. eq("Vim(call):Can't send data to closed stream",
  83. pcall_err(command, [[bdelete | call chansend(id, 'test')]]))
  84. -- channel has been released after one main loop iteration
  85. eq(chans - 1, eval('len(nvim_list_chans())'))
  86. end)
  87. end)