comparison src/testdir/test_terminal2.vim @ 21253:ffa6b82fa993 v8.2.1177

patch 8.2.1177: terminal2 test sometimes hangs in the GUI Commit: https://github.com/vim/vim/commit/18aa13d13b69c090dbe186cd4939896488c433e3 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 11 13:09:36 2020 +0200 patch 8.2.1177: terminal2 test sometimes hangs in the GUI Problem: Terminal2 test sometimes hangs in the GUI. Solution: Move some tests to other files to further locate the problem. Set the GUI to a fixed screen size.
author Bram Moolenaar <Bram@vim.org>
date Sat, 11 Jul 2020 13:15:04 +0200
parents a35036006352
children 34a0f73226d9
comparison
equal deleted inserted replaced
21252:0eea722e7dd2 21253:ffa6b82fa993
1 " Tests for the terminal window. 1 " Tests for the terminal window.
2 " This is split in two, because it can take a lot of time. 2 " This is split in two, because it can take a lot of time.
3 " See test_terminal2.vim for further tests. 3 " See test_terminal.vim and test_terminal3.vim for further tests.
4 4
5 source check.vim 5 source check.vim
6 CheckFeature terminal 6 CheckFeature terminal
7 7
8 source shared.vim 8 source shared.vim
9 source screendump.vim 9 source screendump.vim
10 source mouse.vim 10 source mouse.vim
11 source term_util.vim 11 source term_util.vim
12 12
13 let s:python = PythonProg()
14 let $PROMPT_COMMAND='' 13 let $PROMPT_COMMAND=''
15
16 func Api_drop_common(options)
17 call assert_equal(1, winnr('$'))
18
19 " Use the title termcap entries to output the escape sequence.
20 call writefile([
21 \ 'set title',
22 \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"',
23 \ 'let &titlestring = ''["drop","Xtextfile"' . a:options . ']''',
24 \ 'redraw',
25 \ "set t_ts=",
26 \ ], 'Xscript')
27 let buf = RunVimInTerminal('-S Xscript', {})
28 call WaitFor({-> bufnr('Xtextfile') > 0})
29 call assert_equal('Xtextfile', expand('%:t'))
30 call assert_true(winnr('$') >= 3)
31 return buf
32 endfunc
33
34 func Test_terminal_api_drop_newwin()
35 CheckRunVimInTerminal
36 let buf = Api_drop_common('')
37 call assert_equal(0, &bin)
38 call assert_equal('', &fenc)
39
40 call StopVimInTerminal(buf)
41 call delete('Xscript')
42 bwipe Xtextfile
43 endfunc
44
45 func Test_terminal_api_drop_newwin_bin()
46 CheckRunVimInTerminal
47 let buf = Api_drop_common(',{"bin":1}')
48 call assert_equal(1, &bin)
49
50 call StopVimInTerminal(buf)
51 call delete('Xscript')
52 bwipe Xtextfile
53 endfunc
54
55 func Test_terminal_api_drop_newwin_binary()
56 CheckRunVimInTerminal
57 let buf = Api_drop_common(',{"binary":1}')
58 call assert_equal(1, &bin)
59
60 call StopVimInTerminal(buf)
61 call delete('Xscript')
62 bwipe Xtextfile
63 endfunc
64
65 func Test_terminal_api_drop_newwin_nobin()
66 CheckRunVimInTerminal
67 set binary
68 let buf = Api_drop_common(',{"nobin":1}')
69 call assert_equal(0, &bin)
70
71 call StopVimInTerminal(buf)
72 call delete('Xscript')
73 bwipe Xtextfile
74 set nobinary
75 endfunc
76
77 func Test_terminal_api_drop_newwin_nobinary()
78 CheckRunVimInTerminal
79 set binary
80 let buf = Api_drop_common(',{"nobinary":1}')
81 call assert_equal(0, &bin)
82
83 call StopVimInTerminal(buf)
84 call delete('Xscript')
85 bwipe Xtextfile
86 set nobinary
87 endfunc
88
89 func Test_terminal_api_drop_newwin_ff()
90 CheckRunVimInTerminal
91 let buf = Api_drop_common(',{"ff":"dos"}')
92 call assert_equal("dos", &ff)
93
94 call StopVimInTerminal(buf)
95 call delete('Xscript')
96 bwipe Xtextfile
97 endfunc
98
99 func Test_terminal_api_drop_newwin_fileformat()
100 CheckRunVimInTerminal
101 let buf = Api_drop_common(',{"fileformat":"dos"}')
102 call assert_equal("dos", &ff)
103
104 call StopVimInTerminal(buf)
105 call delete('Xscript')
106 bwipe Xtextfile
107 endfunc
108
109 func Test_terminal_api_drop_newwin_enc()
110 CheckRunVimInTerminal
111 let buf = Api_drop_common(',{"enc":"utf-16"}')
112 call assert_equal("utf-16", &fenc)
113
114 call StopVimInTerminal(buf)
115 call delete('Xscript')
116 bwipe Xtextfile
117 endfunc
118
119 func Test_terminal_api_drop_newwin_encoding()
120 CheckRunVimInTerminal
121 let buf = Api_drop_common(',{"encoding":"utf-16"}')
122 call assert_equal("utf-16", &fenc)
123
124 call StopVimInTerminal(buf)
125 call delete('Xscript')
126 bwipe Xtextfile
127 endfunc
128
129 func Test_terminal_api_drop_oldwin()
130 CheckRunVimInTerminal
131 let firstwinid = win_getid()
132 split Xtextfile
133 let textfile_winid = win_getid()
134 call assert_equal(2, winnr('$'))
135 call win_gotoid(firstwinid)
136
137 " Use the title termcap entries to output the escape sequence.
138 call writefile([
139 \ 'set title',
140 \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"',
141 \ 'let &titlestring = ''["drop","Xtextfile"]''',
142 \ 'redraw',
143 \ "set t_ts=",
144 \ ], 'Xscript')
145 let buf = RunVimInTerminal('-S Xscript', {'rows': 10})
146 call WaitForAssert({-> assert_equal('Xtextfile', expand('%:t'))})
147 call assert_equal(textfile_winid, win_getid())
148
149 call StopVimInTerminal(buf)
150 call delete('Xscript')
151 bwipe Xtextfile
152 endfunc
153
154 func Tapi_TryThis(bufnum, arg)
155 let g:called_bufnum = a:bufnum
156 let g:called_arg = a:arg
157 endfunc
158
159 func WriteApiCall(funcname)
160 " Use the title termcap entries to output the escape sequence.
161 call writefile([
162 \ 'set title',
163 \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"',
164 \ 'let &titlestring = ''["call","' . a:funcname . '",["hello",123]]''',
165 \ 'redraw',
166 \ "set t_ts=",
167 \ ], 'Xscript')
168 endfunc
169
170 func Test_terminal_api_call()
171 CheckRunVimInTerminal
172
173 unlet! g:called_bufnum
174 unlet! g:called_arg
175
176 call WriteApiCall('Tapi_TryThis')
177
178 " Default
179 let buf = RunVimInTerminal('-S Xscript', {})
180 call WaitFor({-> exists('g:called_bufnum')})
181 call assert_equal(buf, g:called_bufnum)
182 call assert_equal(['hello', 123], g:called_arg)
183 call StopVimInTerminal(buf)
184
185 unlet! g:called_bufnum
186 unlet! g:called_arg
187
188 " Enable explicitly
189 let buf = RunVimInTerminal('-S Xscript', {'term_api': 'Tapi_Try'})
190 call WaitFor({-> exists('g:called_bufnum')})
191 call assert_equal(buf, g:called_bufnum)
192 call assert_equal(['hello', 123], g:called_arg)
193 call StopVimInTerminal(buf)
194
195 unlet! g:called_bufnum
196 unlet! g:called_arg
197
198 func! ApiCall_TryThis(bufnum, arg)
199 let g:called_bufnum2 = a:bufnum
200 let g:called_arg2 = a:arg
201 endfunc
202
203 call WriteApiCall('ApiCall_TryThis')
204
205 " Use prefix match
206 let buf = RunVimInTerminal('-S Xscript', {'term_api': 'ApiCall_'})
207 call WaitFor({-> exists('g:called_bufnum2')})
208 call assert_equal(buf, g:called_bufnum2)
209 call assert_equal(['hello', 123], g:called_arg2)
210 call StopVimInTerminal(buf)
211
212 call assert_fails("call term_start('ls', {'term_api' : []})", 'E475:')
213
214 unlet! g:called_bufnum2
215 unlet! g:called_arg2
216
217 call delete('Xscript')
218 delfunction! ApiCall_TryThis
219 unlet! g:called_bufnum2
220 unlet! g:called_arg2
221 endfunc
222
223 func Test_terminal_api_call_fails()
224 CheckRunVimInTerminal
225
226 func! TryThis(bufnum, arg)
227 let g:called_bufnum3 = a:bufnum
228 let g:called_arg3 = a:arg
229 endfunc
230
231 call WriteApiCall('TryThis')
232
233 unlet! g:called_bufnum3
234 unlet! g:called_arg3
235
236 " Not permitted
237 call ch_logfile('Xlog', 'w')
238 let buf = RunVimInTerminal('-S Xscript', {'term_api': ''})
239 call WaitForAssert({-> assert_match('Unpermitted function: TryThis', string(readfile('Xlog')))})
240 call assert_false(exists('g:called_bufnum3'))
241 call assert_false(exists('g:called_arg3'))
242 call StopVimInTerminal(buf)
243
244 " No match
245 call ch_logfile('Xlog', 'w')
246 let buf = RunVimInTerminal('-S Xscript', {'term_api': 'TryThat'})
247 call WaitFor({-> string(readfile('Xlog')) =~ 'Unpermitted function: TryThis'})
248 call assert_false(exists('g:called_bufnum3'))
249 call assert_false(exists('g:called_arg3'))
250 call StopVimInTerminal(buf)
251
252 call delete('Xscript')
253 call ch_logfile('')
254 call delete('Xlog')
255 delfunction! TryThis
256 unlet! g:called_bufnum3
257 unlet! g:called_arg3
258 endfunc
259
260 let s:caught_e937 = 0
261
262 func Tapi_Delete(bufnum, arg)
263 try
264 execute 'bdelete!' a:bufnum
265 catch /E937:/
266 let s:caught_e937 = 1
267 endtry
268 endfunc
269
270 func Test_terminal_api_call_fail_delete()
271 CheckRunVimInTerminal
272
273 call WriteApiCall('Tapi_Delete')
274 let buf = RunVimInTerminal('-S Xscript', {})
275 call WaitForAssert({-> assert_equal(1, s:caught_e937)})
276
277 call StopVimInTerminal(buf)
278 call delete('Xscript')
279 call ch_logfile('', '')
280 endfunc
281
282 func Test_terminal_ansicolors_default()
283 CheckFunction term_getansicolors
284
285 let colors = [
286 \ '#000000', '#e00000',
287 \ '#00e000', '#e0e000',
288 \ '#0000e0', '#e000e0',
289 \ '#00e0e0', '#e0e0e0',
290 \ '#808080', '#ff4040',
291 \ '#40ff40', '#ffff40',
292 \ '#4040ff', '#ff40ff',
293 \ '#40ffff', '#ffffff',
294 \]
295
296 let buf = Run_shell_in_terminal({})
297 call assert_equal(colors, term_getansicolors(buf))
298 call StopShellInTerminal(buf)
299 call TermWait(buf)
300 call assert_equal([], term_getansicolors(buf))
301
302 exe buf . 'bwipe'
303 endfunc
304
305 let s:test_colors = [
306 \ '#616e64', '#0d0a79',
307 \ '#6d610d', '#0a7373',
308 \ '#690d0a', '#6d696e',
309 \ '#0d0a6f', '#616e0d',
310 \ '#0a6479', '#6d0d0a',
311 \ '#617373', '#0d0a69',
312 \ '#6d690d', '#0a6e6f',
313 \ '#610d0a', '#6e6479',
314 \]
315
316 func Test_terminal_ansicolors_global()
317 CheckFeature termguicolors
318 CheckFunction term_getansicolors
319
320 let g:terminal_ansi_colors = reverse(copy(s:test_colors))
321 let buf = Run_shell_in_terminal({})
322 call assert_equal(g:terminal_ansi_colors, term_getansicolors(buf))
323 call StopShellInTerminal(buf)
324 call TermWait(buf)
325
326 exe buf . 'bwipe'
327 unlet g:terminal_ansi_colors
328 endfunc
329
330 func Test_terminal_ansicolors_func()
331 CheckFeature termguicolors
332 CheckFunction term_getansicolors
333
334 let g:terminal_ansi_colors = reverse(copy(s:test_colors))
335 let buf = Run_shell_in_terminal({'ansi_colors': s:test_colors})
336 call assert_equal(s:test_colors, term_getansicolors(buf))
337
338 call term_setansicolors(buf, g:terminal_ansi_colors)
339 call assert_equal(g:terminal_ansi_colors, buf->term_getansicolors())
340
341 let colors = [
342 \ 'ivory', 'AliceBlue',
343 \ 'grey67', 'dark goldenrod',
344 \ 'SteelBlue3', 'PaleVioletRed4',
345 \ 'MediumPurple2', 'yellow2',
346 \ 'RosyBrown3', 'OrangeRed2',
347 \ 'white smoke', 'navy blue',
348 \ 'grey47', 'gray97',
349 \ 'MistyRose2', 'DodgerBlue4',
350 \]
351 eval buf->term_setansicolors(colors)
352
353 let colors[4] = 'Invalid'
354 call assert_fails('call term_setansicolors(buf, colors)', 'E474:')
355 call assert_fails('call term_setansicolors(buf, {})', 'E714:')
356
357 call StopShellInTerminal(buf)
358 call TermWait(buf)
359 call assert_equal(0, term_setansicolors(buf, []))
360 exe buf . 'bwipe'
361 endfunc
362
363 func Test_terminal_all_ansi_colors()
364 CheckRunVimInTerminal
365
366 " Use all the ANSI colors.
367 call writefile([
368 \ 'call setline(1, "AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP XXYYZZ")',
369 \ 'hi Tblack ctermfg=0 ctermbg=8',
370 \ 'hi Tdarkred ctermfg=1 ctermbg=9',
371 \ 'hi Tdarkgreen ctermfg=2 ctermbg=10',
372 \ 'hi Tbrown ctermfg=3 ctermbg=11',
373 \ 'hi Tdarkblue ctermfg=4 ctermbg=12',
374 \ 'hi Tdarkmagenta ctermfg=5 ctermbg=13',
375 \ 'hi Tdarkcyan ctermfg=6 ctermbg=14',
376 \ 'hi Tlightgrey ctermfg=7 ctermbg=15',
377 \ 'hi Tdarkgrey ctermfg=8 ctermbg=0',
378 \ 'hi Tred ctermfg=9 ctermbg=1',
379 \ 'hi Tgreen ctermfg=10 ctermbg=2',
380 \ 'hi Tyellow ctermfg=11 ctermbg=3',
381 \ 'hi Tblue ctermfg=12 ctermbg=4',
382 \ 'hi Tmagenta ctermfg=13 ctermbg=5',
383 \ 'hi Tcyan ctermfg=14 ctermbg=6',
384 \ 'hi Twhite ctermfg=15 ctermbg=7',
385 \ 'hi TdarkredBold ctermfg=1 cterm=bold',
386 \ 'hi TgreenBold ctermfg=10 cterm=bold',
387 \ 'hi TmagentaBold ctermfg=13 cterm=bold ctermbg=5',
388 \ '',
389 \ 'call matchadd("Tblack", "A")',
390 \ 'call matchadd("Tdarkred", "B")',
391 \ 'call matchadd("Tdarkgreen", "C")',
392 \ 'call matchadd("Tbrown", "D")',
393 \ 'call matchadd("Tdarkblue", "E")',
394 \ 'call matchadd("Tdarkmagenta", "F")',
395 \ 'call matchadd("Tdarkcyan", "G")',
396 \ 'call matchadd("Tlightgrey", "H")',
397 \ 'call matchadd("Tdarkgrey", "I")',
398 \ 'call matchadd("Tred", "J")',
399 \ 'call matchadd("Tgreen", "K")',
400 \ 'call matchadd("Tyellow", "L")',
401 \ 'call matchadd("Tblue", "M")',
402 \ 'call matchadd("Tmagenta", "N")',
403 \ 'call matchadd("Tcyan", "O")',
404 \ 'call matchadd("Twhite", "P")',
405 \ 'call matchadd("TdarkredBold", "X")',
406 \ 'call matchadd("TgreenBold", "Y")',
407 \ 'call matchadd("TmagentaBold", "Z")',
408 \ 'redraw',
409 \ ], 'Xcolorscript')
410 let buf = RunVimInTerminal('-S Xcolorscript', {'rows': 10})
411 call VerifyScreenDump(buf, 'Test_terminal_all_ansi_colors', {})
412
413 call term_sendkeys(buf, ":q\<CR>")
414 call StopVimInTerminal(buf)
415 call delete('Xcolorscript')
416 endfunc
417 14
418 func Test_terminal_termwinsize_option_fixed() 15 func Test_terminal_termwinsize_option_fixed()
419 CheckRunVimInTerminal 16 CheckRunVimInTerminal
420 set termwinsize=6x40 17 set termwinsize=6x40
421 let text = [] 18 let text = []
973 exe buf . 'bwipe!' 570 exe buf . 'bwipe!'
974 set splitright& 571 set splitright&
975 only! 572 only!
976 endfunc 573 endfunc
977 574
978 func Test_terminal_altscreen()
979 " somehow doesn't work on MS-Windows
980 CheckUnix
981 let cmd = "cat Xtext\<CR>"
982
983 let buf = term_start(&shell, {})
984 call writefile(["\<Esc>[?1047h"], 'Xtext')
985 call term_sendkeys(buf, cmd)
986 call WaitForAssert({-> assert_equal(1, term_getaltscreen(buf))})
987
988 call writefile(["\<Esc>[?1047l"], 'Xtext')
989 call term_sendkeys(buf, cmd)
990 call WaitForAssert({-> assert_equal(0, term_getaltscreen(buf))})
991
992 call term_sendkeys(buf, "exit\r")
993 exe buf . "bwipe!"
994 call delete('Xtext')
995 endfunc
996
997 func Test_terminal_shell_option()
998 if has('unix')
999 " exec is a shell builtin command, should fail without a shell.
1000 term exec ls runtest.vim
1001 call WaitForAssert({-> assert_match('job failed', term_getline(bufnr(), 1))})
1002 bwipe!
1003
1004 term ++shell exec ls runtest.vim
1005 call WaitForAssert({-> assert_match('runtest.vim', term_getline(bufnr(), 1))})
1006 bwipe!
1007 elseif has('win32')
1008 " dir is a shell builtin command, should fail without a shell.
1009 try
1010 term dir /b runtest.vim
1011 call WaitForAssert({-> assert_match('job failed\|cannot access .*: No such file or directory', term_getline(bufnr(), 1))})
1012 catch /CreateProcess/
1013 " ignore
1014 endtry
1015 bwipe!
1016
1017 term ++shell dir /b runtest.vim
1018 call WaitForAssert({-> assert_match('runtest.vim', term_getline(bufnr(), 1))})
1019 bwipe!
1020 endif
1021 endfunc
1022
1023 func Test_terminal_setapi_and_call()
1024 CheckRunVimInTerminal
1025
1026 call WriteApiCall('Tapi_TryThis')
1027 call ch_logfile('Xlog', 'w')
1028
1029 unlet! g:called_bufnum
1030 unlet! g:called_arg
1031
1032 let buf = RunVimInTerminal('-S Xscript', {'term_api': ''})
1033 call WaitForAssert({-> assert_match('Unpermitted function: Tapi_TryThis', string(readfile('Xlog')))})
1034 call assert_false(exists('g:called_bufnum'))
1035 call assert_false(exists('g:called_arg'))
1036
1037 eval buf->term_setapi('Tapi_')
1038 call term_sendkeys(buf, ":set notitle\<CR>")
1039 call term_sendkeys(buf, ":source Xscript\<CR>")
1040 call WaitFor({-> exists('g:called_bufnum')})
1041 call assert_equal(buf, g:called_bufnum)
1042 call assert_equal(['hello', 123], g:called_arg)
1043
1044 call StopVimInTerminal(buf)
1045
1046 call delete('Xscript')
1047 call ch_logfile('')
1048 call delete('Xlog')
1049 unlet! g:called_bufnum
1050 unlet! g:called_arg
1051 endfunc
1052
1053 func Test_terminal_api_arg()
1054 CheckRunVimInTerminal
1055
1056 call WriteApiCall('Tapi_TryThis')
1057 call ch_logfile('Xlog', 'w')
1058
1059 unlet! g:called_bufnum
1060 unlet! g:called_arg
1061
1062 execute 'term ++api= ' .. GetVimCommandCleanTerm() .. '-S Xscript'
1063 let buf = bufnr('%')
1064 call WaitForAssert({-> assert_match('Unpermitted function: Tapi_TryThis', string(readfile('Xlog')))})
1065 call assert_false(exists('g:called_bufnum'))
1066 call assert_false(exists('g:called_arg'))
1067
1068 call StopVimInTerminal(buf)
1069
1070 call ch_logfile('Xlog', 'w')
1071
1072 execute 'term ++api=Tapi_ ' .. GetVimCommandCleanTerm() .. '-S Xscript'
1073 let buf = bufnr('%')
1074 call WaitFor({-> exists('g:called_bufnum')})
1075 call assert_equal(buf, g:called_bufnum)
1076 call assert_equal(['hello', 123], g:called_arg)
1077
1078 call StopVimInTerminal(buf)
1079
1080 call delete('Xscript')
1081 call ch_logfile('')
1082 call delete('Xlog')
1083 unlet! g:called_bufnum
1084 unlet! g:called_arg
1085 endfunc
1086
1087 func Test_terminal_invalid_arg()
1088 call assert_fails('terminal ++xyz', 'E181:')
1089 endfunc
1090
1091 func Test_terminal_in_popup()
1092 CheckRunVimInTerminal
1093
1094 let text =<< trim END
1095 some text
1096 to edit
1097 in a popup window
1098 END
1099 call writefile(text, 'Xtext')
1100 let cmd = GetVimCommandCleanTerm()
1101 let lines = [
1102 \ 'call setline(1, range(20))',
1103 \ 'hi PopTerm ctermbg=grey',
1104 \ 'func OpenTerm(setColor)',
1105 \ " set noruler",
1106 \ " let s:buf = term_start('" .. cmd .. " Xtext', #{hidden: 1, term_finish: 'close'})",
1107 \ ' let g:winid = popup_create(s:buf, #{minwidth: 45, minheight: 7, border: [], drag: 1, resize: 1})',
1108 \ ' if a:setColor',
1109 \ ' call win_execute(g:winid, "set wincolor=PopTerm")',
1110 \ ' endif',
1111 \ 'endfunc',
1112 \ 'func HidePopup()',
1113 \ ' call popup_hide(g:winid)',
1114 \ 'endfunc',
1115 \ 'func ClosePopup()',
1116 \ ' call popup_close(g:winid)',
1117 \ 'endfunc',
1118 \ 'func ReopenPopup()',
1119 \ ' call popup_create(s:buf, #{minwidth: 40, minheight: 6, border: []})',
1120 \ 'endfunc',
1121 \ ]
1122 call writefile(lines, 'XtermPopup')
1123 let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15})
1124 call TermWait(buf, 100)
1125 call term_sendkeys(buf, ":call OpenTerm(0)\<CR>")
1126 call TermWait(buf, 100)
1127 call term_sendkeys(buf, ":\<CR>")
1128 call TermWait(buf, 100)
1129 call term_sendkeys(buf, "\<C-W>:echo getwinvar(g:winid, \"&buftype\") win_gettype(g:winid)\<CR>")
1130 call VerifyScreenDump(buf, 'Test_terminal_popup_1', {})
1131
1132 call term_sendkeys(buf, ":q\<CR>")
1133 call VerifyScreenDump(buf, 'Test_terminal_popup_2', {})
1134
1135 call term_sendkeys(buf, ":call OpenTerm(1)\<CR>")
1136 call TermWait(buf, 150)
1137 call term_sendkeys(buf, ":set hlsearch\<CR>")
1138 call TermWait(buf, 100)
1139 call term_sendkeys(buf, "/edit\<CR>")
1140 call VerifyScreenDump(buf, 'Test_terminal_popup_3', {})
1141
1142 call term_sendkeys(buf, "\<C-W>:call HidePopup()\<CR>")
1143 call VerifyScreenDump(buf, 'Test_terminal_popup_4', {})
1144 call term_sendkeys(buf, "\<CR>")
1145 call TermWait(buf, 50)
1146
1147 call term_sendkeys(buf, "\<C-W>:call ClosePopup()\<CR>")
1148 call VerifyScreenDump(buf, 'Test_terminal_popup_5', {})
1149
1150 call term_sendkeys(buf, "\<C-W>:call ReopenPopup()\<CR>")
1151 call VerifyScreenDump(buf, 'Test_terminal_popup_6', {})
1152
1153 " Go to terminal-Normal mode and visually select text.
1154 call term_sendkeys(buf, "\<C-W>Ngg/in\<CR>vww")
1155 call VerifyScreenDump(buf, 'Test_terminal_popup_7', {})
1156
1157 " Back to job mode, redraws
1158 call term_sendkeys(buf, "A")
1159 call VerifyScreenDump(buf, 'Test_terminal_popup_8', {})
1160
1161 call TermWait(buf, 50)
1162 call term_sendkeys(buf, ":q\<CR>")
1163 call TermWait(buf, 150) " wait for terminal to vanish
1164
1165 call StopVimInTerminal(buf)
1166 call delete('Xtext')
1167 call delete('XtermPopup')
1168 endfunc
1169
1170 " Check a terminal in popup window uses the default mininum size.
1171 func Test_terminal_in_popup_min_size()
1172 CheckRunVimInTerminal
1173
1174 let text =<< trim END
1175 another text
1176 to show
1177 in a popup window
1178 END
1179 call writefile(text, 'Xtext')
1180 let lines = [
1181 \ 'call setline(1, range(20))',
1182 \ 'func OpenTerm()',
1183 \ " let s:buf = term_start('cat Xtext', #{hidden: 1})",
1184 \ ' let g:winid = popup_create(s:buf, #{ border: []})',
1185 \ 'endfunc',
1186 \ ]
1187 call writefile(lines, 'XtermPopup')
1188 let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15})
1189 call TermWait(buf, 100)
1190 call term_sendkeys(buf, ":set noruler\<CR>")
1191 call term_sendkeys(buf, ":call OpenTerm()\<CR>")
1192 call TermWait(buf, 50)
1193 call term_sendkeys(buf, ":\<CR>")
1194 call VerifyScreenDump(buf, 'Test_terminal_popup_m1', {})
1195
1196 call TermWait(buf, 50)
1197 call term_sendkeys(buf, ":q\<CR>")
1198 call TermWait(buf, 50) " wait for terminal to vanish
1199 call StopVimInTerminal(buf)
1200 call delete('Xtext')
1201 call delete('XtermPopup')
1202 endfunc
1203
1204 " Check a terminal in popup window with different colors
1205 func Terminal_in_popup_colored(group_name, highlight_cmd, highlight_opt)
1206 CheckRunVimInTerminal
1207 CheckUnix
1208
1209 let lines = [
1210 \ 'call setline(1, range(20))',
1211 \ 'func OpenTerm()',
1212 \ " let s:buf = term_start('cat', #{hidden: 1, "
1213 \ .. a:highlight_opt .. "})",
1214 \ ' let g:winid = popup_create(s:buf, #{ border: []})',
1215 \ 'endfunc',
1216 \ a:highlight_cmd,
1217 \ ]
1218 call writefile(lines, 'XtermPopup')
1219 let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15})
1220 call TermWait(buf, 100)
1221 call term_sendkeys(buf, ":set noruler\<CR>")
1222 call term_sendkeys(buf, ":call OpenTerm()\<CR>")
1223 call TermWait(buf, 50)
1224 call term_sendkeys(buf, "hello\<CR>")
1225 call VerifyScreenDump(buf, 'Test_terminal_popup_' .. a:group_name, {})
1226
1227 call term_sendkeys(buf, "\<C-D>")
1228 call TermWait(buf, 50)
1229 call term_sendkeys(buf, ":q\<CR>")
1230 call TermWait(buf, 50) " wait for terminal to vanish
1231 call StopVimInTerminal(buf)
1232 call delete('XtermPopup')
1233 endfunc
1234
1235 func Test_terminal_in_popup_colored_Terminal()
1236 call Terminal_in_popup_colored("Terminal", "highlight Terminal ctermfg=blue ctermbg=yellow", "")
1237 endfunc
1238
1239 func Test_terminal_in_popup_colored_group()
1240 call Terminal_in_popup_colored("MyTermCol", "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue", "term_highlight: 'MyTermCol',")
1241 endfunc
1242
1243 func Test_double_popup_terminal()
1244 let buf1 = term_start(&shell, #{hidden: 1})
1245 let win1 = popup_create(buf1, {})
1246 let buf2 = term_start(&shell, #{hidden: 1})
1247 call assert_fails('call popup_create(buf2, {})', 'E861:')
1248 call popup_close(win1)
1249 exe buf1 .. 'bwipe!'
1250 exe buf2 .. 'bwipe!'
1251 endfunc
1252
1253 func Test_issue_5607()
1254 let wincount = winnr('$')
1255 exe 'terminal' &shell &shellcmdflag 'exit'
1256 let job = term_getjob(bufnr())
1257 call WaitForAssert({-> assert_equal("dead", job_status(job))})
1258
1259 let old_wincolor = &wincolor
1260 try
1261 set wincolor=
1262 finally
1263 let &wincolor = old_wincolor
1264 bw!
1265 endtry
1266 endfunc
1267
1268 func Test_hidden_terminal()
1269 let buf = term_start(&shell, #{hidden: 1})
1270 call assert_equal('', bufname('^$'))
1271 call StopShellInTerminal(buf)
1272 endfunc
1273
1274 func Test_term_nasty_callback()
1275 CheckExecutable sh
1276
1277 set hidden
1278 let g:buf0 = term_start('sh', #{hidden: 1, term_finish: 'close'})
1279 call popup_create(g:buf0, {})
1280 call assert_fails("call term_start(['sh', '-c'], #{curwin: 1})", 'E863:')
1281
1282 call popup_clear(1)
1283 set hidden&
1284 endfunc
1285
1286 func Test_term_and_startinsert()
1287 CheckRunVimInTerminal
1288 CheckUnix
1289
1290 let lines =<< trim EOL
1291 put='some text'
1292 term
1293 startinsert
1294 EOL
1295 call writefile(lines, 'XTest_startinsert')
1296 let buf = RunVimInTerminal('-S XTest_startinsert', {})
1297
1298 call term_sendkeys(buf, "exit\r")
1299 call WaitForAssert({-> assert_equal("some text", term_getline(buf, 1))})
1300 call term_sendkeys(buf, "0l")
1301 call term_sendkeys(buf, "A<\<Esc>")
1302 call WaitForAssert({-> assert_equal("some text<", term_getline(buf, 1))})
1303
1304 call StopVimInTerminal(buf)
1305 call delete('XTest_startinsert')
1306 endfunc
1307
1308 " Test for passing invalid arguments to terminal functions
1309 func Test_term_func_invalid_arg()
1310 call assert_fails('let b = term_getaltscreen([])', 'E745:')
1311 call assert_fails('let a = term_getattr(1, [])', 'E730:')
1312 call assert_fails('let c = term_getcursor([])', 'E745:')
1313 call assert_fails('let l = term_getline([], 1)', 'E745:')
1314 call assert_fails('let l = term_getscrolled([])', 'E745:')
1315 call assert_fails('let s = term_getsize([])', 'E745:')
1316 call assert_fails('let s = term_getstatus([])', 'E745:')
1317 call assert_fails('let s = term_scrape([], 1)', 'E745:')
1318 call assert_fails('call term_sendkeys([], "a")', 'E745:')
1319 call assert_fails('call term_setapi([], "")', 'E745:')
1320 call assert_fails('call term_setrestore([], "")', 'E745:')
1321 call assert_fails('call term_setkill([], "")', 'E745:')
1322 if has('gui') || has('termguicolors')
1323 call assert_fails('let p = term_getansicolors([])', 'E745:')
1324 call assert_fails('call term_setansicolors([], [])', 'E745:')
1325 endif
1326 endfunc
1327
1328 " Test for sending various special keycodes to a terminal
1329 func Test_term_keycode_translation()
1330 CheckRunVimInTerminal
1331
1332 let buf = RunVimInTerminal('', {})
1333 call term_sendkeys(buf, ":set nocompatible\<CR>")
1334
1335 let keys = ["\<F1>", "\<F2>", "\<F3>", "\<F4>", "\<F5>", "\<F6>", "\<F7>",
1336 \ "\<F8>", "\<F9>", "\<F10>", "\<F11>", "\<F12>", "\<Home>",
1337 \ "\<S-Home>", "\<C-Home>", "\<End>", "\<S-End>", "\<C-End>",
1338 \ "\<Ins>", "\<Del>", "\<Left>", "\<S-Left>", "\<C-Left>", "\<Right>",
1339 \ "\<S-Right>", "\<C-Right>", "\<Up>", "\<S-Up>", "\<Down>",
1340 \ "\<S-Down>"]
1341 let output = ['<F1>', '<F2>', '<F3>', '<F4>', '<F5>', '<F6>', '<F7>',
1342 \ '<F8>', '<F9>', '<F10>', '<F11>', '<F12>', '<Home>', '<S-Home>',
1343 \ '<C-Home>', '<End>', '<S-End>', '<C-End>', '<Insert>', '<Del>',
1344 \ '<Left>', '<S-Left>', '<C-Left>', '<Right>', '<S-Right>',
1345 \ '<C-Right>', '<Up>', '<S-Up>', '<Down>', '<S-Down>']
1346
1347 call term_sendkeys(buf, "i")
1348 for i in range(len(keys))
1349 call term_sendkeys(buf, "\<C-U>\<C-K>" .. keys[i])
1350 call WaitForAssert({-> assert_equal(output[i], term_getline(buf, 1))})
1351 endfor
1352
1353 let keypad_keys = ["\<k0>", "\<k1>", "\<k2>", "\<k3>", "\<k4>", "\<k5>",
1354 \ "\<k6>", "\<k7>", "\<k8>", "\<k9>", "\<kPoint>", "\<kPlus>",
1355 \ "\<kMinus>", "\<kMultiply>", "\<kDivide>"]
1356 let keypad_output = ['0', '1', '2', '3', '4', '5',
1357 \ '6', '7', '8', '9', '.', '+',
1358 \ '-', '*', '/']
1359 for i in range(len(keypad_keys))
1360 " TODO: Mysteriously keypad 3 and 9 do not work on some systems.
1361 if keypad_output[i] == '3' || keypad_output[i] == '9'
1362 continue
1363 endif
1364 call term_sendkeys(buf, "\<C-U>" .. keypad_keys[i])
1365 call WaitForAssert({-> assert_equal(keypad_output[i], term_getline(buf, 1))})
1366 endfor
1367
1368 call feedkeys("\<C-U>\<kEnter>\<BS>one\<C-W>.two", 'xt')
1369 call WaitForAssert({-> assert_equal('two', term_getline(buf, 1))})
1370
1371 call StopVimInTerminal(buf)
1372 endfunc
1373
1374 " Test for using the mouse in a terminal
1375 func Test_term_mouse()
1376 CheckNotGui
1377 CheckRunVimInTerminal
1378
1379 let save_mouse = &mouse
1380 let save_term = &term
1381 let save_ttymouse = &ttymouse
1382 let save_clipboard = &clipboard
1383 set mouse=a term=xterm ttymouse=sgr mousetime=200 clipboard=
1384
1385 let lines =<< trim END
1386 one two three four five
1387 red green yellow red blue
1388 vim emacs sublime nano
1389 END
1390 call writefile(lines, 'Xtest_mouse')
1391
1392 " Create a terminal window running Vim for the test with mouse enabled
1393 let prev_win = win_getid()
1394 let buf = RunVimInTerminal('Xtest_mouse -n', {})
1395 call term_sendkeys(buf, ":set nocompatible\<CR>")
1396 call term_sendkeys(buf, ":set mouse=a term=xterm ttymouse=sgr\<CR>")
1397 call term_sendkeys(buf, ":set clipboard=\<CR>")
1398 call term_sendkeys(buf, ":set mousemodel=extend\<CR>")
1399 call term_wait(buf)
1400 redraw!
1401
1402 " Use the mouse to enter the terminal window
1403 call win_gotoid(prev_win)
1404 call feedkeys(MouseLeftClickCode(1, 1), 'x')
1405 call feedkeys(MouseLeftReleaseCode(1, 1), 'x')
1406 call assert_equal(1, getwininfo(win_getid())[0].terminal)
1407
1408 " Test for <LeftMouse> click/release
1409 call test_setmouse(2, 5)
1410 call feedkeys("\<LeftMouse>\<LeftRelease>", 'xt')
1411 call test_setmouse(3, 8)
1412 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>")
1413 call term_wait(buf, 50)
1414 call term_sendkeys(buf, ":call writefile([json_encode(getpos('.'))], 'Xbuf')\<CR>")
1415 call term_wait(buf, 50)
1416 let pos = json_decode(readfile('Xbuf')[0])
1417 call assert_equal([3, 8], pos[1:2])
1418
1419 " Test for selecting text using mouse
1420 call delete('Xbuf')
1421 call test_setmouse(2, 11)
1422 call term_sendkeys(buf, "\<LeftMouse>")
1423 call test_setmouse(2, 16)
1424 call term_sendkeys(buf, "\<LeftRelease>y")
1425 call term_wait(buf, 50)
1426 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
1427 call term_wait(buf, 50)
1428 call assert_equal('yellow', readfile('Xbuf')[0])
1429
1430 " Test for selecting text using doubleclick
1431 call delete('Xbuf')
1432 call test_setmouse(1, 11)
1433 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>")
1434 call test_setmouse(1, 17)
1435 call term_sendkeys(buf, "\<LeftRelease>y")
1436 call term_wait(buf, 50)
1437 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
1438 call term_wait(buf, 50)
1439 call assert_equal('three four', readfile('Xbuf')[0])
1440
1441 " Test for selecting a line using triple click
1442 call delete('Xbuf')
1443 call test_setmouse(3, 2)
1444 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>y")
1445 call term_wait(buf, 50)
1446 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
1447 call term_wait(buf, 50)
1448 call assert_equal("vim emacs sublime nano\n", readfile('Xbuf')[0])
1449
1450 " Test for selecting a block using qudraple click
1451 call delete('Xbuf')
1452 call test_setmouse(1, 11)
1453 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>")
1454 call test_setmouse(3, 13)
1455 call term_sendkeys(buf, "\<LeftRelease>y")
1456 call term_wait(buf, 50)
1457 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
1458 call term_wait(buf, 50)
1459 call assert_equal("ree\nyel\nsub", readfile('Xbuf')[0])
1460
1461 " Test for extending a selection using right click
1462 call delete('Xbuf')
1463 call test_setmouse(2, 9)
1464 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>")
1465 call test_setmouse(2, 16)
1466 call term_sendkeys(buf, "\<RightMouse>\<RightRelease>y")
1467 call term_wait(buf, 50)
1468 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
1469 call term_wait(buf, 50)
1470 call assert_equal("n yellow", readfile('Xbuf')[0])
1471
1472 " Test for pasting text using middle click
1473 call delete('Xbuf')
1474 call term_sendkeys(buf, ":let @r='bright '\<CR>")
1475 call test_setmouse(2, 22)
1476 call term_sendkeys(buf, "\"r\<MiddleMouse>\<MiddleRelease>")
1477 call term_wait(buf, 50)
1478 call term_sendkeys(buf, ":call writefile([getline(2)], 'Xbuf')\<CR>")
1479 call term_wait(buf, 50)
1480 call assert_equal("red bright blue", readfile('Xbuf')[0][-15:])
1481
1482 " cleanup
1483 call term_wait(buf)
1484 call StopVimInTerminal(buf)
1485 let &mouse = save_mouse
1486 let &term = save_term
1487 let &ttymouse = save_ttymouse
1488 let &clipboard = save_clipboard
1489 set mousetime&
1490 call delete('Xtest_mouse')
1491 call delete('Xbuf')
1492 endfunc
1493
1494 " Test for modeless selection in a terminal
1495 func Test_term_modeless_selection()
1496 CheckUnix
1497 CheckNotGui
1498 CheckRunVimInTerminal
1499 CheckFeature clipboard_working
1500
1501 let save_mouse = &mouse
1502 let save_term = &term
1503 let save_ttymouse = &ttymouse
1504 set mouse=a term=xterm ttymouse=sgr mousetime=200
1505 set clipboard=autoselectml
1506
1507 let lines =<< trim END
1508 one two three four five
1509 red green yellow red blue
1510 vim emacs sublime nano
1511 END
1512 call writefile(lines, 'Xtest_modeless')
1513
1514 " Create a terminal window running Vim for the test with mouse disabled
1515 let prev_win = win_getid()
1516 let buf = RunVimInTerminal('Xtest_modeless -n', {})
1517 call term_sendkeys(buf, ":set nocompatible\<CR>")
1518 call term_sendkeys(buf, ":set mouse=\<CR>")
1519 call term_wait(buf)
1520 redraw!
1521
1522 " Use the mouse to enter the terminal window
1523 call win_gotoid(prev_win)
1524 call feedkeys(MouseLeftClickCode(1, 1), 'x')
1525 call feedkeys(MouseLeftReleaseCode(1, 1), 'x')
1526 call term_wait(buf)
1527 call assert_equal(1, getwininfo(win_getid())[0].terminal)
1528
1529 " Test for copying a modeless selection to clipboard
1530 let @* = 'clean'
1531 " communicating with X server may take a little time
1532 sleep 100m
1533 call feedkeys(MouseLeftClickCode(2, 3), 'x')
1534 call feedkeys(MouseLeftDragCode(2, 11), 'x')
1535 call feedkeys(MouseLeftReleaseCode(2, 11), 'x')
1536 call assert_equal("d green y", @*)
1537
1538 " cleanup
1539 call term_wait(buf)
1540 call StopVimInTerminal(buf)
1541 let &mouse = save_mouse
1542 let &term = save_term
1543 let &ttymouse = save_ttymouse
1544 set mousetime& clipboard&
1545 call delete('Xtest_modeless')
1546 new | only!
1547 endfunc
1548
1549 575
1550 " vim: shiftwidth=2 sts=2 expandtab 576 " vim: shiftwidth=2 sts=2 expandtab