blob: d8e40d1c3e496f7e863c9a1fc789d956577f53ec [file] [log] [blame]
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02001" Tests for the terminal window.
2
Bram Moolenaarea5d6fa2017-08-18 21:07:11 +02003if !has('terminal')
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02004 finish
5endif
6
7source shared.vim
Bram Moolenaar25cdd9c2018-03-10 20:28:12 +01008source screendump.vim
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009
Bram Moolenaarb81bc772017-08-11 22:45:01 +020010let s:python = PythonProg()
11
Bram Moolenaar94053a52017-08-01 21:44:33 +020012" Open a terminal with a shell, assign the job to g:job and return the buffer
13" number.
Bram Moolenaar05aafed2017-08-11 19:12:11 +020014func Run_shell_in_terminal(options)
Bram Moolenaarba6febd2017-10-30 21:56:23 +010015 if has('win32')
16 let buf = term_start([&shell,'/k'], a:options)
17 else
18 let buf = term_start(&shell, a:options)
19 endif
Bram Moolenaarc6df10e2017-07-29 20:15:08 +020020
21 let termlist = term_list()
22 call assert_equal(1, len(termlist))
23 call assert_equal(buf, termlist[0])
24
25 let g:job = term_getjob(buf)
26 call assert_equal(v:t_job, type(g:job))
27
Bram Moolenaar35422f42017-08-05 16:33:56 +020028 let string = string({'job': term_getjob(buf)})
29 call assert_match("{'job': 'process \\d\\+ run'}", string)
30
Bram Moolenaar94053a52017-08-01 21:44:33 +020031 return buf
32endfunc
33
Bram Moolenaar20e6cd02017-08-01 20:25:22 +020034func Test_terminal_basic()
Bram Moolenaarb00fdf62017-09-21 22:16:21 +020035 au BufWinEnter * if &buftype == 'terminal' | let b:done = 'yes' | endif
Bram Moolenaar05aafed2017-08-11 19:12:11 +020036 let buf = Run_shell_in_terminal({})
Bram Moolenaarb00fdf62017-09-21 22:16:21 +020037
Bram Moolenaar7c9aec42017-08-03 13:51:25 +020038 if has("unix")
Bram Moolenaar2dc9d262017-09-08 14:39:30 +020039 call assert_match('^/dev/', job_info(g:job).tty_out)
40 call assert_match('^/dev/', term_gettty(''))
Bram Moolenaar7c9aec42017-08-03 13:51:25 +020041 else
Bram Moolenaar2dc9d262017-09-08 14:39:30 +020042 call assert_match('^\\\\.\\pipe\\', job_info(g:job).tty_out)
43 call assert_match('^\\\\.\\pipe\\', term_gettty(''))
Bram Moolenaar7c9aec42017-08-03 13:51:25 +020044 endif
Bram Moolenaar2bb7b6b2017-08-13 20:58:33 +020045 call assert_equal('t', mode())
Bram Moolenaarb00fdf62017-09-21 22:16:21 +020046 call assert_equal('yes', b:done)
Bram Moolenaar2bb7b6b2017-08-13 20:58:33 +020047 call assert_match('%aR[^\n]*running]', execute('ls'))
48
Bram Moolenaar94053a52017-08-01 21:44:33 +020049 call Stop_shell_in_terminal(buf)
50 call term_wait(buf)
Bram Moolenaar2bb7b6b2017-08-13 20:58:33 +020051 call assert_equal('n', mode())
52 call assert_match('%aF[^\n]*finished]', execute('ls'))
Bram Moolenaar20e6cd02017-08-01 20:25:22 +020053
Bram Moolenaar94053a52017-08-01 21:44:33 +020054 " closing window wipes out the terminal buffer a with finished job
55 close
56 call assert_equal("", bufname(buf))
57
Bram Moolenaarb00fdf62017-09-21 22:16:21 +020058 au! BufWinEnter
Bram Moolenaar20e6cd02017-08-01 20:25:22 +020059 unlet g:job
60endfunc
61
62func Test_terminal_make_change()
Bram Moolenaar05aafed2017-08-11 19:12:11 +020063 let buf = Run_shell_in_terminal({})
Bram Moolenaar94053a52017-08-01 21:44:33 +020064 call Stop_shell_in_terminal(buf)
Bram Moolenaar20e6cd02017-08-01 20:25:22 +020065 call term_wait(buf)
66
67 setlocal modifiable
68 exe "normal Axxx\<Esc>"
69 call assert_fails(buf . 'bwipe', 'E517')
70 undo
71
Bram Moolenaarc6df10e2017-07-29 20:15:08 +020072 exe buf . 'bwipe'
73 unlet g:job
74endfunc
75
Bram Moolenaar94053a52017-08-01 21:44:33 +020076func Test_terminal_wipe_buffer()
Bram Moolenaar05aafed2017-08-11 19:12:11 +020077 let buf = Run_shell_in_terminal({})
Bram Moolenaareb44a682017-08-03 22:44:55 +020078 call assert_fails(buf . 'bwipe', 'E517')
79 exe buf . 'bwipe!'
Bram Moolenaar94053a52017-08-01 21:44:33 +020080 call WaitFor('job_status(g:job) == "dead"')
81 call assert_equal('dead', job_status(g:job))
82 call assert_equal("", bufname(buf))
83
84 unlet g:job
85endfunc
86
Bram Moolenaar8adb0d02017-09-17 19:08:02 +020087func Test_terminal_split_quit()
88 let buf = Run_shell_in_terminal({})
89 call term_wait(buf)
90 split
91 quit!
92 call term_wait(buf)
93 sleep 50m
94 call assert_equal('run', job_status(g:job))
95
96 quit!
97 call WaitFor('job_status(g:job) == "dead"')
98 call assert_equal('dead', job_status(g:job))
99
100 exe buf . 'bwipe'
101 unlet g:job
102endfunc
103
Bram Moolenaar94053a52017-08-01 21:44:33 +0200104func Test_terminal_hide_buffer()
Bram Moolenaar05aafed2017-08-11 19:12:11 +0200105 let buf = Run_shell_in_terminal({})
Bram Moolenaar97a80e42017-08-30 13:31:49 +0200106 setlocal bufhidden=hide
Bram Moolenaar94053a52017-08-01 21:44:33 +0200107 quit
108 for nr in range(1, winnr('$'))
109 call assert_notequal(winbufnr(nr), buf)
110 endfor
111 call assert_true(bufloaded(buf))
112 call assert_true(buflisted(buf))
113
114 exe 'split ' . buf . 'buf'
115 call Stop_shell_in_terminal(buf)
116 exe buf . 'bwipe'
117
118 unlet g:job
119endfunc
120
Bram Moolenaar3c3a80d2017-08-03 17:06:45 +0200121func! s:Nasty_exit_cb(job, st)
122 exe g:buf . 'bwipe!'
123 let g:buf = 0
124endfunc
125
Bram Moolenaar9d189612017-09-09 18:11:00 +0200126func Get_cat_123_cmd()
127 if has('win32')
128 return 'cmd /c "cls && color 2 && echo 123"'
129 else
130 call writefile(["\<Esc>[32m123"], 'Xtext')
131 return "cat Xtext"
132 endif
133endfunc
134
Bram Moolenaar3c3a80d2017-08-03 17:06:45 +0200135func Test_terminal_nasty_cb()
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200136 let cmd = Get_cat_123_cmd()
Bram Moolenaar3c3a80d2017-08-03 17:06:45 +0200137 let g:buf = term_start(cmd, {'exit_cb': function('s:Nasty_exit_cb')})
138 let g:job = term_getjob(g:buf)
139
140 call WaitFor('job_status(g:job) == "dead"')
141 call WaitFor('g:buf == 0')
142 unlet g:buf
143 unlet g:job
144 call delete('Xtext')
145endfunc
146
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200147func Check_123(buf)
Bram Moolenaar5c838a32017-08-02 22:10:34 +0200148 let l = term_scrape(a:buf, 0)
149 call assert_true(len(l) == 0)
150 let l = term_scrape(a:buf, 999)
151 call assert_true(len(l) == 0)
Bram Moolenaar9c844842017-08-01 18:41:21 +0200152 let l = term_scrape(a:buf, 1)
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200153 call assert_true(len(l) > 0)
154 call assert_equal('1', l[0].chars)
155 call assert_equal('2', l[1].chars)
156 call assert_equal('3', l[2].chars)
157 call assert_equal('#00e000', l[0].fg)
158 if &background == 'light'
159 call assert_equal('#ffffff', l[0].bg)
160 else
161 call assert_equal('#000000', l[0].bg)
162 endif
163
Bram Moolenaar5c838a32017-08-02 22:10:34 +0200164 let l = term_getline(a:buf, -1)
165 call assert_equal('', l)
166 let l = term_getline(a:buf, 0)
167 call assert_equal('', l)
168 let l = term_getline(a:buf, 999)
169 call assert_equal('', l)
Bram Moolenaar9c844842017-08-01 18:41:21 +0200170 let l = term_getline(a:buf, 1)
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200171 call assert_equal('123', l)
172endfunc
173
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200174func Test_terminal_scrape_123()
175 let cmd = Get_cat_123_cmd()
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200176 let buf = term_start(cmd)
177
178 let termlist = term_list()
179 call assert_equal(1, len(termlist))
180 call assert_equal(buf, termlist[0])
181
Bram Moolenaarf144a3f2017-07-30 18:02:12 +0200182 " Nothing happens with invalid buffer number
183 call term_wait(1234)
184
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200185 call term_wait(buf)
Bram Moolenaar17833372017-09-04 22:23:19 +0200186 " On MS-Windows we first get a startup message of two lines, wait for the
Bram Moolenaar1bfdc072017-09-05 20:19:42 +0200187 " "cls" to happen, after that we have one line with three characters.
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100188 call WaitFor({-> len(term_scrape(buf, 1)) == 3})
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200189 call Check_123(buf)
190
191 " Must still work after the job ended.
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100192 let job = term_getjob(buf)
193 call WaitFor({-> job_status(job) == "dead"})
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200194 call term_wait(buf)
195 call Check_123(buf)
196
197 exe buf . 'bwipe'
Bram Moolenaarf144a3f2017-07-30 18:02:12 +0200198 call delete('Xtext')
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200199endfunc
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200200
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200201func Test_terminal_scrape_multibyte()
202 if !has('multi_byte')
203 return
204 endif
205 call writefile(["léttまrs"], 'Xtext')
206 if has('win32')
Bram Moolenaar36783932017-08-14 23:07:30 +0200207 " Run cmd with UTF-8 codepage to make the type command print the expected
208 " multibyte characters.
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100209 let buf = term_start("cmd /K chcp 65001")
210 call term_sendkeys(buf, "type Xtext\<CR>")
211 call term_sendkeys(buf, "exit\<CR>")
212 let line = 4
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200213 else
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100214 let buf = term_start("cat Xtext")
215 let line = 1
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200216 endif
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200217
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100218 call WaitFor({-> len(term_scrape(buf, line)) >= 7 && term_scrape(buf, line)[0].chars == "l"})
219 let l = term_scrape(buf, line)
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200220 call assert_true(len(l) >= 7)
221 call assert_equal('l', l[0].chars)
222 call assert_equal('é', l[1].chars)
223 call assert_equal(1, l[1].width)
224 call assert_equal('t', l[2].chars)
225 call assert_equal('t', l[3].chars)
226 call assert_equal('ま', l[4].chars)
227 call assert_equal(2, l[4].width)
228 call assert_equal('r', l[5].chars)
229 call assert_equal('s', l[6].chars)
230
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100231 let job = term_getjob(buf)
232 call WaitFor({-> job_status(job) == "dead"})
233 call term_wait(buf)
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200234
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100235 exe buf . 'bwipe'
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200236 call delete('Xtext')
237endfunc
238
Bram Moolenaarf8d57a52017-08-07 20:38:42 +0200239func Test_terminal_scroll()
240 call writefile(range(1, 200), 'Xtext')
241 if has('win32')
242 let cmd = 'cmd /c "type Xtext"'
243 else
244 let cmd = "cat Xtext"
245 endif
246 let buf = term_start(cmd)
247
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100248 let job = term_getjob(buf)
249 call WaitFor({-> job_status(job) == "dead"})
Bram Moolenaarf8d57a52017-08-07 20:38:42 +0200250 call term_wait(buf)
251 if has('win32')
252 " TODO: this should not be needed
253 sleep 100m
254 endif
255
Bram Moolenaar82b9ca02017-08-08 23:06:46 +0200256 let scrolled = term_getscrolled(buf)
Bram Moolenaarf8d57a52017-08-07 20:38:42 +0200257 call assert_equal('1', getline(1))
Bram Moolenaar82b9ca02017-08-08 23:06:46 +0200258 call assert_equal('1', term_getline(buf, 1 - scrolled))
Bram Moolenaarf8d57a52017-08-07 20:38:42 +0200259 call assert_equal('49', getline(49))
Bram Moolenaar82b9ca02017-08-08 23:06:46 +0200260 call assert_equal('49', term_getline(buf, 49 - scrolled))
Bram Moolenaarf8d57a52017-08-07 20:38:42 +0200261 call assert_equal('200', getline(200))
Bram Moolenaar82b9ca02017-08-08 23:06:46 +0200262 call assert_equal('200', term_getline(buf, 200 - scrolled))
Bram Moolenaarf8d57a52017-08-07 20:38:42 +0200263
264 exe buf . 'bwipe'
265 call delete('Xtext')
266endfunc
267
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200268func Test_terminal_size()
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200269 let cmd = Get_cat_123_cmd()
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200270
Bram Moolenaarb2412082017-08-20 18:09:14 +0200271 exe 'terminal ++rows=5 ' . cmd
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200272 let size = term_getsize('')
273 bwipe!
274 call assert_equal(5, size[0])
275
Bram Moolenaar08d384f2017-08-11 21:51:23 +0200276 call term_start(cmd, {'term_rows': 6})
277 let size = term_getsize('')
278 bwipe!
279 call assert_equal(6, size[0])
280
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200281 vsplit
Bram Moolenaarb2412082017-08-20 18:09:14 +0200282 exe 'terminal ++rows=5 ++cols=33 ' . cmd
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200283 let size = term_getsize('')
284 bwipe!
285 call assert_equal([5, 33], size)
286
Bram Moolenaar08d384f2017-08-11 21:51:23 +0200287 call term_start(cmd, {'term_rows': 6, 'term_cols': 36})
288 let size = term_getsize('')
289 bwipe!
290 call assert_equal([6, 36], size)
291
Bram Moolenaarb2412082017-08-20 18:09:14 +0200292 exe 'vertical terminal ++cols=20 ' . cmd
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200293 let size = term_getsize('')
294 bwipe!
295 call assert_equal(20, size[1])
296
Bram Moolenaar08d384f2017-08-11 21:51:23 +0200297 call term_start(cmd, {'vertical': 1, 'term_cols': 26})
298 let size = term_getsize('')
299 bwipe!
300 call assert_equal(26, size[1])
301
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200302 split
Bram Moolenaarb2412082017-08-20 18:09:14 +0200303 exe 'vertical terminal ++rows=6 ++cols=20 ' . cmd
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200304 let size = term_getsize('')
305 bwipe!
306 call assert_equal([6, 20], size)
Bram Moolenaar08d384f2017-08-11 21:51:23 +0200307
308 call term_start(cmd, {'vertical': 1, 'term_rows': 7, 'term_cols': 27})
309 let size = term_getsize('')
310 bwipe!
311 call assert_equal([7, 27], size)
Bram Moolenaar9d654a82017-09-03 19:52:17 +0200312
313 call delete('Xtext')
Bram Moolenaarda43b612017-08-11 22:27:50 +0200314endfunc
315
316func Test_terminal_curwin()
317 let cmd = Get_cat_123_cmd()
318 call assert_equal(1, winnr('$'))
319
320 split dummy
321 exe 'terminal ++curwin ' . cmd
322 call assert_equal(2, winnr('$'))
323 bwipe!
324
325 split dummy
326 call term_start(cmd, {'curwin': 1})
327 call assert_equal(2, winnr('$'))
328 bwipe!
329
330 split dummy
331 call setline(1, 'change')
332 call assert_fails('terminal ++curwin ' . cmd, 'E37:')
333 call assert_equal(2, winnr('$'))
334 exe 'terminal! ++curwin ' . cmd
335 call assert_equal(2, winnr('$'))
336 bwipe!
337
338 split dummy
339 call setline(1, 'change')
340 call assert_fails("call term_start(cmd, {'curwin': 1})", 'E37:')
341 call assert_equal(2, winnr('$'))
342 bwipe!
343
344 split dummy
345 bwipe!
Bram Moolenaar9d654a82017-09-03 19:52:17 +0200346 call delete('Xtext')
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200347endfunc
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200348
Bram Moolenaarff546792017-11-21 14:47:57 +0100349func s:get_sleep_cmd()
Bram Moolenaarb81bc772017-08-11 22:45:01 +0200350 if s:python != ''
351 let cmd = s:python . " test_short_sleep.py"
352 let waittime = 500
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200353 else
Bram Moolenaarb81bc772017-08-11 22:45:01 +0200354 echo 'This will take five seconds...'
355 let waittime = 2000
356 if has('win32')
357 let cmd = $windir . '\system32\timeout.exe 1'
358 else
359 let cmd = 'sleep 1'
360 endif
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200361 endif
Bram Moolenaarff546792017-11-21 14:47:57 +0100362 return [cmd, waittime]
363endfunc
364
365func Test_terminal_finish_open_close()
366 call assert_equal(1, winnr('$'))
367
368 let [cmd, waittime] = s:get_sleep_cmd()
Bram Moolenaarb81bc772017-08-11 22:45:01 +0200369
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200370 exe 'terminal ++close ' . cmd
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200371 call assert_equal(2, winnr('$'))
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200372 wincmd p
Bram Moolenaarb81bc772017-08-11 22:45:01 +0200373 call WaitFor("winnr('$') == 1", waittime)
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200374
375 call term_start(cmd, {'term_finish': 'close'})
376 call assert_equal(2, winnr('$'))
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200377 wincmd p
Bram Moolenaarb81bc772017-08-11 22:45:01 +0200378 call WaitFor("winnr('$') == 1", waittime)
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200379 call assert_equal(1, winnr('$'))
380
381 exe 'terminal ++open ' . cmd
Bram Moolenaar97a80e42017-08-30 13:31:49 +0200382 close!
Bram Moolenaarb81bc772017-08-11 22:45:01 +0200383 call WaitFor("winnr('$') == 2", waittime)
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200384 call assert_equal(2, winnr('$'))
385 bwipe
386
387 call term_start(cmd, {'term_finish': 'open'})
Bram Moolenaar97a80e42017-08-30 13:31:49 +0200388 close!
Bram Moolenaarb81bc772017-08-11 22:45:01 +0200389 call WaitFor("winnr('$') == 2", waittime)
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200390 call assert_equal(2, winnr('$'))
Bram Moolenaar8cad9302017-08-12 14:32:32 +0200391 bwipe
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200392
Bram Moolenaar8cad9302017-08-12 14:32:32 +0200393 exe 'terminal ++hidden ++open ' . cmd
394 call assert_equal(1, winnr('$'))
395 call WaitFor("winnr('$') == 2", waittime)
396 call assert_equal(2, winnr('$'))
397 bwipe
398
399 call term_start(cmd, {'term_finish': 'open', 'hidden': 1})
400 call assert_equal(1, winnr('$'))
401 call WaitFor("winnr('$') == 2", waittime)
402 call assert_equal(2, winnr('$'))
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200403 bwipe
Bram Moolenaar37c45832017-08-12 16:01:04 +0200404
405 call assert_fails("call term_start(cmd, {'term_opencmd': 'open'})", 'E475:')
406 call assert_fails("call term_start(cmd, {'term_opencmd': 'split %x'})", 'E475:')
407 call assert_fails("call term_start(cmd, {'term_opencmd': 'split %d and %s'})", 'E475:')
408 call assert_fails("call term_start(cmd, {'term_opencmd': 'split % and %d'})", 'E475:')
409
410 call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d'})
Bram Moolenaar97a80e42017-08-30 13:31:49 +0200411 close!
Bram Moolenaar37c45832017-08-12 16:01:04 +0200412 call WaitFor("winnr('$') == 2", waittime)
413 call assert_equal(2, winnr('$'))
414 call assert_equal(4, winheight(0))
415 bwipe
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200416endfunc
Bram Moolenaar05aafed2017-08-11 19:12:11 +0200417
418func Test_terminal_cwd()
Bram Moolenaare9f6fd22017-09-10 14:25:49 +0200419 if !executable('pwd')
Bram Moolenaar05aafed2017-08-11 19:12:11 +0200420 return
421 endif
422 call mkdir('Xdir')
423 let buf = term_start('pwd', {'cwd': 'Xdir'})
Bram Moolenaare9f6fd22017-09-10 14:25:49 +0200424 call WaitFor('"Xdir" == fnamemodify(getline(1), ":t")')
425 call assert_equal('Xdir', fnamemodify(getline(1), ":t"))
Bram Moolenaar05aafed2017-08-11 19:12:11 +0200426
427 exe buf . 'bwipe'
428 call delete('Xdir', 'rf')
429endfunc
430
Bram Moolenaar52dbb5e2017-11-21 18:11:27 +0100431func Test_terminal_servername()
432 if !has('clientserver')
433 return
434 endif
435 let g:buf = Run_shell_in_terminal({})
436 " Wait for the shell to display a prompt
437 call WaitFor('term_getline(g:buf, 1) != ""')
438 if has('win32')
439 call term_sendkeys(g:buf, "echo %VIM_SERVERNAME%\r")
440 else
441 call term_sendkeys(g:buf, "echo $VIM_SERVERNAME\r")
442 endif
443 call term_wait(g:buf)
444 call Stop_shell_in_terminal(g:buf)
445 call WaitFor('getline(2) == v:servername')
446 call assert_equal(v:servername, getline(2))
447
448 exe g:buf . 'bwipe'
449 unlet g:buf
450endfunc
451
Bram Moolenaar05aafed2017-08-11 19:12:11 +0200452func Test_terminal_env()
Bram Moolenaarc0870612017-08-14 22:01:16 +0200453 let g:buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}})
Bram Moolenaar51c23682017-08-14 21:45:00 +0200454 " Wait for the shell to display a prompt
Bram Moolenaarc0870612017-08-14 22:01:16 +0200455 call WaitFor('term_getline(g:buf, 1) != ""')
Bram Moolenaarba6febd2017-10-30 21:56:23 +0100456 if has('win32')
457 call term_sendkeys(g:buf, "echo %TESTENV%\r")
458 else
459 call term_sendkeys(g:buf, "echo $TESTENV\r")
460 endif
Bram Moolenaarc0870612017-08-14 22:01:16 +0200461 call term_wait(g:buf)
462 call Stop_shell_in_terminal(g:buf)
Bram Moolenaar51c23682017-08-14 21:45:00 +0200463 call WaitFor('getline(2) == "correct"')
Bram Moolenaar05aafed2017-08-11 19:12:11 +0200464 call assert_equal('correct', getline(2))
465
Bram Moolenaarc0870612017-08-14 22:01:16 +0200466 exe g:buf . 'bwipe'
467 unlet g:buf
Bram Moolenaar05aafed2017-08-11 19:12:11 +0200468endfunc
Bram Moolenaar679653e2017-08-13 14:13:19 +0200469
470" must be last, we can't go back from GUI to terminal
471func Test_zz_terminal_in_gui()
Bram Moolenaar9f0139a2017-08-13 20:26:20 +0200472 if !CanRunGui()
Bram Moolenaar679653e2017-08-13 14:13:19 +0200473 return
474 endif
Bram Moolenaar97f65fa2017-08-29 20:42:07 +0200475
476 " Ignore the "failed to create input context" error.
477 call test_ignore_error('E285:')
478
Bram Moolenaar679653e2017-08-13 14:13:19 +0200479 gui -f
480
481 call assert_equal(1, winnr('$'))
482 let buf = Run_shell_in_terminal({'term_finish': 'close'})
483 call Stop_shell_in_terminal(buf)
484 call term_wait(buf)
485
486 " closing window wipes out the terminal buffer a with finished job
487 call WaitFor("winnr('$') == 1")
488 call assert_equal(1, winnr('$'))
489 call assert_equal("", bufname(buf))
490
491 unlet g:job
492endfunc
Bram Moolenaardcaa6132017-08-13 17:13:09 +0200493
494func Test_terminal_list_args()
495 let buf = term_start([&shell, &shellcmdflag, 'echo "123"'])
496 call assert_fails(buf . 'bwipe', 'E517')
497 exe buf . 'bwipe!'
498 call assert_equal("", bufname(buf))
499endfunction
Bram Moolenaar97bd5e62017-08-18 20:50:30 +0200500
501func Test_terminal_noblock()
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100502 let buf = term_start(&shell)
Bram Moolenaard8d85bf2017-09-03 18:08:00 +0200503 if has('mac')
504 " The shell or something else has a problem dealing with more than 1000
505 " characters at the same time.
506 let len = 1000
507 else
508 let len = 5000
509 endif
Bram Moolenaar97bd5e62017-08-18 20:50:30 +0200510
511 for c in ['a','b','c','d','e','f','g','h','i','j','k']
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100512 call term_sendkeys(buf, 'echo ' . repeat(c, len) . "\<cr>")
Bram Moolenaar97bd5e62017-08-18 20:50:30 +0200513 endfor
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100514 call term_sendkeys(buf, "echo done\<cr>")
Bram Moolenaareef05312017-08-20 20:21:23 +0200515
516 " On MS-Windows there is an extra empty line below "done". Find "done" in
517 " the last-but-one or the last-but-two line.
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100518 let lnum = term_getsize(buf)[0] - 1
Bram Moolenaar21810142018-02-02 18:30:36 +0100519 call WaitFor({-> term_getline(buf, lnum) =~ "done" || term_getline(buf, lnum - 1) =~ "done"}, 10000)
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100520 let line = term_getline(buf, lnum)
Bram Moolenaareef05312017-08-20 20:21:23 +0200521 if line !~ 'done'
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100522 let line = term_getline(buf, lnum - 1)
Bram Moolenaareef05312017-08-20 20:21:23 +0200523 endif
524 call assert_match('done', line)
Bram Moolenaar97bd5e62017-08-18 20:50:30 +0200525
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100526 let g:job = term_getjob(buf)
527 call Stop_shell_in_terminal(buf)
528 call term_wait(buf)
Bram Moolenaard21f8b52017-08-19 15:40:01 +0200529 unlet g:job
Bram Moolenaar97bd5e62017-08-18 20:50:30 +0200530 bwipe
531endfunc
Bram Moolenaar37819ed2017-08-20 19:33:47 +0200532
533func Test_terminal_write_stdin()
Bram Moolenaar3346cc42017-09-02 14:54:21 +0200534 if !executable('wc')
Bram Moolenaardada6d22017-09-02 17:18:35 +0200535 throw 'skipped: wc command not available'
Bram Moolenaar37819ed2017-08-20 19:33:47 +0200536 endif
537 new
538 call setline(1, ['one', 'two', 'three'])
539 %term wc
Bram Moolenaardada6d22017-09-02 17:18:35 +0200540 call WaitFor('getline("$") =~ "3"')
Bram Moolenaar3346cc42017-09-02 14:54:21 +0200541 let nrs = split(getline('$'))
Bram Moolenaar37819ed2017-08-20 19:33:47 +0200542 call assert_equal(['3', '3', '14'], nrs)
543 bwipe
544
Bram Moolenaardada6d22017-09-02 17:18:35 +0200545 new
Bram Moolenaar37819ed2017-08-20 19:33:47 +0200546 call setline(1, ['one', 'two', 'three', 'four'])
547 2,3term wc
Bram Moolenaardada6d22017-09-02 17:18:35 +0200548 call WaitFor('getline("$") =~ "2"')
Bram Moolenaar3346cc42017-09-02 14:54:21 +0200549 let nrs = split(getline('$'))
Bram Moolenaar37819ed2017-08-20 19:33:47 +0200550 call assert_equal(['2', '2', '10'], nrs)
551 bwipe
552
Bram Moolenaardada6d22017-09-02 17:18:35 +0200553 if executable('python')
554 new
555 call setline(1, ['print("hello")'])
556 1term ++eof=exit() python
557 " MS-Windows echoes the input, Unix doesn't.
558 call WaitFor('getline("$") =~ "exit" || getline(1) =~ "hello"')
559 if getline(1) =~ 'hello'
560 call assert_equal('hello', getline(1))
561 else
562 call assert_equal('hello', getline(line('$') - 1))
563 endif
564 bwipe
565
566 if has('win32')
567 new
568 call setline(1, ['print("hello")'])
569 1term ++eof=<C-Z> python
570 call WaitFor('getline("$") =~ "Z"')
571 call assert_equal('hello', getline(line('$') - 1))
572 bwipe
573 endif
574 endif
575
Bram Moolenaar37819ed2017-08-20 19:33:47 +0200576 bwipe!
577endfunc
Bram Moolenaar13ebb032017-08-26 22:02:51 +0200578
579func Test_terminal_no_cmd()
Bram Moolenaar13ebb032017-08-26 22:02:51 +0200580 " Todo: make this work in the GUI
581 if !has('gui_running')
582 return
583 endif
584 let buf = term_start('NONE', {})
585 call assert_notequal(0, buf)
586
Bram Moolenaar2dc9d262017-09-08 14:39:30 +0200587 let pty = job_info(term_getjob(buf))['tty_out']
Bram Moolenaar13ebb032017-08-26 22:02:51 +0200588 call assert_notequal('', pty)
Bram Moolenaar2dc9d262017-09-08 14:39:30 +0200589 if has('win32')
Bram Moolenaare738a1a2017-09-16 17:42:41 +0200590 silent exe '!start cmd /c "echo look here > ' . pty . '"'
Bram Moolenaar2dc9d262017-09-08 14:39:30 +0200591 else
592 call system('echo "look here" > ' . pty)
593 endif
Bram Moolenaare738a1a2017-09-16 17:42:41 +0200594 let g:buf = buf
595 call WaitFor('term_getline(g:buf, 1) =~ "look here"')
Bram Moolenaar2dc9d262017-09-08 14:39:30 +0200596
Bram Moolenaare738a1a2017-09-16 17:42:41 +0200597 call assert_match('look here', term_getline(buf, 1))
Bram Moolenaar13ebb032017-08-26 22:02:51 +0200598 bwipe!
599endfunc
Bram Moolenaar9d654a82017-09-03 19:52:17 +0200600
601func Test_terminal_special_chars()
602 " this file name only works on Unix
603 if !has('unix')
604 return
605 endif
606 call mkdir('Xdir with spaces')
607 call writefile(['x'], 'Xdir with spaces/quoted"file')
608 term ls Xdir\ with\ spaces/quoted\"file
609 call WaitFor('term_getline("", 1) =~ "quoted"')
610 call assert_match('quoted"file', term_getline('', 1))
611 call term_wait('')
612
613 call delete('Xdir with spaces', 'rf')
614 bwipe
615endfunc
Bram Moolenaare88fc7a2017-09-03 20:59:40 +0200616
617func Test_terminal_wrong_options()
618 call assert_fails('call term_start(&shell, {
619 \ "in_io": "file",
620 \ "in_name": "xxx",
621 \ "out_io": "file",
622 \ "out_name": "xxx",
623 \ "err_io": "file",
624 \ "err_name": "xxx"
625 \ })', 'E474:')
626 call assert_fails('call term_start(&shell, {
627 \ "out_buf": bufnr("%")
628 \ })', 'E474:')
629 call assert_fails('call term_start(&shell, {
630 \ "err_buf": bufnr("%")
631 \ })', 'E474:')
632endfunc
633
634func Test_terminal_redir_file()
Bram Moolenaar17833372017-09-04 22:23:19 +0200635 " TODO: this should work on MS-Window
636 if has('unix')
637 let cmd = Get_cat_123_cmd()
638 let buf = term_start(cmd, {'out_io': 'file', 'out_name': 'Xfile'})
639 call term_wait(buf)
640 call WaitFor('len(readfile("Xfile")) > 0')
641 call assert_match('123', readfile('Xfile')[0])
Bram Moolenaare9f6fd22017-09-10 14:25:49 +0200642 let g:job = term_getjob(buf)
643 call WaitFor('job_status(g:job) == "dead"')
Bram Moolenaar17833372017-09-04 22:23:19 +0200644 call delete('Xfile')
Bram Moolenaar2dc9d262017-09-08 14:39:30 +0200645 bwipe
Bram Moolenaar17833372017-09-04 22:23:19 +0200646 endif
Bram Moolenaare88fc7a2017-09-03 20:59:40 +0200647
648 if has('unix')
Bram Moolenaare88fc7a2017-09-03 20:59:40 +0200649 call writefile(['one line'], 'Xfile')
650 let buf = term_start('cat', {'in_io': 'file', 'in_name': 'Xfile'})
651 call term_wait(buf)
652 call WaitFor('term_getline(' . buf . ', 1) == "one line"')
653 call assert_equal('one line', term_getline(buf, 1))
Bram Moolenaar8b53b792017-09-05 20:29:25 +0200654 let g:job = term_getjob(buf)
655 call WaitFor('job_status(g:job) == "dead"')
Bram Moolenaare88fc7a2017-09-03 20:59:40 +0200656 bwipe
657 call delete('Xfile')
658 endif
659endfunc
Bram Moolenaar69fbc9e2017-09-14 20:37:57 +0200660
661func TerminalTmap(remap)
662 let buf = Run_shell_in_terminal({})
663 call assert_equal('t', mode())
664
665 if a:remap
666 tmap 123 456
667 else
668 tnoremap 123 456
669 endif
Bram Moolenaar461fe502017-12-05 12:30:03 +0100670 " don't use abcde, it's an existing command
671 tmap 456 abxde
Bram Moolenaar69fbc9e2017-09-14 20:37:57 +0200672 call assert_equal('456', maparg('123', 't'))
Bram Moolenaar461fe502017-12-05 12:30:03 +0100673 call assert_equal('abxde', maparg('456', 't'))
Bram Moolenaar69fbc9e2017-09-14 20:37:57 +0200674 call feedkeys("123", 'tx')
Bram Moolenaar1514e8f2017-09-16 17:35:13 +0200675 let g:buf = buf
Bram Moolenaar461fe502017-12-05 12:30:03 +0100676 call WaitFor("term_getline(g:buf,term_getcursor(g:buf)[0]) =~ 'abxde\\|456'")
Bram Moolenaar69fbc9e2017-09-14 20:37:57 +0200677 let lnum = term_getcursor(buf)[0]
678 if a:remap
Bram Moolenaar461fe502017-12-05 12:30:03 +0100679 call assert_match('abxde', term_getline(buf, lnum))
Bram Moolenaar69fbc9e2017-09-14 20:37:57 +0200680 else
681 call assert_match('456', term_getline(buf, lnum))
682 endif
683
684 call term_sendkeys(buf, "\r")
685 call Stop_shell_in_terminal(buf)
686 call term_wait(buf)
687
688 tunmap 123
689 tunmap 456
690 call assert_equal('', maparg('123', 't'))
691 close
692 unlet g:job
693endfunc
694
695func Test_terminal_tmap()
696 call TerminalTmap(1)
697 call TerminalTmap(0)
698endfunc
Bram Moolenaar059db5c2017-10-15 22:42:23 +0200699
700func Test_terminal_wall()
701 let buf = Run_shell_in_terminal({})
702 wall
703 call Stop_shell_in_terminal(buf)
704 call term_wait(buf)
705 exe buf . 'bwipe'
706 unlet g:job
707endfunc
Bram Moolenaar6daeef12017-10-15 22:56:49 +0200708
Bram Moolenaar7a760922018-02-19 23:10:02 +0100709func Test_terminal_wqall()
710 let buf = Run_shell_in_terminal({})
711 call assert_fails('wqall', 'E948')
712 call Stop_shell_in_terminal(buf)
713 call term_wait(buf)
714 exe buf . 'bwipe'
715 unlet g:job
716endfunc
717
Bram Moolenaar6daeef12017-10-15 22:56:49 +0200718func Test_terminal_composing_unicode()
719 let save_enc = &encoding
720 set encoding=utf-8
721
722 if has('win32')
723 let cmd = "cmd /K chcp 65001"
724 let lnum = [3, 6, 9]
725 else
726 let cmd = &shell
727 let lnum = [1, 3, 5]
728 endif
729
730 enew
731 let buf = term_start(cmd, {'curwin': bufnr('')})
Bram Moolenaar3e1c6172017-11-02 16:58:00 +0100732 let g:job = term_getjob(buf)
Bram Moolenaar6daeef12017-10-15 22:56:49 +0200733 call term_wait(buf, 50)
734
735 " ascii + composing
736 let txt = "a\u0308bc"
737 call term_sendkeys(buf, "echo " . txt . "\r")
738 call term_wait(buf, 50)
739 call assert_match("echo " . txt, term_getline(buf, lnum[0]))
740 call assert_equal(txt, term_getline(buf, lnum[0] + 1))
741 let l = term_scrape(buf, lnum[0] + 1)
742 call assert_equal("a\u0308", l[0].chars)
743 call assert_equal("b", l[1].chars)
744 call assert_equal("c", l[2].chars)
745
746 " multibyte + composing
747 let txt = "\u304b\u3099\u304e\u304f\u3099\u3052\u3053\u3099"
748 call term_sendkeys(buf, "echo " . txt . "\r")
749 call term_wait(buf, 50)
750 call assert_match("echo " . txt, term_getline(buf, lnum[1]))
751 call assert_equal(txt, term_getline(buf, lnum[1] + 1))
752 let l = term_scrape(buf, lnum[1] + 1)
753 call assert_equal("\u304b\u3099", l[0].chars)
754 call assert_equal("\u304e", l[1].chars)
755 call assert_equal("\u304f\u3099", l[2].chars)
756 call assert_equal("\u3052", l[3].chars)
757 call assert_equal("\u3053\u3099", l[4].chars)
758
759 " \u00a0 + composing
760 let txt = "abc\u00a0\u0308"
761 call term_sendkeys(buf, "echo " . txt . "\r")
762 call term_wait(buf, 50)
763 call assert_match("echo " . txt, term_getline(buf, lnum[2]))
764 call assert_equal(txt, term_getline(buf, lnum[2] + 1))
765 let l = term_scrape(buf, lnum[2] + 1)
766 call assert_equal("\u00a0\u0308", l[3].chars)
767
768 call term_sendkeys(buf, "exit\r")
Bram Moolenaar3e1c6172017-11-02 16:58:00 +0100769 call WaitFor('job_status(g:job) == "dead"')
770 call assert_equal('dead', job_status(g:job))
Bram Moolenaar6daeef12017-10-15 22:56:49 +0200771 bwipe!
Bram Moolenaar3e1c6172017-11-02 16:58:00 +0100772 unlet g:job
Bram Moolenaar6daeef12017-10-15 22:56:49 +0200773 let &encoding = save_enc
774endfunc
Bram Moolenaarff546792017-11-21 14:47:57 +0100775
776func Test_terminal_aucmd_on_close()
777 fun Nop()
778 let s:called = 1
779 endfun
780
781 aug repro
782 au!
783 au BufWinLeave * call Nop()
784 aug END
785
786 let [cmd, waittime] = s:get_sleep_cmd()
787
788 call assert_equal(1, winnr('$'))
789 new
790 call setline(1, ['one', 'two'])
791 exe 'term ++close ' . cmd
792 wincmd p
793 call WaitFor("winnr('$') == 2", waittime)
794 call assert_equal(1, s:called)
795 bwipe!
796
797 unlet s:called
798 au! repro
799 delfunc Nop
800endfunc
Bram Moolenaarede35bb2018-01-26 20:05:18 +0100801
802func Test_terminal_term_start_empty_command()
803 let cmd = "call term_start('', {'curwin' : 1, 'term_finish' : 'close'})"
804 call assert_fails(cmd, 'E474')
805 let cmd = "call term_start('', {'curwin' : 1, 'term_finish' : 'close'})"
806 call assert_fails(cmd, 'E474')
807 let cmd = "call term_start({}, {'curwin' : 1, 'term_finish' : 'close'})"
808 call assert_fails(cmd, 'E474')
809 let cmd = "call term_start(0, {'curwin' : 1, 'term_finish' : 'close'})"
810 call assert_fails(cmd, 'E474')
811endfunc
Bram Moolenaarb50773c2018-01-30 22:31:19 +0100812
813func Test_terminal_response_to_control_sequence()
814 if !has('unix')
815 return
816 endif
817
818 let buf = Run_shell_in_terminal({})
819 call term_wait(buf)
820
Bram Moolenaard4a282f2018-02-02 18:22:31 +0100821 new
822 call setline(1, "\x1b[6n")
823 write! Xescape
824 bwipe
825 call term_sendkeys(buf, "cat Xescape\<cr>")
826
Bram Moolenaarb50773c2018-01-30 22:31:19 +0100827 " wait for the response of control sequence from libvterm (and send it to tty)
Bram Moolenaard4a282f2018-02-02 18:22:31 +0100828 sleep 200m
Bram Moolenaarb50773c2018-01-30 22:31:19 +0100829 call term_wait(buf)
Bram Moolenaard4a282f2018-02-02 18:22:31 +0100830
831 " Wait for output from tty to display, below an empty line.
832 " It should show \e3;1R, but only 1R may show up
833 call assert_match('\<\d\+R', term_getline(buf, 3))
Bram Moolenaarb50773c2018-01-30 22:31:19 +0100834
835 call term_sendkeys(buf, "\<c-c>")
836 call term_wait(buf)
837 call Stop_shell_in_terminal(buf)
838
839 exe buf . 'bwipe'
Bram Moolenaard4a282f2018-02-02 18:22:31 +0100840 call delete('Xescape')
Bram Moolenaarb50773c2018-01-30 22:31:19 +0100841 unlet g:job
842endfunc
Bram Moolenaar25cdd9c2018-03-10 20:28:12 +0100843
844" Run Vim in a terminal, then start a terminal in that Vim with a kill
845" argument, check that :qall works.
846func Test_terminal_qall_kill_arg()
847 if !CanRunVimInTerminal()
848 return
849 endif
850 let buf = RunVimInTerminal('', {})
851
852 " Open a terminal window and wait for the prompt to appear
853 call term_sendkeys(buf, ":term ++kill=kill\<CR>")
854 call WaitFor({-> term_getline(buf, 10) =~ '\[running]'})
855 call WaitFor({-> term_getline(buf, 1) !~ '^\s*$'})
856
857 " make Vim exit, it will kill the shell
858 call term_sendkeys(buf, "\<C-W>:qall\<CR>")
859 call WaitFor({-> term_getstatus(buf) == "finished"})
860
861 " close the terminal window where Vim was running
862 quit
863endfunc
864
865" Run Vim in a terminal, then start a terminal in that Vim with a kill
866" argument, check that :qall works.
867func Test_terminal_qall_kill_func()
868 if !CanRunVimInTerminal()
869 return
870 endif
871 let buf = RunVimInTerminal('', {})
872
873 " Open a terminal window and wait for the prompt to appear
874 call term_sendkeys(buf, ":term\<CR>")
875 call WaitFor({-> term_getline(buf, 10) =~ '\[running]'})
876 call WaitFor({-> term_getline(buf, 1) !~ '^\s*$'})
877
878 " set kill using term_setkill()
879 call term_sendkeys(buf, "\<C-W>:call term_setkill(bufnr('%'), 'kill')\<CR>")
880
881 " make Vim exit, it will kill the shell
882 call term_sendkeys(buf, "\<C-W>:qall\<CR>")
883 call WaitFor({-> term_getstatus(buf) == "finished"})
884
885 " close the terminal window where Vim was running
886 quit
887endfunc
Bram Moolenaar435acdb2018-03-10 20:51:25 +0100888
889" Run Vim in a terminal, then start a terminal in that Vim without a kill
890" argument, check that :confirm qall works.
891func Test_terminal_qall_prompt()
892 if !CanRunVimInTerminal()
893 return
894 endif
895 let buf = RunVimInTerminal('', {})
896
897 " Open a terminal window and wait for the prompt to appear
898 call term_sendkeys(buf, ":term\<CR>")
899 call WaitFor({-> term_getline(buf, 10) =~ '\[running]'})
900 call WaitFor({-> term_getline(buf, 1) !~ '^\s*$'})
901
902 " make Vim exit, it will prompt to kill the shell
903 call term_sendkeys(buf, "\<C-W>:confirm qall\<CR>")
904 call WaitFor({-> term_getline(buf, 20) =~ 'ancel:'})
905 call term_sendkeys(buf, "y")
906 call WaitFor({-> term_getstatus(buf) == "finished"})
907
908 " close the terminal window where Vim was running
909 quit
910endfunc
Bram Moolenaarb852c3e2018-03-11 16:55:36 +0100911
912func Test_terminalopen_autocmd()
913 augroup repro
914 au!
915 au TerminalOpen * let s:called += 1
916 augroup END
917
918 let s:called = 0
919
920 " Open a terminal window with :terminal
921 terminal
922 call assert_equal(1, s:called)
923 bwipe!
924
925 " Open a terminal window with term_start()
926 call term_start(&shell)
927 call assert_equal(2, s:called)
928 bwipe!
929
930 " Open a hidden terminal buffer with :terminal
931 terminal ++hidden
932 call assert_equal(3, s:called)
933 for buf in term_list()
934 exe buf . "bwipe!"
935 endfor
936
937 " Open a hidden terminal buffer with term_start()
938 let buf = term_start(&shell, {'hidden': 1})
939 call assert_equal(4, s:called)
940 exe buf . "bwipe!"
941
942 unlet s:called
943 au! repro
944endfunction