blob: a4041d72526bca8e1f1f80d212575b77730a6409 [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
8
Bram Moolenaarb81bc772017-08-11 22:45:01 +02009let s:python = PythonProg()
10
Bram Moolenaar94053a52017-08-01 21:44:33 +020011" Open a terminal with a shell, assign the job to g:job and return the buffer
12" number.
Bram Moolenaar05aafed2017-08-11 19:12:11 +020013func Run_shell_in_terminal(options)
14 let buf = term_start(&shell, a:options)
Bram Moolenaarc6df10e2017-07-29 20:15:08 +020015
16 let termlist = term_list()
17 call assert_equal(1, len(termlist))
18 call assert_equal(buf, termlist[0])
19
20 let g:job = term_getjob(buf)
21 call assert_equal(v:t_job, type(g:job))
22
Bram Moolenaar35422f42017-08-05 16:33:56 +020023 let string = string({'job': term_getjob(buf)})
24 call assert_match("{'job': 'process \\d\\+ run'}", string)
25
Bram Moolenaar94053a52017-08-01 21:44:33 +020026 return buf
27endfunc
28
29" Stops the shell started by Run_shell_in_terminal().
30func Stop_shell_in_terminal(buf)
31 call term_sendkeys(a:buf, "exit\r")
Bram Moolenaarc6df10e2017-07-29 20:15:08 +020032 call WaitFor('job_status(g:job) == "dead"')
33 call assert_equal('dead', job_status(g:job))
Bram Moolenaar20e6cd02017-08-01 20:25:22 +020034endfunc
35
36func Test_terminal_basic()
Bram Moolenaar05aafed2017-08-11 19:12:11 +020037 let buf = Run_shell_in_terminal({})
Bram Moolenaar7c9aec42017-08-03 13:51:25 +020038 if has("unix")
39 call assert_match("^/dev/", job_info(g:job).tty)
40 call assert_match("^/dev/", term_gettty(''))
41 else
Bram Moolenaar5be8dd02017-08-03 20:52:19 +020042 call assert_match("^winpty://", job_info(g:job).tty)
43 call assert_match("^winpty://", term_gettty(''))
Bram Moolenaar7c9aec42017-08-03 13:51:25 +020044 endif
Bram Moolenaar2bb7b6b2017-08-13 20:58:33 +020045 call assert_equal('t', mode())
46 call assert_match('%aR[^\n]*running]', execute('ls'))
47
Bram Moolenaar94053a52017-08-01 21:44:33 +020048 call Stop_shell_in_terminal(buf)
49 call term_wait(buf)
Bram Moolenaar2bb7b6b2017-08-13 20:58:33 +020050 call assert_equal('n', mode())
51 call assert_match('%aF[^\n]*finished]', execute('ls'))
Bram Moolenaar20e6cd02017-08-01 20:25:22 +020052
Bram Moolenaar94053a52017-08-01 21:44:33 +020053 " closing window wipes out the terminal buffer a with finished job
54 close
55 call assert_equal("", bufname(buf))
56
Bram Moolenaar20e6cd02017-08-01 20:25:22 +020057 unlet g:job
58endfunc
59
60func Test_terminal_make_change()
Bram Moolenaar05aafed2017-08-11 19:12:11 +020061 let buf = Run_shell_in_terminal({})
Bram Moolenaar94053a52017-08-01 21:44:33 +020062 call Stop_shell_in_terminal(buf)
Bram Moolenaar20e6cd02017-08-01 20:25:22 +020063 call term_wait(buf)
64
65 setlocal modifiable
66 exe "normal Axxx\<Esc>"
67 call assert_fails(buf . 'bwipe', 'E517')
68 undo
69
Bram Moolenaarc6df10e2017-07-29 20:15:08 +020070 exe buf . 'bwipe'
71 unlet g:job
72endfunc
73
Bram Moolenaar94053a52017-08-01 21:44:33 +020074func Test_terminal_wipe_buffer()
Bram Moolenaar05aafed2017-08-11 19:12:11 +020075 let buf = Run_shell_in_terminal({})
Bram Moolenaareb44a682017-08-03 22:44:55 +020076 call assert_fails(buf . 'bwipe', 'E517')
77 exe buf . 'bwipe!'
Bram Moolenaar94053a52017-08-01 21:44:33 +020078 call WaitFor('job_status(g:job) == "dead"')
79 call assert_equal('dead', job_status(g:job))
80 call assert_equal("", bufname(buf))
81
82 unlet g:job
83endfunc
84
85func Test_terminal_hide_buffer()
Bram Moolenaar05aafed2017-08-11 19:12:11 +020086 let buf = Run_shell_in_terminal({})
Bram Moolenaar94053a52017-08-01 21:44:33 +020087 quit
88 for nr in range(1, winnr('$'))
89 call assert_notequal(winbufnr(nr), buf)
90 endfor
91 call assert_true(bufloaded(buf))
92 call assert_true(buflisted(buf))
93
94 exe 'split ' . buf . 'buf'
95 call Stop_shell_in_terminal(buf)
96 exe buf . 'bwipe'
97
98 unlet g:job
99endfunc
100
Bram Moolenaar3c3a80d2017-08-03 17:06:45 +0200101func! s:Nasty_exit_cb(job, st)
102 exe g:buf . 'bwipe!'
103 let g:buf = 0
104endfunc
105
106func Test_terminal_nasty_cb()
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200107 let cmd = Get_cat_123_cmd()
Bram Moolenaar3c3a80d2017-08-03 17:06:45 +0200108 let g:buf = term_start(cmd, {'exit_cb': function('s:Nasty_exit_cb')})
109 let g:job = term_getjob(g:buf)
110
111 call WaitFor('job_status(g:job) == "dead"')
112 call WaitFor('g:buf == 0')
113 unlet g:buf
114 unlet g:job
115 call delete('Xtext')
116endfunc
117
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200118func Check_123(buf)
Bram Moolenaar5c838a32017-08-02 22:10:34 +0200119 let l = term_scrape(a:buf, 0)
120 call assert_true(len(l) == 0)
121 let l = term_scrape(a:buf, 999)
122 call assert_true(len(l) == 0)
Bram Moolenaar9c844842017-08-01 18:41:21 +0200123 let l = term_scrape(a:buf, 1)
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200124 call assert_true(len(l) > 0)
125 call assert_equal('1', l[0].chars)
126 call assert_equal('2', l[1].chars)
127 call assert_equal('3', l[2].chars)
128 call assert_equal('#00e000', l[0].fg)
129 if &background == 'light'
130 call assert_equal('#ffffff', l[0].bg)
131 else
132 call assert_equal('#000000', l[0].bg)
133 endif
134
Bram Moolenaar5c838a32017-08-02 22:10:34 +0200135 let l = term_getline(a:buf, -1)
136 call assert_equal('', l)
137 let l = term_getline(a:buf, 0)
138 call assert_equal('', l)
139 let l = term_getline(a:buf, 999)
140 call assert_equal('', l)
Bram Moolenaar9c844842017-08-01 18:41:21 +0200141 let l = term_getline(a:buf, 1)
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200142 call assert_equal('123', l)
143endfunc
144
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200145func Get_cat_123_cmd()
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200146 if has('win32')
Bram Moolenaar3c3a80d2017-08-03 17:06:45 +0200147 return 'cmd /c "cls && color 2 && echo 123"'
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200148 else
149 call writefile(["\<Esc>[32m123"], 'Xtext')
Bram Moolenaar3c3a80d2017-08-03 17:06:45 +0200150 return "cat Xtext"
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200151 endif
Bram Moolenaar3c3a80d2017-08-03 17:06:45 +0200152endfunc
153
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200154func Test_terminal_scrape_123()
155 let cmd = Get_cat_123_cmd()
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200156 let buf = term_start(cmd)
157
158 let termlist = term_list()
159 call assert_equal(1, len(termlist))
160 call assert_equal(buf, termlist[0])
161
Bram Moolenaarf144a3f2017-07-30 18:02:12 +0200162 " Nothing happens with invalid buffer number
163 call term_wait(1234)
164
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200165 call term_wait(buf)
Bram Moolenaar620d0642017-08-03 21:08:05 +0200166 if has('win32')
167 " TODO: this should not be needed
168 sleep 100m
169 endif
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200170 call Check_123(buf)
171
172 " Must still work after the job ended.
173 let g:job = term_getjob(buf)
174 call WaitFor('job_status(g:job) == "dead"')
175 call term_wait(buf)
176 call Check_123(buf)
177
178 exe buf . 'bwipe'
Bram Moolenaarf144a3f2017-07-30 18:02:12 +0200179 call delete('Xtext')
Bram Moolenaarc6df10e2017-07-29 20:15:08 +0200180endfunc
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200181
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200182func Test_terminal_scrape_multibyte()
183 if !has('multi_byte')
184 return
185 endif
186 call writefile(["léttまrs"], 'Xtext')
187 if has('win32')
Bram Moolenaar36783932017-08-14 23:07:30 +0200188 " Run cmd with UTF-8 codepage to make the type command print the expected
189 " multibyte characters.
190 let g:buf = term_start("cmd /K chcp 65001")
191 call term_sendkeys(g:buf, "type Xtext\<CR>")
192 call term_sendkeys(g:buf, "exit\<CR>")
193 let g:line = 4
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200194 else
Bram Moolenaar36783932017-08-14 23:07:30 +0200195 let g:buf = term_start("cat Xtext")
196 let g:line = 1
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200197 endif
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200198
Bram Moolenaar36783932017-08-14 23:07:30 +0200199 call WaitFor('term_scrape(g:buf, g:line)[0].chars == "l"')
200 let l = term_scrape(g:buf, g:line)
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200201 call assert_true(len(l) >= 7)
202 call assert_equal('l', l[0].chars)
203 call assert_equal('é', l[1].chars)
204 call assert_equal(1, l[1].width)
205 call assert_equal('t', l[2].chars)
206 call assert_equal('t', l[3].chars)
207 call assert_equal('ま', l[4].chars)
208 call assert_equal(2, l[4].width)
209 call assert_equal('r', l[5].chars)
210 call assert_equal('s', l[6].chars)
211
Bram Moolenaarc0870612017-08-14 22:01:16 +0200212 let g:job = term_getjob(g:buf)
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200213 call WaitFor('job_status(g:job) == "dead"')
Bram Moolenaarc0870612017-08-14 22:01:16 +0200214 call term_wait(g:buf)
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200215
Bram Moolenaarc0870612017-08-14 22:01:16 +0200216 exe g:buf . 'bwipe'
217 unlet g:buf
Bram Moolenaar36783932017-08-14 23:07:30 +0200218 unlet g:line
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200219 call delete('Xtext')
220endfunc
221
Bram Moolenaarf8d57a52017-08-07 20:38:42 +0200222func Test_terminal_scroll()
223 call writefile(range(1, 200), 'Xtext')
224 if has('win32')
225 let cmd = 'cmd /c "type Xtext"'
226 else
227 let cmd = "cat Xtext"
228 endif
229 let buf = term_start(cmd)
230
231 let g:job = term_getjob(buf)
232 call WaitFor('job_status(g:job) == "dead"')
233 call term_wait(buf)
234 if has('win32')
235 " TODO: this should not be needed
236 sleep 100m
237 endif
238
Bram Moolenaar82b9ca02017-08-08 23:06:46 +0200239 let scrolled = term_getscrolled(buf)
Bram Moolenaarf8d57a52017-08-07 20:38:42 +0200240 call assert_equal('1', getline(1))
Bram Moolenaar82b9ca02017-08-08 23:06:46 +0200241 call assert_equal('1', term_getline(buf, 1 - scrolled))
Bram Moolenaarf8d57a52017-08-07 20:38:42 +0200242 call assert_equal('49', getline(49))
Bram Moolenaar82b9ca02017-08-08 23:06:46 +0200243 call assert_equal('49', term_getline(buf, 49 - scrolled))
Bram Moolenaarf8d57a52017-08-07 20:38:42 +0200244 call assert_equal('200', getline(200))
Bram Moolenaar82b9ca02017-08-08 23:06:46 +0200245 call assert_equal('200', term_getline(buf, 200 - scrolled))
Bram Moolenaarf8d57a52017-08-07 20:38:42 +0200246
247 exe buf . 'bwipe'
248 call delete('Xtext')
249endfunc
250
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200251func Test_terminal_size()
Bram Moolenaar33a43be2017-08-06 21:36:22 +0200252 let cmd = Get_cat_123_cmd()
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200253
Bram Moolenaarb2412082017-08-20 18:09:14 +0200254 exe 'terminal ++rows=5 ' . cmd
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200255 let size = term_getsize('')
256 bwipe!
257 call assert_equal(5, size[0])
258
Bram Moolenaar08d384f2017-08-11 21:51:23 +0200259 call term_start(cmd, {'term_rows': 6})
260 let size = term_getsize('')
261 bwipe!
262 call assert_equal(6, size[0])
263
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200264 vsplit
Bram Moolenaarb2412082017-08-20 18:09:14 +0200265 exe 'terminal ++rows=5 ++cols=33 ' . cmd
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200266 let size = term_getsize('')
267 bwipe!
268 call assert_equal([5, 33], size)
269
Bram Moolenaar08d384f2017-08-11 21:51:23 +0200270 call term_start(cmd, {'term_rows': 6, 'term_cols': 36})
271 let size = term_getsize('')
272 bwipe!
273 call assert_equal([6, 36], size)
274
Bram Moolenaarb2412082017-08-20 18:09:14 +0200275 exe 'vertical terminal ++cols=20 ' . cmd
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200276 let size = term_getsize('')
277 bwipe!
278 call assert_equal(20, size[1])
279
Bram Moolenaar08d384f2017-08-11 21:51:23 +0200280 call term_start(cmd, {'vertical': 1, 'term_cols': 26})
281 let size = term_getsize('')
282 bwipe!
283 call assert_equal(26, size[1])
284
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200285 split
Bram Moolenaarb2412082017-08-20 18:09:14 +0200286 exe 'vertical terminal ++rows=6 ++cols=20 ' . cmd
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200287 let size = term_getsize('')
288 bwipe!
289 call assert_equal([6, 20], size)
Bram Moolenaar08d384f2017-08-11 21:51:23 +0200290
291 call term_start(cmd, {'vertical': 1, 'term_rows': 7, 'term_cols': 27})
292 let size = term_getsize('')
293 bwipe!
294 call assert_equal([7, 27], size)
Bram Moolenaarda43b612017-08-11 22:27:50 +0200295endfunc
296
297func Test_terminal_curwin()
298 let cmd = Get_cat_123_cmd()
299 call assert_equal(1, winnr('$'))
300
301 split dummy
302 exe 'terminal ++curwin ' . cmd
303 call assert_equal(2, winnr('$'))
304 bwipe!
305
306 split dummy
307 call term_start(cmd, {'curwin': 1})
308 call assert_equal(2, winnr('$'))
309 bwipe!
310
311 split dummy
312 call setline(1, 'change')
313 call assert_fails('terminal ++curwin ' . cmd, 'E37:')
314 call assert_equal(2, winnr('$'))
315 exe 'terminal! ++curwin ' . cmd
316 call assert_equal(2, winnr('$'))
317 bwipe!
318
319 split dummy
320 call setline(1, 'change')
321 call assert_fails("call term_start(cmd, {'curwin': 1})", 'E37:')
322 call assert_equal(2, winnr('$'))
323 bwipe!
324
325 split dummy
326 bwipe!
Bram Moolenaar08d384f2017-08-11 21:51:23 +0200327
Bram Moolenaarcfcc0222017-08-05 17:13:48 +0200328endfunc
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200329
Bram Moolenaar37c45832017-08-12 16:01:04 +0200330func Test_finish_open_close()
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200331 call assert_equal(1, winnr('$'))
332
Bram Moolenaarb81bc772017-08-11 22:45:01 +0200333 if s:python != ''
334 let cmd = s:python . " test_short_sleep.py"
335 let waittime = 500
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200336 else
Bram Moolenaarb81bc772017-08-11 22:45:01 +0200337 echo 'This will take five seconds...'
338 let waittime = 2000
339 if has('win32')
340 let cmd = $windir . '\system32\timeout.exe 1'
341 else
342 let cmd = 'sleep 1'
343 endif
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200344 endif
Bram Moolenaarb81bc772017-08-11 22:45:01 +0200345
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200346 exe 'terminal ++close ' . cmd
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200347 call assert_equal(2, winnr('$'))
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200348 wincmd p
Bram Moolenaarb81bc772017-08-11 22:45:01 +0200349 call WaitFor("winnr('$') == 1", waittime)
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200350 call assert_equal(1, winnr('$'))
351
352 call term_start(cmd, {'term_finish': 'close'})
353 call assert_equal(2, winnr('$'))
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200354 wincmd p
Bram Moolenaarb81bc772017-08-11 22:45:01 +0200355 call WaitFor("winnr('$') == 1", waittime)
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200356 call assert_equal(1, winnr('$'))
357
358 exe 'terminal ++open ' . cmd
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200359 close
Bram Moolenaarb81bc772017-08-11 22:45:01 +0200360 call WaitFor("winnr('$') == 2", waittime)
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200361 call assert_equal(2, winnr('$'))
362 bwipe
363
364 call term_start(cmd, {'term_finish': 'open'})
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200365 close
Bram Moolenaarb81bc772017-08-11 22:45:01 +0200366 call WaitFor("winnr('$') == 2", waittime)
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200367 call assert_equal(2, winnr('$'))
Bram Moolenaar8cad9302017-08-12 14:32:32 +0200368 bwipe
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200369
Bram Moolenaar8cad9302017-08-12 14:32:32 +0200370 exe 'terminal ++hidden ++open ' . cmd
371 call assert_equal(1, winnr('$'))
372 call WaitFor("winnr('$') == 2", waittime)
373 call assert_equal(2, winnr('$'))
374 bwipe
375
376 call term_start(cmd, {'term_finish': 'open', 'hidden': 1})
377 call assert_equal(1, winnr('$'))
378 call WaitFor("winnr('$') == 2", waittime)
379 call assert_equal(2, winnr('$'))
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200380 bwipe
Bram Moolenaar37c45832017-08-12 16:01:04 +0200381
382 call assert_fails("call term_start(cmd, {'term_opencmd': 'open'})", 'E475:')
383 call assert_fails("call term_start(cmd, {'term_opencmd': 'split %x'})", 'E475:')
384 call assert_fails("call term_start(cmd, {'term_opencmd': 'split %d and %s'})", 'E475:')
385 call assert_fails("call term_start(cmd, {'term_opencmd': 'split % and %d'})", 'E475:')
386
387 call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d'})
388 close
389 call WaitFor("winnr('$') == 2", waittime)
390 call assert_equal(2, winnr('$'))
391 call assert_equal(4, winheight(0))
392 bwipe
393
Bram Moolenaardd693ce2017-08-10 23:15:19 +0200394endfunc
Bram Moolenaar05aafed2017-08-11 19:12:11 +0200395
396func Test_terminal_cwd()
397 if !has('unix')
398 return
399 endif
400 call mkdir('Xdir')
401 let buf = term_start('pwd', {'cwd': 'Xdir'})
402 sleep 100m
403 call term_wait(buf)
404 call assert_equal(getcwd() . '/Xdir', getline(1))
405
406 exe buf . 'bwipe'
407 call delete('Xdir', 'rf')
408endfunc
409
410func Test_terminal_env()
411 if !has('unix')
412 return
413 endif
Bram Moolenaarc0870612017-08-14 22:01:16 +0200414 let g:buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}})
Bram Moolenaar51c23682017-08-14 21:45:00 +0200415 " Wait for the shell to display a prompt
Bram Moolenaarc0870612017-08-14 22:01:16 +0200416 call WaitFor('term_getline(g:buf, 1) != ""')
417 call term_sendkeys(g:buf, "echo $TESTENV\r")
418 call term_wait(g:buf)
419 call Stop_shell_in_terminal(g:buf)
Bram Moolenaar51c23682017-08-14 21:45:00 +0200420 call WaitFor('getline(2) == "correct"')
Bram Moolenaar05aafed2017-08-11 19:12:11 +0200421 call assert_equal('correct', getline(2))
422
Bram Moolenaarc0870612017-08-14 22:01:16 +0200423 exe g:buf . 'bwipe'
424 unlet g:buf
Bram Moolenaar05aafed2017-08-11 19:12:11 +0200425endfunc
Bram Moolenaar679653e2017-08-13 14:13:19 +0200426
427" must be last, we can't go back from GUI to terminal
428func Test_zz_terminal_in_gui()
Bram Moolenaar9f0139a2017-08-13 20:26:20 +0200429 if !CanRunGui()
Bram Moolenaar679653e2017-08-13 14:13:19 +0200430 return
431 endif
432 gui -f
433
434 call assert_equal(1, winnr('$'))
435 let buf = Run_shell_in_terminal({'term_finish': 'close'})
436 call Stop_shell_in_terminal(buf)
437 call term_wait(buf)
438
439 " closing window wipes out the terminal buffer a with finished job
440 call WaitFor("winnr('$') == 1")
441 call assert_equal(1, winnr('$'))
442 call assert_equal("", bufname(buf))
443
444 unlet g:job
445endfunc
Bram Moolenaardcaa6132017-08-13 17:13:09 +0200446
447func Test_terminal_list_args()
448 let buf = term_start([&shell, &shellcmdflag, 'echo "123"'])
449 call assert_fails(buf . 'bwipe', 'E517')
450 exe buf . 'bwipe!'
451 call assert_equal("", bufname(buf))
452endfunction
Bram Moolenaar97bd5e62017-08-18 20:50:30 +0200453
454func Test_terminal_noblock()
Bram Moolenaard21f8b52017-08-19 15:40:01 +0200455 let g:buf = term_start(&shell)
Bram Moolenaar97bd5e62017-08-18 20:50:30 +0200456
457 for c in ['a','b','c','d','e','f','g','h','i','j','k']
Bram Moolenaard21f8b52017-08-19 15:40:01 +0200458 call term_sendkeys(g:buf, 'echo ' . repeat(c, 5000) . "\<cr>")
Bram Moolenaar97bd5e62017-08-18 20:50:30 +0200459 endfor
Bram Moolenaard21f8b52017-08-19 15:40:01 +0200460 call term_sendkeys(g:buf, "echo done\<cr>")
461 let g:lnum = term_getsize(g:buf)[0] - 1
462 call WaitFor('term_getline(g:buf, g:lnum) =~ "done"', 3000)
463 call assert_match('done', term_getline(g:buf, g:lnum))
Bram Moolenaar97bd5e62017-08-18 20:50:30 +0200464
Bram Moolenaard21f8b52017-08-19 15:40:01 +0200465 let g:job = term_getjob(g:buf)
466 call Stop_shell_in_terminal(g:buf)
467 call term_wait(g:buf)
468 unlet g:buf
469 unlet g:job
470 unlet g:lnum
Bram Moolenaar97bd5e62017-08-18 20:50:30 +0200471 bwipe
472endfunc