blob: c6acb99bc359df26776a7daf914f40f46cd5fdc2 [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
Bram Moolenaarc4860bd2022-10-15 20:52:26 +010022 call writefile(text, 'Xwinsize', 'D')
Bram Moolenaar1112c0f2020-07-01 21:53:50 +020023 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)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +020037
Bram Moolenaare2e40752020-09-04 21:18:46 +020038 call assert_fails('set termwinsize=40', 'E474:')
39 call assert_fails('set termwinsize=10+40', 'E474:')
40 call assert_fails('set termwinsize=abc', 'E474:')
Bram Moolenaar1112c0f2020-07-01 21:53:50 +020041
42 set termwinsize=
43endfunc
44
45func Test_terminal_termwinsize_option_zero()
46 set termwinsize=0x0
47 let buf = Run_shell_in_terminal({})
48 let win = bufwinid(buf)
49 call assert_equal([winheight(win), winwidth(win)], term_getsize(buf))
50 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +020051 exe buf . 'bwipe'
52
53 set termwinsize=7x0
54 let buf = Run_shell_in_terminal({})
55 let win = bufwinid(buf)
56 call assert_equal([7, winwidth(win)], term_getsize(buf))
57 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +020058 exe buf . 'bwipe'
59
60 set termwinsize=0x33
61 let buf = Run_shell_in_terminal({})
62 let win = bufwinid(buf)
63 call assert_equal([winheight(win), 33], term_getsize(buf))
64 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +020065 exe buf . 'bwipe'
66
67 set termwinsize=
68endfunc
69
70func Test_terminal_termwinsize_minimum()
71 set termwinsize=10*50
72 vsplit
73 let buf = Run_shell_in_terminal({})
74 let win = bufwinid(buf)
75 call assert_inrange(10, 1000, winheight(win))
76 call assert_inrange(50, 1000, winwidth(win))
77 call assert_equal([winheight(win), winwidth(win)], term_getsize(buf))
78
79 resize 15
80 vertical resize 60
81 redraw
82 call assert_equal([15, 60], term_getsize(buf))
83 call assert_equal(15, winheight(win))
84 call assert_equal(60, winwidth(win))
85
86 resize 7
87 vertical resize 30
88 redraw
89 call assert_equal([10, 50], term_getsize(buf))
90 call assert_equal(7, winheight(win))
91 call assert_equal(30, winwidth(win))
92
93 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +020094 exe buf . 'bwipe'
95
96 set termwinsize=0*0
97 let buf = Run_shell_in_terminal({})
98 let win = bufwinid(buf)
99 call assert_equal([winheight(win), winwidth(win)], term_getsize(buf))
100 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200101 exe buf . 'bwipe'
102
103 set termwinsize=
104endfunc
105
Bram Moolenaarb936b792020-09-04 18:34:09 +0200106func Test_terminal_termwinsize_overruled()
107 let cmd = GetDummyCmd()
108 set termwinsize=5x43
109 let buf = term_start(cmd, #{term_rows: 7, term_cols: 50})
110 call TermWait(buf)
111 call assert_equal([7, 50], term_getsize(buf))
112 exe "bwipe! " .. buf
113
114 let buf = term_start(cmd, #{term_cols: 50})
115 call TermWait(buf)
116 call assert_equal([5, 50], term_getsize(buf))
117 exe "bwipe! " .. buf
118
119 let buf = term_start(cmd, #{term_rows: 7})
120 call TermWait(buf)
121 call assert_equal([7, 43], term_getsize(buf))
122 exe "bwipe! " .. buf
123
124 set termwinsize=
125endfunc
126
Bram Moolenaar2ce14582020-09-05 16:08:49 +0200127" hidden terminal must not change current window size
128func Test_terminal_hidden_winsize()
129 let cmd = GetDummyCmd()
130 let rows = winheight(0)
131 let buf = term_start(cmd, #{hidden: 1, term_rows: 10})
132 call assert_equal(rows, winheight(0))
133 call assert_equal([10, &columns], term_getsize(buf))
134 exe "bwipe! " .. buf
135endfunc
136
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200137func Test_terminal_termwinkey()
138 " make three tabpages, terminal in the middle
139 0tabnew
140 tabnext
141 tabnew
142 tabprev
143 call assert_equal(1, winnr('$'))
144 call assert_equal(2, tabpagenr())
145 let thiswin = win_getid()
146
147 let buf = Run_shell_in_terminal({})
148 let termwin = bufwinid(buf)
149 set termwinkey=<C-L>
150 call feedkeys("\<C-L>w", 'tx')
151 call assert_equal(thiswin, win_getid())
152 call feedkeys("\<C-W>w", 'tx')
153 call assert_equal(termwin, win_getid())
154
155 if has('langmap')
156 set langmap=xjyk
157 call feedkeys("\<C-L>x", 'tx')
158 call assert_equal(thiswin, win_getid())
159 call feedkeys("\<C-W>y", 'tx')
160 call assert_equal(termwin, win_getid())
161 set langmap=
162 endif
163
164 call feedkeys("\<C-L>gt", "xt")
165 call assert_equal(3, tabpagenr())
166 tabprev
167 call assert_equal(2, tabpagenr())
168 call assert_equal(termwin, win_getid())
169
170 call feedkeys("\<C-L>gT", "xt")
171 call assert_equal(1, tabpagenr())
172 tabnext
173 call assert_equal(2, tabpagenr())
174 call assert_equal(termwin, win_getid())
175
176 let job = term_getjob(buf)
177 call feedkeys("\<C-L>\<C-C>", 'tx')
178 call WaitForAssert({-> assert_equal("dead", job_status(job))})
179
180 set termwinkey&
181 tabnext
182 tabclose
183 tabprev
184 tabclose
185endfunc
186
187func Test_terminal_out_err()
188 CheckUnix
189
190 call writefile([
191 \ '#!/bin/sh',
192 \ 'echo "this is standard error" >&2',
193 \ 'echo "this is standard out" >&1',
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100194 \ ], 'Xechoerrout.sh', 'D')
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200195 call setfperm('Xechoerrout.sh', 'rwxrwx---')
196
197 let outfile = 'Xtermstdout'
198 let buf = term_start(['./Xechoerrout.sh'], {'out_io': 'file', 'out_name': outfile})
199
200 call WaitFor({-> !empty(readfile(outfile)) && !empty(term_getline(buf, 1))})
201 call assert_equal(['this is standard out'], readfile(outfile))
202 call assert_equal('this is standard error', term_getline(buf, 1))
203
204 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))})
205 exe buf . 'bwipe'
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200206 call delete(outfile)
207endfunc
208
209func Test_termwinscroll()
210 CheckUnix
Bram Moolenaarf65927f2020-07-11 14:04:28 +0200211 " TODO: Somehow this test sometimes hangs in the GUI
212 CheckNotGui
Bram Moolenaarf08b0eb2021-10-16 13:00:14 +0100213 let g:test_is_flaky = 1
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200214
215 " Let the terminal output more than 'termwinscroll' lines, some at the start
216 " will be dropped.
217 exe 'set termwinscroll=' . &lines
218 let buf = term_start('/bin/sh')
219 for i in range(1, &lines)
220 call feedkeys("echo " . i . "\<CR>", 'xt')
221 call WaitForAssert({-> assert_match(string(i), term_getline(buf, term_getcursor(buf)[0] - 1))})
222 endfor
223 " Go to Terminal-Normal mode to update the buffer.
224 call feedkeys("\<C-W>N", 'xt')
225 call assert_inrange(&lines, &lines * 110 / 100 + winheight(0), line('$'))
226
227 " Every "echo nr" must only appear once
228 let lines = getline(1, line('$'))
229 for i in range(&lines - len(lines) / 2 + 2, &lines)
230 let filtered = filter(copy(lines), {idx, val -> val =~ 'echo ' . i . '\>'})
231 call assert_equal(1, len(filtered), 'for "echo ' . i . '"')
232 endfor
233
234 exe buf . 'bwipe!'
235endfunc
236
237" Resizing the terminal window caused an ml_get error.
238" TODO: This does not reproduce the original problem.
239func Test_terminal_resize()
240 set statusline=x
241 terminal
242 call assert_equal(2, winnr('$'))
Bram Moolenaarc54f3472021-03-23 19:22:12 +0100243 let buf = bufnr()
244
245 " Wait for the shell to display a prompt
246 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200247
248 " Fill the terminal with text.
249 if has('win32')
250 call feedkeys("dir\<CR>", 'xt')
251 else
252 call feedkeys("ls\<CR>", 'xt')
253 endif
Bram Moolenaarc54f3472021-03-23 19:22:12 +0100254 " Wait for some output
255 call WaitForAssert({-> assert_notequal('', term_getline(buf, 3))})
256
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200257 " Go to Terminal-Normal mode for a moment.
258 call feedkeys("\<C-W>N", 'xt')
259 " Open a new window
260 call feedkeys("i\<C-W>n", 'xt')
261 call assert_equal(3, winnr('$'))
262 redraw
263
264 close
265 call assert_equal(2, winnr('$'))
266 call feedkeys("exit\<CR>", 'xt')
Bram Moolenaarc54f3472021-03-23 19:22:12 +0100267 call TermWait(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200268 set statusline&
269endfunc
270
271" must be nearly the last, we can't go back from GUI to terminal
272func Test_zz1_terminal_in_gui()
273 CheckCanRunGui
274
275 " Ignore the "failed to create input context" error.
276 call test_ignore_error('E285:')
277
278 gui -f
279
280 call assert_equal(1, winnr('$'))
281 let buf = Run_shell_in_terminal({'term_finish': 'close'})
282 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200283
284 " closing window wipes out the terminal buffer a with finished job
285 call WaitForAssert({-> assert_equal(1, winnr('$'))})
286 call assert_equal("", bufname(buf))
287
288 unlet g:job
289endfunc
290
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100291func Test_zz2_terminal_guioptions_bang()
292 CheckGui
293 set guioptions+=!
294
295 let filename = 'Xtestscript'
296 if has('win32')
297 let filename .= '.bat'
298 let prefix = ''
299 let contents = ['@echo off', 'exit %1']
300 else
301 let filename .= '.sh'
302 let prefix = './'
303 let contents = ['#!/bin/sh', 'exit $1']
304 endif
305 call writefile(contents, filename, 'D')
306 call setfperm(filename, 'rwxrwx---')
307
308 " Check if v:shell_error is equal to the exit status.
309 let exitval = 0
310 execute printf(':!%s%s %d', prefix, filename, exitval)
311 call assert_equal(exitval, v:shell_error)
312
313 let exitval = 9
314 execute printf(':!%s%s %d', prefix, filename, exitval)
315 call assert_equal(exitval, v:shell_error)
316
317 set guioptions&
318endfunc
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200319
320func Test_terminal_hidden()
321 CheckUnix
322
323 term ++hidden cat
324 let bnr = bufnr('$')
325 call assert_equal('terminal', getbufvar(bnr, '&buftype'))
326 exe 'sbuf ' . bnr
327 call assert_equal('terminal', &buftype)
328 call term_sendkeys(bnr, "asdf\<CR>")
329 call WaitForAssert({-> assert_match('asdf', term_getline(bnr, 2))})
330 call term_sendkeys(bnr, "\<C-D>")
331 call WaitForAssert({-> assert_equal('finished', bnr->term_getstatus())})
332 bwipe!
333endfunc
334
335func Test_terminal_switch_mode()
336 term
337 let bnr = bufnr('$')
338 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
Bram Moolenaarc85156b2020-07-12 14:09:23 +0200339 " In the GUI the first switch sometimes doesn't work. Switch twice to avoid
Bram Moolenaar8e7d6222020-12-18 19:49:56 +0100340 " flakiness.
Bram Moolenaarc85156b2020-07-12 14:09:23 +0200341 call feedkeys("\<C-W>N", 'xt')
342 call feedkeys("A", 'xt')
343 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200344 call feedkeys("\<C-W>N", 'xt')
345 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))})
346 call feedkeys("A", 'xt')
347 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
348 call feedkeys("\<C-\>\<C-N>", 'xt')
349 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))})
350 call feedkeys("I", 'xt')
351 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
352 call feedkeys("\<C-W>Nv", '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("A", 'xt')
359 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
360 bwipe!
361endfunc
362
363func Test_terminal_normal_mode()
364 CheckRunVimInTerminal
365
366 " Run Vim in a terminal and open a terminal window to run Vim in.
367 let lines =<< trim END
368 call setline(1, range(11111, 11122))
369 3
370 END
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100371 call writefile(lines, 'XtermNormal', 'D')
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200372 let buf = RunVimInTerminal('-S XtermNormal', {'rows': 8})
373 call TermWait(buf)
374
375 call term_sendkeys(buf, "\<C-W>N")
376 call term_sendkeys(buf, ":set number cursorline culopt=both\r")
377 call VerifyScreenDump(buf, 'Test_terminal_normal_1', {})
378
379 call term_sendkeys(buf, ":set culopt=number\r")
380 call VerifyScreenDump(buf, 'Test_terminal_normal_2', {})
381
382 call term_sendkeys(buf, ":set culopt=line\r")
383 call VerifyScreenDump(buf, 'Test_terminal_normal_3', {})
384
385 call assert_fails('call term_sendkeys(buf, [])', 'E730:')
386 call term_sendkeys(buf, "a:q!\<CR>:q\<CR>:q\<CR>")
387 call StopVimInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200388endfunc
389
390func Test_terminal_hidden_and_close()
391 CheckUnix
392
393 call assert_equal(1, winnr('$'))
394 term ++hidden ++close ls
395 let bnr = bufnr('$')
396 call assert_equal('terminal', getbufvar(bnr, '&buftype'))
397 call WaitForAssert({-> assert_false(bufexists(bnr))})
398 call assert_equal(1, winnr('$'))
399endfunc
400
401func Test_terminal_does_not_truncate_last_newlines()
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200402 if has('conpty')
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200403 throw 'Skipped: fail on ConPTY'
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200404 endif
Bram Moolenaarf08b0eb2021-10-16 13:00:14 +0100405 let g:test_is_flaky = 1
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200406 let contents = [
407 \ [ 'One', '', 'X' ],
408 \ [ 'Two', '', '' ],
409 \ [ 'Three' ] + repeat([''], 30)
410 \ ]
411
412 for c in contents
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100413 call writefile(c, 'Xdntfile', 'D')
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200414 if has('win32')
Bram Moolenaarb18b4962022-09-02 21:55:50 +0100415 term cmd /c type Xdntfile
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200416 else
Bram Moolenaarb18b4962022-09-02 21:55:50 +0100417 term cat Xdntfile
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200418 endif
419 let bnr = bufnr('$')
420 call assert_equal('terminal', getbufvar(bnr, '&buftype'))
421 call WaitForAssert({-> assert_equal('finished', term_getstatus(bnr))})
422 sleep 100m
423 call assert_equal(c, getline(1, line('$')))
424 quit
425 endfor
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200426endfunc
427
Bram Moolenaarb936b792020-09-04 18:34:09 +0200428func GetDummyCmd()
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200429 if has('win32')
Bram Moolenaarb936b792020-09-04 18:34:09 +0200430 return 'cmd /c ""'
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200431 else
432 CheckExecutable false
Bram Moolenaarb936b792020-09-04 18:34:09 +0200433 return 'false'
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200434 endif
Bram Moolenaarb936b792020-09-04 18:34:09 +0200435endfunc
436
437func Test_terminal_no_job()
438 let cmd = GetDummyCmd()
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200439 let term = term_start(cmd, {'term_finish': 'close'})
440 call WaitForAssert({-> assert_equal(v:null, term_getjob(term)) })
441endfunc
442
443func Test_term_getcursor()
444 CheckUnix
445
446 let buf = Run_shell_in_terminal({})
447
448 " Wait for the shell to display a prompt.
449 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
450
451 " Hide the cursor.
452 call term_sendkeys(buf, "echo -e '\\033[?25l'\r")
453 call WaitForAssert({-> assert_equal(0, term_getcursor(buf)[2].visible)})
454
455 " Show the cursor.
456 call term_sendkeys(buf, "echo -e '\\033[?25h'\r")
457 call WaitForAssert({-> assert_equal(1, buf->term_getcursor()[2].visible)})
458
459 " Change color of cursor.
460 call WaitForAssert({-> assert_equal('', term_getcursor(buf)[2].color)})
461 call term_sendkeys(buf, "echo -e '\\033]12;blue\\007'\r")
462 call WaitForAssert({-> assert_equal('blue', term_getcursor(buf)[2].color)})
463 call term_sendkeys(buf, "echo -e '\\033]12;green\\007'\r")
464 call WaitForAssert({-> assert_equal('green', term_getcursor(buf)[2].color)})
465
466 " Make cursor a blinking block.
467 call term_sendkeys(buf, "echo -e '\\033[1 q'\r")
468 call WaitForAssert({-> assert_equal([1, 1],
469 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
470
471 " Make cursor a steady block.
472 call term_sendkeys(buf, "echo -e '\\033[2 q'\r")
473 call WaitForAssert({-> assert_equal([0, 1],
474 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
475
476 " Make cursor a blinking underline.
477 call term_sendkeys(buf, "echo -e '\\033[3 q'\r")
478 call WaitForAssert({-> assert_equal([1, 2],
479 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
480
481 " Make cursor a steady underline.
482 call term_sendkeys(buf, "echo -e '\\033[4 q'\r")
483 call WaitForAssert({-> assert_equal([0, 2],
484 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
485
486 " Make cursor a blinking vertical bar.
487 call term_sendkeys(buf, "echo -e '\\033[5 q'\r")
488 call WaitForAssert({-> assert_equal([1, 3],
489 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
490
491 " Make cursor a steady vertical bar.
492 call term_sendkeys(buf, "echo -e '\\033[6 q'\r")
493 call WaitForAssert({-> assert_equal([0, 3],
494 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
495
496 call StopShellInTerminal(buf)
497endfunc
498
499" Test for term_gettitle()
500func Test_term_gettitle()
501 " term_gettitle() returns an empty string for a non-terminal buffer
502 " and for a non-existing buffer.
503 call assert_equal('', bufnr('%')->term_gettitle())
504 call assert_equal('', term_gettitle(bufnr('$') + 1))
505
506 if !has('title') || empty(&t_ts)
507 throw "Skipped: can't get/set title"
508 endif
509
510 let term = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', '-c', 'set title'])
Bram Moolenaar3bb79dc2021-12-12 18:50:19 +0000511 " When Vim is running as a server then the title ends in VIM{number}, thus
512 " optionally match a number after "VIM".
513 call WaitForAssert({-> assert_match('^\[No Name\] - VIM\d*$', term_gettitle(term)) })
514 call term_sendkeys(term, ":e Xfoo\r")
515 call WaitForAssert({-> assert_match('^Xfoo (.*[/\\]testdir) - VIM\d*$', term_gettitle(term)) })
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200516
517 call term_sendkeys(term, ":set titlestring=foo\r")
518 call WaitForAssert({-> assert_equal('foo', term_gettitle(term)) })
519
520 exe term . 'bwipe!'
521endfunc
522
523func Test_term_gettty()
524 let buf = Run_shell_in_terminal({})
525 let gettty = term_gettty(buf)
526
527 if has('unix') && executable('tty')
528 " Find tty using the tty shell command.
529 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
530 call term_sendkeys(buf, "tty\r")
531 call WaitForAssert({-> assert_notequal('', term_getline(buf, 3))})
532 let tty = term_getline(buf, 2)
533 call assert_equal(tty, gettty)
534 endif
535
536 let gettty0 = term_gettty(buf, 0)
537 let gettty1 = term_gettty(buf, 1)
538
539 call assert_equal(gettty, gettty0)
540 call assert_equal(job_info(g:job).tty_out, gettty0)
541 call assert_equal(job_info(g:job).tty_in, gettty1)
542
543 if has('unix')
544 " For unix, term_gettty(..., 0) and term_gettty(..., 1)
545 " are identical according to :help term_gettty()
546 call assert_equal(gettty0, gettty1)
547 call assert_match('^/dev/', gettty)
548 else
549 " ConPTY works on anonymous pipe.
550 if !has('conpty')
551 call assert_match('^\\\\.\\pipe\\', gettty0)
552 call assert_match('^\\\\.\\pipe\\', gettty1)
553 endif
554 endif
555
Bram Moolenaarbade44e2020-09-26 22:39:24 +0200556 call assert_fails('call term_gettty(buf, 2)', 'E475:')
557 call assert_fails('call term_gettty(buf, -1)', 'E475:')
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200558
559 call assert_equal('', term_gettty(buf + 1))
560
561 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200562 exe buf . 'bwipe'
563endfunc
564
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200565
566" vim: shiftwidth=2 sts=2 expandtab