blob: 6e70ad6cce929c97e8a8148cc262ae192504370a [file] [log] [blame]
Bram Moolenaar1112c0f2020-07-01 21:53:50 +02001" Tests for the terminal window.
2" This is split in two, because it can take a lot of time.
Bram Moolenaar18aa13d2020-07-11 13:09:36 +02003" See test_terminal.vim and test_terminal3.vim for further tests.
Bram Moolenaar1112c0f2020-07-01 21:53:50 +02004
5source check.vim
6CheckFeature terminal
7
8source shared.vim
9source screendump.vim
10source mouse.vim
11source term_util.vim
12
Bram Moolenaar1112c0f2020-07-01 21:53:50 +020013let $PROMPT_COMMAND=''
14
Bram Moolenaar1112c0f2020-07-01 21:53:50 +020015func Test_terminal_termwinsize_option_fixed()
16 CheckRunVimInTerminal
17 set termwinsize=6x40
18 let text = []
19 for n in range(10)
20 call add(text, repeat(n, 50))
21 endfor
22 call writefile(text, 'Xwinsize')
23 let buf = RunVimInTerminal('Xwinsize', {})
24 let win = bufwinid(buf)
25 call assert_equal([6, 40], term_getsize(buf))
26 call assert_equal(6, winheight(win))
27 call assert_equal(40, winwidth(win))
28
29 " resizing the window doesn't resize the terminal.
30 resize 10
31 vertical resize 60
32 call assert_equal([6, 40], term_getsize(buf))
33 call assert_equal(10, winheight(win))
34 call assert_equal(60, winwidth(win))
35
36 call StopVimInTerminal(buf)
37 call delete('Xwinsize')
38
Bram Moolenaare2e40752020-09-04 21:18:46 +020039 call assert_fails('set termwinsize=40', 'E474:')
40 call assert_fails('set termwinsize=10+40', 'E474:')
41 call assert_fails('set termwinsize=abc', 'E474:')
Bram Moolenaar1112c0f2020-07-01 21:53:50 +020042
43 set termwinsize=
44endfunc
45
46func Test_terminal_termwinsize_option_zero()
47 set termwinsize=0x0
48 let buf = Run_shell_in_terminal({})
49 let win = bufwinid(buf)
50 call assert_equal([winheight(win), winwidth(win)], term_getsize(buf))
51 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +020052 exe buf . 'bwipe'
53
54 set termwinsize=7x0
55 let buf = Run_shell_in_terminal({})
56 let win = bufwinid(buf)
57 call assert_equal([7, winwidth(win)], term_getsize(buf))
58 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +020059 exe buf . 'bwipe'
60
61 set termwinsize=0x33
62 let buf = Run_shell_in_terminal({})
63 let win = bufwinid(buf)
64 call assert_equal([winheight(win), 33], term_getsize(buf))
65 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +020066 exe buf . 'bwipe'
67
68 set termwinsize=
69endfunc
70
71func Test_terminal_termwinsize_minimum()
72 set termwinsize=10*50
73 vsplit
74 let buf = Run_shell_in_terminal({})
75 let win = bufwinid(buf)
76 call assert_inrange(10, 1000, winheight(win))
77 call assert_inrange(50, 1000, winwidth(win))
78 call assert_equal([winheight(win), winwidth(win)], term_getsize(buf))
79
80 resize 15
81 vertical resize 60
82 redraw
83 call assert_equal([15, 60], term_getsize(buf))
84 call assert_equal(15, winheight(win))
85 call assert_equal(60, winwidth(win))
86
87 resize 7
88 vertical resize 30
89 redraw
90 call assert_equal([10, 50], term_getsize(buf))
91 call assert_equal(7, winheight(win))
92 call assert_equal(30, winwidth(win))
93
94 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +020095 exe buf . 'bwipe'
96
97 set termwinsize=0*0
98 let buf = Run_shell_in_terminal({})
99 let win = bufwinid(buf)
100 call assert_equal([winheight(win), winwidth(win)], term_getsize(buf))
101 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200102 exe buf . 'bwipe'
103
104 set termwinsize=
105endfunc
106
Bram Moolenaarb936b792020-09-04 18:34:09 +0200107func Test_terminal_termwinsize_overruled()
108 let cmd = GetDummyCmd()
109 set termwinsize=5x43
110 let buf = term_start(cmd, #{term_rows: 7, term_cols: 50})
111 call TermWait(buf)
112 call assert_equal([7, 50], term_getsize(buf))
113 exe "bwipe! " .. buf
114
115 let buf = term_start(cmd, #{term_cols: 50})
116 call TermWait(buf)
117 call assert_equal([5, 50], term_getsize(buf))
118 exe "bwipe! " .. buf
119
120 let buf = term_start(cmd, #{term_rows: 7})
121 call TermWait(buf)
122 call assert_equal([7, 43], term_getsize(buf))
123 exe "bwipe! " .. buf
124
125 set termwinsize=
126endfunc
127
Bram Moolenaar2ce14582020-09-05 16:08:49 +0200128" hidden terminal must not change current window size
129func Test_terminal_hidden_winsize()
130 let cmd = GetDummyCmd()
131 let rows = winheight(0)
132 let buf = term_start(cmd, #{hidden: 1, term_rows: 10})
133 call assert_equal(rows, winheight(0))
134 call assert_equal([10, &columns], term_getsize(buf))
135 exe "bwipe! " .. buf
136endfunc
137
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200138func Test_terminal_termwinkey()
139 " make three tabpages, terminal in the middle
140 0tabnew
141 tabnext
142 tabnew
143 tabprev
144 call assert_equal(1, winnr('$'))
145 call assert_equal(2, tabpagenr())
146 let thiswin = win_getid()
147
148 let buf = Run_shell_in_terminal({})
149 let termwin = bufwinid(buf)
150 set termwinkey=<C-L>
151 call feedkeys("\<C-L>w", 'tx')
152 call assert_equal(thiswin, win_getid())
153 call feedkeys("\<C-W>w", 'tx')
154 call assert_equal(termwin, win_getid())
155
156 if has('langmap')
157 set langmap=xjyk
158 call feedkeys("\<C-L>x", 'tx')
159 call assert_equal(thiswin, win_getid())
160 call feedkeys("\<C-W>y", 'tx')
161 call assert_equal(termwin, win_getid())
162 set langmap=
163 endif
164
165 call feedkeys("\<C-L>gt", "xt")
166 call assert_equal(3, tabpagenr())
167 tabprev
168 call assert_equal(2, tabpagenr())
169 call assert_equal(termwin, win_getid())
170
171 call feedkeys("\<C-L>gT", "xt")
172 call assert_equal(1, tabpagenr())
173 tabnext
174 call assert_equal(2, tabpagenr())
175 call assert_equal(termwin, win_getid())
176
177 let job = term_getjob(buf)
178 call feedkeys("\<C-L>\<C-C>", 'tx')
179 call WaitForAssert({-> assert_equal("dead", job_status(job))})
180
181 set termwinkey&
182 tabnext
183 tabclose
184 tabprev
185 tabclose
186endfunc
187
188func Test_terminal_out_err()
189 CheckUnix
190
191 call writefile([
192 \ '#!/bin/sh',
193 \ 'echo "this is standard error" >&2',
194 \ 'echo "this is standard out" >&1',
195 \ ], 'Xechoerrout.sh')
196 call setfperm('Xechoerrout.sh', 'rwxrwx---')
197
198 let outfile = 'Xtermstdout'
199 let buf = term_start(['./Xechoerrout.sh'], {'out_io': 'file', 'out_name': outfile})
200
201 call WaitFor({-> !empty(readfile(outfile)) && !empty(term_getline(buf, 1))})
202 call assert_equal(['this is standard out'], readfile(outfile))
203 call assert_equal('this is standard error', term_getline(buf, 1))
204
205 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))})
206 exe buf . 'bwipe'
207 call delete('Xechoerrout.sh')
208 call delete(outfile)
209endfunc
210
211func Test_termwinscroll()
212 CheckUnix
Bram Moolenaarf65927f2020-07-11 14:04:28 +0200213 " TODO: Somehow this test sometimes hangs in the GUI
214 CheckNotGui
Bram Moolenaarf08b0eb2021-10-16 13:00:14 +0100215 let g:test_is_flaky = 1
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200216
217 " Let the terminal output more than 'termwinscroll' lines, some at the start
218 " will be dropped.
219 exe 'set termwinscroll=' . &lines
220 let buf = term_start('/bin/sh')
221 for i in range(1, &lines)
222 call feedkeys("echo " . i . "\<CR>", 'xt')
223 call WaitForAssert({-> assert_match(string(i), term_getline(buf, term_getcursor(buf)[0] - 1))})
224 endfor
225 " Go to Terminal-Normal mode to update the buffer.
226 call feedkeys("\<C-W>N", 'xt')
227 call assert_inrange(&lines, &lines * 110 / 100 + winheight(0), line('$'))
228
229 " Every "echo nr" must only appear once
230 let lines = getline(1, line('$'))
231 for i in range(&lines - len(lines) / 2 + 2, &lines)
232 let filtered = filter(copy(lines), {idx, val -> val =~ 'echo ' . i . '\>'})
233 call assert_equal(1, len(filtered), 'for "echo ' . i . '"')
234 endfor
235
236 exe buf . 'bwipe!'
237endfunc
238
239" Resizing the terminal window caused an ml_get error.
240" TODO: This does not reproduce the original problem.
241func Test_terminal_resize()
242 set statusline=x
243 terminal
244 call assert_equal(2, winnr('$'))
Bram Moolenaarc54f3472021-03-23 19:22:12 +0100245 let buf = bufnr()
246
247 " Wait for the shell to display a prompt
248 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200249
250 " Fill the terminal with text.
251 if has('win32')
252 call feedkeys("dir\<CR>", 'xt')
253 else
254 call feedkeys("ls\<CR>", 'xt')
255 endif
Bram Moolenaarc54f3472021-03-23 19:22:12 +0100256 " Wait for some output
257 call WaitForAssert({-> assert_notequal('', term_getline(buf, 3))})
258
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200259 " Go to Terminal-Normal mode for a moment.
260 call feedkeys("\<C-W>N", 'xt')
261 " Open a new window
262 call feedkeys("i\<C-W>n", 'xt')
263 call assert_equal(3, winnr('$'))
264 redraw
265
266 close
267 call assert_equal(2, winnr('$'))
268 call feedkeys("exit\<CR>", 'xt')
Bram Moolenaarc54f3472021-03-23 19:22:12 +0100269 call TermWait(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200270 set statusline&
271endfunc
272
273" must be nearly the last, we can't go back from GUI to terminal
274func Test_zz1_terminal_in_gui()
275 CheckCanRunGui
276
277 " Ignore the "failed to create input context" error.
278 call test_ignore_error('E285:')
279
280 gui -f
281
282 call assert_equal(1, winnr('$'))
283 let buf = Run_shell_in_terminal({'term_finish': 'close'})
284 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200285
286 " closing window wipes out the terminal buffer a with finished job
287 call WaitForAssert({-> assert_equal(1, winnr('$'))})
288 call assert_equal("", bufname(buf))
289
290 unlet g:job
291endfunc
292
Bram Moolenaar8e7d6222020-12-18 19:49:56 +0100293" TODO: re-enable when this no longer hangs on Travis
Bram Moolenaarc85156b2020-07-12 14:09:23 +0200294"func Test_zz2_terminal_guioptions_bang()
295" CheckGui
296" set guioptions+=!
297"
298" let filename = 'Xtestscript'
299" if has('win32')
300" let filename .= '.bat'
301" let prefix = ''
302" let contents = ['@echo off', 'exit %1']
303" else
304" let filename .= '.sh'
305" let prefix = './'
306" let contents = ['#!/bin/sh', 'exit $1']
307" endif
308" call writefile(contents, filename)
309" call setfperm(filename, 'rwxrwx---')
310"
311" " Check if v:shell_error is equal to the exit status.
312" let exitval = 0
313" execute printf(':!%s%s %d', prefix, filename, exitval)
314" call assert_equal(exitval, v:shell_error)
315"
316" let exitval = 9
317" execute printf(':!%s%s %d', prefix, filename, exitval)
318" call assert_equal(exitval, v:shell_error)
319"
320" set guioptions&
321" call delete(filename)
322"endfunc
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200323
324func Test_terminal_hidden()
325 CheckUnix
326
327 term ++hidden cat
328 let bnr = bufnr('$')
329 call assert_equal('terminal', getbufvar(bnr, '&buftype'))
330 exe 'sbuf ' . bnr
331 call assert_equal('terminal', &buftype)
332 call term_sendkeys(bnr, "asdf\<CR>")
333 call WaitForAssert({-> assert_match('asdf', term_getline(bnr, 2))})
334 call term_sendkeys(bnr, "\<C-D>")
335 call WaitForAssert({-> assert_equal('finished', bnr->term_getstatus())})
336 bwipe!
337endfunc
338
339func Test_terminal_switch_mode()
340 term
341 let bnr = bufnr('$')
342 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
Bram Moolenaarc85156b2020-07-12 14:09:23 +0200343 " In the GUI the first switch sometimes doesn't work. Switch twice to avoid
Bram Moolenaar8e7d6222020-12-18 19:49:56 +0100344 " flakiness.
Bram Moolenaarc85156b2020-07-12 14:09:23 +0200345 call feedkeys("\<C-W>N", 'xt')
346 call feedkeys("A", 'xt')
347 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200348 call feedkeys("\<C-W>N", 'xt')
349 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))})
350 call feedkeys("A", 'xt')
351 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
352 call feedkeys("\<C-\>\<C-N>", 'xt')
353 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))})
354 call feedkeys("I", 'xt')
355 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
356 call feedkeys("\<C-W>Nv", 'xt')
357 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))})
358 call feedkeys("I", 'xt')
359 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
360 call feedkeys("\<C-W>Nv", 'xt')
361 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))})
362 call feedkeys("A", 'xt')
363 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
364 bwipe!
365endfunc
366
367func Test_terminal_normal_mode()
368 CheckRunVimInTerminal
369
370 " Run Vim in a terminal and open a terminal window to run Vim in.
371 let lines =<< trim END
372 call setline(1, range(11111, 11122))
373 3
374 END
375 call writefile(lines, 'XtermNormal')
376 let buf = RunVimInTerminal('-S XtermNormal', {'rows': 8})
377 call TermWait(buf)
378
379 call term_sendkeys(buf, "\<C-W>N")
380 call term_sendkeys(buf, ":set number cursorline culopt=both\r")
381 call VerifyScreenDump(buf, 'Test_terminal_normal_1', {})
382
383 call term_sendkeys(buf, ":set culopt=number\r")
384 call VerifyScreenDump(buf, 'Test_terminal_normal_2', {})
385
386 call term_sendkeys(buf, ":set culopt=line\r")
387 call VerifyScreenDump(buf, 'Test_terminal_normal_3', {})
388
389 call assert_fails('call term_sendkeys(buf, [])', 'E730:')
390 call term_sendkeys(buf, "a:q!\<CR>:q\<CR>:q\<CR>")
391 call StopVimInTerminal(buf)
392 call delete('XtermNormal')
393endfunc
394
395func Test_terminal_hidden_and_close()
396 CheckUnix
397
398 call assert_equal(1, winnr('$'))
399 term ++hidden ++close ls
400 let bnr = bufnr('$')
401 call assert_equal('terminal', getbufvar(bnr, '&buftype'))
402 call WaitForAssert({-> assert_false(bufexists(bnr))})
403 call assert_equal(1, winnr('$'))
404endfunc
405
406func Test_terminal_does_not_truncate_last_newlines()
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200407 if has('conpty')
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200408 throw 'Skipped: fail on ConPTY'
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200409 endif
Bram Moolenaarf08b0eb2021-10-16 13:00:14 +0100410 let g:test_is_flaky = 1
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200411 let contents = [
412 \ [ 'One', '', 'X' ],
413 \ [ 'Two', '', '' ],
414 \ [ 'Three' ] + repeat([''], 30)
415 \ ]
416
417 for c in contents
Bram Moolenaarb18b4962022-09-02 21:55:50 +0100418 call writefile(c, 'Xdntfile')
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200419 if has('win32')
Bram Moolenaarb18b4962022-09-02 21:55:50 +0100420 term cmd /c type Xdntfile
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200421 else
Bram Moolenaarb18b4962022-09-02 21:55:50 +0100422 term cat Xdntfile
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200423 endif
424 let bnr = bufnr('$')
425 call assert_equal('terminal', getbufvar(bnr, '&buftype'))
426 call WaitForAssert({-> assert_equal('finished', term_getstatus(bnr))})
427 sleep 100m
428 call assert_equal(c, getline(1, line('$')))
429 quit
430 endfor
431
Bram Moolenaarb18b4962022-09-02 21:55:50 +0100432 call delete('Xdntfile')
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200433endfunc
434
Bram Moolenaarb936b792020-09-04 18:34:09 +0200435func GetDummyCmd()
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200436 if has('win32')
Bram Moolenaarb936b792020-09-04 18:34:09 +0200437 return 'cmd /c ""'
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200438 else
439 CheckExecutable false
Bram Moolenaarb936b792020-09-04 18:34:09 +0200440 return 'false'
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200441 endif
Bram Moolenaarb936b792020-09-04 18:34:09 +0200442endfunc
443
444func Test_terminal_no_job()
445 let cmd = GetDummyCmd()
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200446 let term = term_start(cmd, {'term_finish': 'close'})
447 call WaitForAssert({-> assert_equal(v:null, term_getjob(term)) })
448endfunc
449
450func Test_term_getcursor()
451 CheckUnix
452
453 let buf = Run_shell_in_terminal({})
454
455 " Wait for the shell to display a prompt.
456 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
457
458 " Hide the cursor.
459 call term_sendkeys(buf, "echo -e '\\033[?25l'\r")
460 call WaitForAssert({-> assert_equal(0, term_getcursor(buf)[2].visible)})
461
462 " Show the cursor.
463 call term_sendkeys(buf, "echo -e '\\033[?25h'\r")
464 call WaitForAssert({-> assert_equal(1, buf->term_getcursor()[2].visible)})
465
466 " Change color of cursor.
467 call WaitForAssert({-> assert_equal('', term_getcursor(buf)[2].color)})
468 call term_sendkeys(buf, "echo -e '\\033]12;blue\\007'\r")
469 call WaitForAssert({-> assert_equal('blue', term_getcursor(buf)[2].color)})
470 call term_sendkeys(buf, "echo -e '\\033]12;green\\007'\r")
471 call WaitForAssert({-> assert_equal('green', term_getcursor(buf)[2].color)})
472
473 " Make cursor a blinking block.
474 call term_sendkeys(buf, "echo -e '\\033[1 q'\r")
475 call WaitForAssert({-> assert_equal([1, 1],
476 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
477
478 " Make cursor a steady block.
479 call term_sendkeys(buf, "echo -e '\\033[2 q'\r")
480 call WaitForAssert({-> assert_equal([0, 1],
481 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
482
483 " Make cursor a blinking underline.
484 call term_sendkeys(buf, "echo -e '\\033[3 q'\r")
485 call WaitForAssert({-> assert_equal([1, 2],
486 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
487
488 " Make cursor a steady underline.
489 call term_sendkeys(buf, "echo -e '\\033[4 q'\r")
490 call WaitForAssert({-> assert_equal([0, 2],
491 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
492
493 " Make cursor a blinking vertical bar.
494 call term_sendkeys(buf, "echo -e '\\033[5 q'\r")
495 call WaitForAssert({-> assert_equal([1, 3],
496 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
497
498 " Make cursor a steady vertical bar.
499 call term_sendkeys(buf, "echo -e '\\033[6 q'\r")
500 call WaitForAssert({-> assert_equal([0, 3],
501 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
502
503 call StopShellInTerminal(buf)
504endfunc
505
506" Test for term_gettitle()
507func Test_term_gettitle()
508 " term_gettitle() returns an empty string for a non-terminal buffer
509 " and for a non-existing buffer.
510 call assert_equal('', bufnr('%')->term_gettitle())
511 call assert_equal('', term_gettitle(bufnr('$') + 1))
512
513 if !has('title') || empty(&t_ts)
514 throw "Skipped: can't get/set title"
515 endif
516
517 let term = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', '-c', 'set title'])
Bram Moolenaar3bb79dc2021-12-12 18:50:19 +0000518 " When Vim is running as a server then the title ends in VIM{number}, thus
519 " optionally match a number after "VIM".
520 call WaitForAssert({-> assert_match('^\[No Name\] - VIM\d*$', term_gettitle(term)) })
521 call term_sendkeys(term, ":e Xfoo\r")
522 call WaitForAssert({-> assert_match('^Xfoo (.*[/\\]testdir) - VIM\d*$', term_gettitle(term)) })
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200523
524 call term_sendkeys(term, ":set titlestring=foo\r")
525 call WaitForAssert({-> assert_equal('foo', term_gettitle(term)) })
526
527 exe term . 'bwipe!'
528endfunc
529
530func Test_term_gettty()
531 let buf = Run_shell_in_terminal({})
532 let gettty = term_gettty(buf)
533
534 if has('unix') && executable('tty')
535 " Find tty using the tty shell command.
536 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
537 call term_sendkeys(buf, "tty\r")
538 call WaitForAssert({-> assert_notequal('', term_getline(buf, 3))})
539 let tty = term_getline(buf, 2)
540 call assert_equal(tty, gettty)
541 endif
542
543 let gettty0 = term_gettty(buf, 0)
544 let gettty1 = term_gettty(buf, 1)
545
546 call assert_equal(gettty, gettty0)
547 call assert_equal(job_info(g:job).tty_out, gettty0)
548 call assert_equal(job_info(g:job).tty_in, gettty1)
549
550 if has('unix')
551 " For unix, term_gettty(..., 0) and term_gettty(..., 1)
552 " are identical according to :help term_gettty()
553 call assert_equal(gettty0, gettty1)
554 call assert_match('^/dev/', gettty)
555 else
556 " ConPTY works on anonymous pipe.
557 if !has('conpty')
558 call assert_match('^\\\\.\\pipe\\', gettty0)
559 call assert_match('^\\\\.\\pipe\\', gettty1)
560 endif
561 endif
562
Bram Moolenaarbade44e2020-09-26 22:39:24 +0200563 call assert_fails('call term_gettty(buf, 2)', 'E475:')
564 call assert_fails('call term_gettty(buf, -1)', 'E475:')
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200565
566 call assert_equal('', term_gettty(buf + 1))
567
568 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200569 exe buf . 'bwipe'
570endfunc
571
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200572
573" vim: shiftwidth=2 sts=2 expandtab