robin/laufey

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

zeertzjqvim-patch:9.1.2095: :wqall! doesn't quit when using :quit in BufWritePostb4e602dde5

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