blob: 8615bf55ad48ff23c0b35898a96601537f95b106 [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})
Yegappan Lakshmanane446a012023-01-19 17:49:58 +0000132 call TermWait(buf)
Bram Moolenaar2ce14582020-09-05 16:08:49 +0200133 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',
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100195 \ ], 'Xechoerrout.sh', 'D')
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200196 call setfperm('Xechoerrout.sh', 'rwxrwx---')
197
198 let outfile = 'Xtermstdout'
199 let buf = term_start(['./Xechoerrout.sh'], {'out_io': 'file', 'out_name': outfile})
Yegappan Lakshmanane446a012023-01-19 17:49:58 +0000200 call TermWait(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200201
202 call WaitFor({-> !empty(readfile(outfile)) && !empty(term_getline(buf, 1))})
203 call assert_equal(['this is standard out'], readfile(outfile))
204 call assert_equal('this is standard error', term_getline(buf, 1))
205
206 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))})
207 exe buf . 'bwipe'
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200208 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')
Yegappan Lakshmanane446a012023-01-19 17:49:58 +0000221 call TermWait(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200222 for i in range(1, &lines)
223 call feedkeys("echo " . i . "\<CR>", 'xt')
224 call WaitForAssert({-> assert_match(string(i), term_getline(buf, term_getcursor(buf)[0] - 1))})
225 endfor
226 " Go to Terminal-Normal mode to update the buffer.
227 call feedkeys("\<C-W>N", 'xt')
228 call assert_inrange(&lines, &lines * 110 / 100 + winheight(0), line('$'))
229
230 " Every "echo nr" must only appear once
231 let lines = getline(1, line('$'))
232 for i in range(&lines - len(lines) / 2 + 2, &lines)
233 let filtered = filter(copy(lines), {idx, val -> val =~ 'echo ' . i . '\>'})
234 call assert_equal(1, len(filtered), 'for "echo ' . i . '"')
235 endfor
236
237 exe buf . 'bwipe!'
238endfunc
239
240" Resizing the terminal window caused an ml_get error.
241" TODO: This does not reproduce the original problem.
242func Test_terminal_resize()
243 set statusline=x
244 terminal
245 call assert_equal(2, winnr('$'))
Bram Moolenaarc54f3472021-03-23 19:22:12 +0100246 let buf = bufnr()
247
248 " Wait for the shell to display a prompt
249 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200250
251 " Fill the terminal with text.
252 if has('win32')
253 call feedkeys("dir\<CR>", 'xt')
254 else
255 call feedkeys("ls\<CR>", 'xt')
256 endif
Bram Moolenaarc54f3472021-03-23 19:22:12 +0100257 " Wait for some output
258 call WaitForAssert({-> assert_notequal('', term_getline(buf, 3))})
259
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200260 " Go to Terminal-Normal mode for a moment.
261 call feedkeys("\<C-W>N", 'xt')
262 " Open a new window
263 call feedkeys("i\<C-W>n", 'xt')
264 call assert_equal(3, winnr('$'))
265 redraw
266
267 close
268 call assert_equal(2, winnr('$'))
269 call feedkeys("exit\<CR>", 'xt')
Bram Moolenaarc54f3472021-03-23 19:22:12 +0100270 call TermWait(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200271 set statusline&
272endfunc
273
274" must be nearly the last, we can't go back from GUI to terminal
275func Test_zz1_terminal_in_gui()
276 CheckCanRunGui
277
278 " Ignore the "failed to create input context" error.
279 call test_ignore_error('E285:')
280
281 gui -f
282
283 call assert_equal(1, winnr('$'))
284 let buf = Run_shell_in_terminal({'term_finish': 'close'})
285 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200286
287 " closing window wipes out the terminal buffer a with finished job
288 call WaitForAssert({-> assert_equal(1, winnr('$'))})
289 call assert_equal("", bufname(buf))
290
291 unlet g:job
292endfunc
293
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100294func 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, 'D')
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&
321endfunc
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200322
323func Test_terminal_hidden()
324 CheckUnix
325
326 term ++hidden cat
327 let bnr = bufnr('$')
328 call assert_equal('terminal', getbufvar(bnr, '&buftype'))
329 exe 'sbuf ' . bnr
330 call assert_equal('terminal', &buftype)
331 call term_sendkeys(bnr, "asdf\<CR>")
332 call WaitForAssert({-> assert_match('asdf', term_getline(bnr, 2))})
333 call term_sendkeys(bnr, "\<C-D>")
334 call WaitForAssert({-> assert_equal('finished', bnr->term_getstatus())})
335 bwipe!
336endfunc
337
338func Test_terminal_switch_mode()
339 term
340 let bnr = bufnr('$')
341 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
Bram Moolenaarc85156b2020-07-12 14:09:23 +0200342 " In the GUI the first switch sometimes doesn't work. Switch twice to avoid
Bram Moolenaar8e7d6222020-12-18 19:49:56 +0100343 " flakiness.
Bram Moolenaarc85156b2020-07-12 14:09:23 +0200344 call feedkeys("\<C-W>N", 'xt')
345 call feedkeys("A", 'xt')
346 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200347 call feedkeys("\<C-W>N", 'xt')
348 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))})
349 call feedkeys("A", 'xt')
350 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
351 call feedkeys("\<C-\>\<C-N>", 'xt')
352 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))})
353 call feedkeys("I", 'xt')
354 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
355 call feedkeys("\<C-W>Nv", 'xt')
356 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))})
357 call feedkeys("I", 'xt')
358 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
359 call feedkeys("\<C-W>Nv", 'xt')
360 call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))})
361 call feedkeys("A", 'xt')
362 call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
363 bwipe!
364endfunc
365
366func Test_terminal_normal_mode()
367 CheckRunVimInTerminal
368
369 " Run Vim in a terminal and open a terminal window to run Vim in.
370 let lines =<< trim END
371 call setline(1, range(11111, 11122))
372 3
373 END
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100374 call writefile(lines, 'XtermNormal', 'D')
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200375 let buf = RunVimInTerminal('-S XtermNormal', {'rows': 8})
376 call TermWait(buf)
377
378 call term_sendkeys(buf, "\<C-W>N")
379 call term_sendkeys(buf, ":set number cursorline culopt=both\r")
380 call VerifyScreenDump(buf, 'Test_terminal_normal_1', {})
381
382 call term_sendkeys(buf, ":set culopt=number\r")
383 call VerifyScreenDump(buf, 'Test_terminal_normal_2', {})
384
385 call term_sendkeys(buf, ":set culopt=line\r")
386 call VerifyScreenDump(buf, 'Test_terminal_normal_3', {})
387
388 call assert_fails('call term_sendkeys(buf, [])', 'E730:')
389 call term_sendkeys(buf, "a:q!\<CR>:q\<CR>:q\<CR>")
390 call StopVimInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200391endfunc
392
393func Test_terminal_hidden_and_close()
394 CheckUnix
395
396 call assert_equal(1, winnr('$'))
397 term ++hidden ++close ls
398 let bnr = bufnr('$')
399 call assert_equal('terminal', getbufvar(bnr, '&buftype'))
400 call WaitForAssert({-> assert_false(bufexists(bnr))})
401 call assert_equal(1, winnr('$'))
402endfunc
403
404func Test_terminal_does_not_truncate_last_newlines()
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200405 if has('conpty')
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200406 throw 'Skipped: fail on ConPTY'
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200407 endif
Bram Moolenaarf08b0eb2021-10-16 13:00:14 +0100408 let g:test_is_flaky = 1
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200409 let contents = [
410 \ [ 'One', '', 'X' ],
411 \ [ 'Two', '', '' ],
412 \ [ 'Three' ] + repeat([''], 30)
413 \ ]
414
415 for c in contents
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100416 call writefile(c, 'Xdntfile', 'D')
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200417 if has('win32')
Bram Moolenaarb18b4962022-09-02 21:55:50 +0100418 term cmd /c type Xdntfile
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200419 else
Bram Moolenaarb18b4962022-09-02 21:55:50 +0100420 term cat Xdntfile
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200421 endif
422 let bnr = bufnr('$')
423 call assert_equal('terminal', getbufvar(bnr, '&buftype'))
424 call WaitForAssert({-> assert_equal('finished', term_getstatus(bnr))})
425 sleep 100m
426 call assert_equal(c, getline(1, line('$')))
427 quit
428 endfor
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200429endfunc
430
Bram Moolenaarb936b792020-09-04 18:34:09 +0200431func GetDummyCmd()
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200432 if has('win32')
Bram Moolenaarb936b792020-09-04 18:34:09 +0200433 return 'cmd /c ""'
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200434 else
435 CheckExecutable false
Bram Moolenaarb936b792020-09-04 18:34:09 +0200436 return 'false'
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200437 endif
Bram Moolenaarb936b792020-09-04 18:34:09 +0200438endfunc
439
440func Test_terminal_no_job()
441 let cmd = GetDummyCmd()
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200442 let term = term_start(cmd, {'term_finish': 'close'})
443 call WaitForAssert({-> assert_equal(v:null, term_getjob(term)) })
444endfunc
445
446func Test_term_getcursor()
447 CheckUnix
448
449 let buf = Run_shell_in_terminal({})
450
451 " Wait for the shell to display a prompt.
452 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
453
454 " Hide the cursor.
455 call term_sendkeys(buf, "echo -e '\\033[?25l'\r")
456 call WaitForAssert({-> assert_equal(0, term_getcursor(buf)[2].visible)})
457
458 " Show the cursor.
459 call term_sendkeys(buf, "echo -e '\\033[?25h'\r")
460 call WaitForAssert({-> assert_equal(1, buf->term_getcursor()[2].visible)})
461
462 " Change color of cursor.
463 call WaitForAssert({-> assert_equal('', term_getcursor(buf)[2].color)})
464 call term_sendkeys(buf, "echo -e '\\033]12;blue\\007'\r")
465 call WaitForAssert({-> assert_equal('blue', term_getcursor(buf)[2].color)})
466 call term_sendkeys(buf, "echo -e '\\033]12;green\\007'\r")
467 call WaitForAssert({-> assert_equal('green', term_getcursor(buf)[2].color)})
468
469 " Make cursor a blinking block.
470 call term_sendkeys(buf, "echo -e '\\033[1 q'\r")
471 call WaitForAssert({-> assert_equal([1, 1],
472 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
473
474 " Make cursor a steady block.
475 call term_sendkeys(buf, "echo -e '\\033[2 q'\r")
476 call WaitForAssert({-> assert_equal([0, 1],
477 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
478
479 " Make cursor a blinking underline.
480 call term_sendkeys(buf, "echo -e '\\033[3 q'\r")
481 call WaitForAssert({-> assert_equal([1, 2],
482 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
483
484 " Make cursor a steady underline.
485 call term_sendkeys(buf, "echo -e '\\033[4 q'\r")
486 call WaitForAssert({-> assert_equal([0, 2],
487 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
488
489 " Make cursor a blinking vertical bar.
490 call term_sendkeys(buf, "echo -e '\\033[5 q'\r")
491 call WaitForAssert({-> assert_equal([1, 3],
492 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
493
494 " Make cursor a steady vertical bar.
495 call term_sendkeys(buf, "echo -e '\\033[6 q'\r")
496 call WaitForAssert({-> assert_equal([0, 3],
497 \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])})
498
499 call StopShellInTerminal(buf)
500endfunc
501
502" Test for term_gettitle()
503func Test_term_gettitle()
504 " term_gettitle() returns an empty string for a non-terminal buffer
505 " and for a non-existing buffer.
506 call assert_equal('', bufnr('%')->term_gettitle())
507 call assert_equal('', term_gettitle(bufnr('$') + 1))
508
509 if !has('title') || empty(&t_ts)
510 throw "Skipped: can't get/set title"
511 endif
512
513 let term = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', '-c', 'set title'])
Yegappan Lakshmanane446a012023-01-19 17:49:58 +0000514 call TermWait(term)
Bram Moolenaar3bb79dc2021-12-12 18:50:19 +0000515 " When Vim is running as a server then the title ends in VIM{number}, thus
516 " optionally match a number after "VIM".
517 call WaitForAssert({-> assert_match('^\[No Name\] - VIM\d*$', term_gettitle(term)) })
518 call term_sendkeys(term, ":e Xfoo\r")
519 call WaitForAssert({-> assert_match('^Xfoo (.*[/\\]testdir) - VIM\d*$', term_gettitle(term)) })
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200520
521 call term_sendkeys(term, ":set titlestring=foo\r")
522 call WaitForAssert({-> assert_equal('foo', term_gettitle(term)) })
523
524 exe term . 'bwipe!'
525endfunc
526
527func Test_term_gettty()
528 let buf = Run_shell_in_terminal({})
529 let gettty = term_gettty(buf)
530
531 if has('unix') && executable('tty')
532 " Find tty using the tty shell command.
533 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
534 call term_sendkeys(buf, "tty\r")
535 call WaitForAssert({-> assert_notequal('', term_getline(buf, 3))})
536 let tty = term_getline(buf, 2)
537 call assert_equal(tty, gettty)
538 endif
539
540 let gettty0 = term_gettty(buf, 0)
541 let gettty1 = term_gettty(buf, 1)
542
543 call assert_equal(gettty, gettty0)
544 call assert_equal(job_info(g:job).tty_out, gettty0)
545 call assert_equal(job_info(g:job).tty_in, gettty1)
546
547 if has('unix')
548 " For unix, term_gettty(..., 0) and term_gettty(..., 1)
549 " are identical according to :help term_gettty()
550 call assert_equal(gettty0, gettty1)
551 call assert_match('^/dev/', gettty)
552 else
553 " ConPTY works on anonymous pipe.
554 if !has('conpty')
555 call assert_match('^\\\\.\\pipe\\', gettty0)
556 call assert_match('^\\\\.\\pipe\\', gettty1)
557 endif
558 endif
559
Bram Moolenaarbade44e2020-09-26 22:39:24 +0200560 call assert_fails('call term_gettty(buf, 2)', 'E475:')
561 call assert_fails('call term_gettty(buf, -1)', 'E475:')
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200562
563 call assert_equal('', term_gettty(buf + 1))
564
565 call StopShellInTerminal(buf)
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200566 exe buf . 'bwipe'
567endfunc
568
Bram Moolenaar1112c0f2020-07-01 21:53:50 +0200569
570" vim: shiftwidth=2 sts=2 expandtab