test_exit.vim 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. " Tests for exiting Vim.
  2. source shared.vim
  3. source check.vim
  4. func Test_exiting()
  5. let after =<< trim [CODE]
  6. au QuitPre * call writefile(["QuitPre"], "Xtestout")
  7. au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
  8. quit
  9. [CODE]
  10. if RunVim([], after, '')
  11. call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout'))
  12. endif
  13. call delete('Xtestout')
  14. let after =<< trim [CODE]
  15. au QuitPre * call writefile(["QuitPre"], "Xtestout")
  16. au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
  17. help
  18. wincmd w
  19. quit
  20. [CODE]
  21. if RunVim([], after, '')
  22. call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout'))
  23. endif
  24. call delete('Xtestout')
  25. let after =<< trim [CODE]
  26. au QuitPre * call writefile(["QuitPre"], "Xtestout")
  27. au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
  28. split
  29. new
  30. qall
  31. [CODE]
  32. if RunVim([], after, '')
  33. call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout'))
  34. endif
  35. call delete('Xtestout')
  36. " ExitPre autocommand splits the window, so that it's no longer the last one.
  37. let after =<< trim [CODE]
  38. au QuitPre * call writefile(["QuitPre"], "Xtestout", "a")
  39. au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
  40. augroup nasty
  41. au ExitPre * split
  42. augroup END
  43. quit
  44. augroup nasty
  45. au! ExitPre
  46. augroup END
  47. quit
  48. [CODE]
  49. if RunVim([], after, '')
  50. call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'],
  51. \ readfile('Xtestout'))
  52. endif
  53. call delete('Xtestout')
  54. " ExitPre autocommand splits and closes the window, so that there is still
  55. " one window but it's a different one.
  56. let after =<< trim [CODE]
  57. au QuitPre * call writefile(["QuitPre"], "Xtestout", "a")
  58. au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
  59. augroup nasty
  60. au ExitPre * split | only
  61. augroup END
  62. quit
  63. augroup nasty
  64. au! ExitPre
  65. augroup END
  66. quit
  67. [CODE]
  68. if RunVim([], after, '')
  69. call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'],
  70. \ readfile('Xtestout'))
  71. endif
  72. call delete('Xtestout')
  73. " ExitPre autocommand also executed on :wqall
  74. let after =<< trim [CODE]
  75. au QuitPre * call writefile(["QuitPre"], "Xtestout", "a")
  76. au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
  77. wqall
  78. [CODE]
  79. if RunVim([], after, '')
  80. call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout'))
  81. endif
  82. call delete('Xtestout')
  83. endfunc
  84. " Test for getting the Vim exit code from v:exiting
  85. func Test_exit_code()
  86. call assert_equal(v:null, v:exiting)
  87. let before =<< trim [CODE]
  88. au QuitPre * call writefile(['qp = ' .. v:exiting], 'Xtestout', 'a')
  89. au ExitPre * call writefile(['ep = ' .. v:exiting], 'Xtestout', 'a')
  90. au VimLeavePre * call writefile(['lp = ' .. v:exiting], 'Xtestout', 'a')
  91. au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout', 'a')
  92. [CODE]
  93. if RunVim(before, ['quit'], '')
  94. call assert_equal(['qp = v:null', 'ep = v:null', 'lp = 0', 'l = 0'], readfile('Xtestout'))
  95. endif
  96. call delete('Xtestout')
  97. if RunVim(before, ['cquit'], '')
  98. call assert_equal(['lp = 1', 'l = 1'], readfile('Xtestout'))
  99. endif
  100. call delete('Xtestout')
  101. if RunVim(before, ['cquit 4'], '')
  102. call assert_equal(['lp = 4', 'l = 4'], readfile('Xtestout'))
  103. endif
  104. call delete('Xtestout')
  105. endfunc
  106. func Test_exit_error_reading_input()
  107. throw 'Skipped: Nvim does not exit after stdin is read'
  108. CheckNotGui
  109. CheckNotMSWindows
  110. " The early exit causes memory not to be freed somehow
  111. CheckNotAsan
  112. CheckNotValgrind
  113. call writefile([":au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout')", ":tabnew", "q:"], 'Xscript', 'b')
  114. " Nvim requires "-s -" to read stdin as Normal mode input
  115. " if RunVim([], [], '<Xscript')
  116. if RunVim([], [], '-s - <Xscript')
  117. call assert_equal(1, v:shell_error)
  118. call assert_equal(['l = 1'], readfile('Xtestout'))
  119. endif
  120. call delete('Xscript')
  121. call delete('Xtestout')
  122. endfun
  123. " vim: shiftwidth=2 sts=2 expandtab