blob: 61193dfd3d26185509193b6b2e0efd6db1bd3677 [file] [log] [blame]
Bram Moolenaar461a7fc2018-12-22 13:28:07 +01001" Tests for :messages, :echomsg, :echoerr
Bram Moolenaar451f8492016-04-14 17:16:22 +02002
Christian Brabandteb380b92025-07-07 20:53:55 +02003source util/screendump.vim
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +02004
Bram Moolenaar49b2fb32020-04-25 17:13:56 +02005func Test_messages()
Bram Moolenaar451f8492016-04-14 17:16:22 +02006 let oldmore = &more
7 try
8 set nomore
9
10 let arr = map(range(10), '"hello" . v:val')
11 for s in arr
12 echomsg s | redraw
13 endfor
Bram Moolenaar451f8492016-04-14 17:16:22 +020014
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020015 " get last two messages
Bram Moolenaar451f8492016-04-14 17:16:22 +020016 redir => result
17 2messages | redraw
18 redir END
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020019 let msg_list = split(result, "\n")
20 call assert_equal(["hello8", "hello9"], msg_list)
Bram Moolenaar451f8492016-04-14 17:16:22 +020021
22 " clear messages without last one
23 1messages clear
Bram Moolenaar49b2fb32020-04-25 17:13:56 +020024 let msg_list = GetMessages()
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020025 call assert_equal(['hello9'], msg_list)
Bram Moolenaar451f8492016-04-14 17:16:22 +020026
27 " clear all messages
28 messages clear
Bram Moolenaar49b2fb32020-04-25 17:13:56 +020029 let msg_list = GetMessages()
30 call assert_equal([], msg_list)
Bram Moolenaar451f8492016-04-14 17:16:22 +020031 finally
32 let &more = oldmore
33 endtry
Bram Moolenaar067297e2020-04-13 19:55:50 +020034
35 call assert_fails('message 1', 'E474:')
Bram Moolenaar49b2fb32020-04-25 17:13:56 +020036endfunc
Bram Moolenaar2abad542018-05-19 14:43:45 +020037
Bram Moolenaarf52f9ea2018-06-27 20:49:44 +020038" Patch 7.4.1696 defined the "clearmode()" function for clearing the mode
Bram Moolenaar2abad542018-05-19 14:43:45 +020039" indicator (e.g., "-- INSERT --") when ":stopinsert" is invoked. Message
40" output could then be disturbed when 'cmdheight' was greater than one.
41" This test ensures that the bugfix for this issue remains in place.
Bram Moolenaar1e115362019-01-09 23:01:02 +010042func Test_stopinsert_does_not_break_message_output()
Bram Moolenaar2abad542018-05-19 14:43:45 +020043 set cmdheight=2
44 redraw!
45
46 stopinsert | echo 'test echo'
47 call assert_equal(116, screenchar(&lines - 1, 1))
48 call assert_equal(32, screenchar(&lines, 1))
49 redraw!
50
51 stopinsert | echomsg 'test echomsg'
52 call assert_equal(116, screenchar(&lines - 1, 1))
53 call assert_equal(32, screenchar(&lines, 1))
54 redraw!
55
56 set cmdheight&
Bram Moolenaar1e115362019-01-09 23:01:02 +010057endfunc
Bram Moolenaarb513d302018-12-02 14:55:08 +010058
59func Test_message_completion()
60 call feedkeys(":message \<C-A>\<C-B>\"\<CR>", 'tx')
61 call assert_equal('"message clear', @:)
62endfunc
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010063
64func Test_echomsg()
65 call assert_equal("\nhello", execute(':echomsg "hello"'))
66 call assert_equal("\n", execute(':echomsg ""'))
67 call assert_equal("\n12345", execute(':echomsg 12345'))
68 call assert_equal("\n[]", execute(':echomsg []'))
69 call assert_equal("\n[1, 2, 3]", execute(':echomsg [1, 2, 3]'))
Bram Moolenaardb950e42020-04-22 19:13:19 +020070 call assert_equal("\n[1, 2, []]", execute(':echomsg [1, 2, test_null_list()]'))
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010071 call assert_equal("\n{}", execute(':echomsg {}'))
72 call assert_equal("\n{'a': 1, 'b': 2}", execute(':echomsg {"a": 1, "b": 2}'))
Bram Moolenaar73e28dc2022-09-17 21:08:33 +010073 call assert_equal("\n1.23", execute(':echomsg 1.23'))
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010074 call assert_match("function('<lambda>\\d*')", execute(':echomsg {-> 1234}'))
75endfunc
76
77func Test_echoerr()
78 call test_ignore_error('IgNoRe')
79 call assert_equal("\nIgNoRe hello", execute(':echoerr "IgNoRe hello"'))
80 call assert_equal("\n12345 IgNoRe", execute(':echoerr 12345 "IgNoRe"'))
81 call assert_equal("\n[1, 2, 'IgNoRe']", execute(':echoerr [1, 2, "IgNoRe"]'))
82 call assert_equal("\n{'IgNoRe': 2, 'a': 1}", execute(':echoerr {"a": 1, "IgNoRe": 2}'))
Bram Moolenaar73e28dc2022-09-17 21:08:33 +010083 call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"'))
Bram Moolenaarce90e362019-09-08 18:58:44 +020084 eval '<lambda>'->test_ignore_error()
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010085 call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}'))
86 call test_ignore_error('RESET')
87endfunc
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +020088
89func Test_mode_message_at_leaving_insert_by_ctrl_c()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020090 CheckFeature terminal
91 CheckNotGui
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +020092
93 " Set custom statusline built by user-defined function.
94 let testfile = 'Xtest.vim'
Bram Moolenaare7eb9272019-06-24 00:58:07 +020095 let lines =<< trim END
96 func StatusLine() abort
97 return ""
98 endfunc
99 set statusline=%!StatusLine()
100 set laststatus=2
101 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100102 call writefile(lines, testfile, 'D')
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +0200103
104 let rows = 10
105 let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200106 call TermWait(buf, 100)
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +0200107 call assert_equal('run', job_status(term_getjob(buf)))
108
109 call term_sendkeys(buf, "i")
110 call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))})
111 call term_sendkeys(buf, "\<C-C>")
112 call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))})
113
114 call term_sendkeys(buf, ":qall!\<CR>")
115 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))})
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100116
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +0200117 exe buf . 'bwipe!'
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +0200118endfunc
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200119
120func Test_mode_message_at_leaving_insert_with_esc_mapped()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200121 CheckFeature terminal
122 CheckNotGui
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200123
124 " Set custom statusline built by user-defined function.
125 let testfile = 'Xtest.vim'
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200126 let lines =<< trim END
127 set laststatus=2
128 inoremap <Esc> <Esc>00
129 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100130 call writefile(lines, testfile, 'D')
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200131
132 let rows = 10
133 let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200134 call WaitForAssert({-> assert_match('0,0-1\s*All$', term_getline(buf, rows - 1))})
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200135 call assert_equal('run', job_status(term_getjob(buf)))
136
137 call term_sendkeys(buf, "i")
138 call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))})
139 call term_sendkeys(buf, "\<Esc>")
140 call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))})
141
142 call term_sendkeys(buf, ":qall!\<CR>")
143 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))})
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100144
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200145 exe buf . 'bwipe!'
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200146endfunc
Bram Moolenaar37f4cbd2019-08-23 20:58:45 +0200147
148func Test_echospace()
149 set noruler noshowcmd laststatus=1
150 call assert_equal(&columns - 1, v:echospace)
151 split
152 call assert_equal(&columns - 1, v:echospace)
153 set ruler
154 call assert_equal(&columns - 1, v:echospace)
155 close
156 call assert_equal(&columns - 19, v:echospace)
157 set showcmd noruler
158 call assert_equal(&columns - 12, v:echospace)
159 set showcmd ruler
160 call assert_equal(&columns - 29, v:echospace)
Sam-programs062141b2024-02-29 17:40:29 +0100161 set showcmdloc=statusline
162 call assert_equal(&columns - 19, v:echospace)
163 set showcmdloc=tabline
164 call assert_equal(&columns - 19, v:echospace)
zeertzjqc27fcf42024-03-01 23:01:43 +0100165 call assert_fails('set showcmdloc=leap', 'E474:')
166 call assert_equal(&columns - 19, v:echospace)
167 set showcmdloc=last
168 call assert_equal(&columns - 29, v:echospace)
169 call assert_fails('set showcmdloc=jump', 'E474:')
170 call assert_equal(&columns - 29, v:echospace)
Bram Moolenaar37f4cbd2019-08-23 20:58:45 +0200171
Sam-programs062141b2024-02-29 17:40:29 +0100172 set ruler& showcmd& showcmdloc&
Bram Moolenaar37f4cbd2019-08-23 20:58:45 +0200173endfunc
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100174
zeertzjqbdedd2b2022-09-20 12:45:15 +0100175func Test_warning_scroll()
176 CheckRunVimInTerminal
177 let lines =<< trim END
178 call test_override('ui_delay', 50)
179 set noruler
180 set readonly
181 undo
182 END
183 call writefile(lines, 'XTestWarningScroll', 'D')
184 let buf = RunVimInTerminal('', #{rows: 8})
185
186 " When the warning comes from a script, messages are scrolled so that the
187 " stacktrace is visible.
188 call term_sendkeys(buf, ":source XTestWarningScroll\n")
189 " only match the final colon in the line that shows the source
190 call WaitForAssert({-> assert_match(':$', term_getline(buf, 5))})
191 call WaitForAssert({-> assert_equal('line 4:W10: Warning: Changing a readonly file', term_getline(buf, 6))})
192 call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 7))})
193 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 8))})
194 call term_sendkeys(buf, "\n")
195
196 " When the warning does not come from a script, messages are not scrolled.
197 call term_sendkeys(buf, ":enew\n")
198 call term_sendkeys(buf, ":set readonly\n")
199 call term_sendkeys(buf, 'u')
200 call WaitForAssert({-> assert_equal('W10: Warning: Changing a readonly file', term_getline(buf, 8))})
201 call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 8))})
202
203 " clean up
204 call StopVimInTerminal(buf)
205endfunc
206
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100207" Test more-prompt (see :help more-prompt).
208func Test_message_more()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200209 CheckRunVimInTerminal
Christian Brabandt51d4d842024-12-06 17:26:25 +0100210
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100211 let buf = RunVimInTerminal('', {'rows': 6})
212 call term_sendkeys(buf, ":call setline(1, range(1, 100))\n")
213
zeertzjq46af7bc2022-07-28 12:34:09 +0100214 call term_sendkeys(buf, ":%pfoo\<C-H>\<C-H>\<C-H>#")
215 call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 6))})
216 call term_sendkeys(buf, "\n")
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100217 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))})
218 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
219
220 call term_sendkeys(buf, '?')
221 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))})
222 call WaitForAssert({-> assert_equal('-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit ', term_getline(buf, 6))})
223
224 " Down a line with j, <CR>, <NL> or <Down>.
225 call term_sendkeys(buf, "j")
226 call WaitForAssert({-> assert_equal(' 6 6', term_getline(buf, 5))})
227 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
228 call term_sendkeys(buf, "\<NL>")
229 call WaitForAssert({-> assert_equal(' 7 7', term_getline(buf, 5))})
230 call term_sendkeys(buf, "\<CR>")
231 call WaitForAssert({-> assert_equal(' 8 8', term_getline(buf, 5))})
232 call term_sendkeys(buf, "\<Down>")
233 call WaitForAssert({-> assert_equal(' 9 9', term_getline(buf, 5))})
234
235 " Down a screen with <Space>, f, or <PageDown>.
236 call term_sendkeys(buf, 'f')
237 call WaitForAssert({-> assert_equal(' 14 14', term_getline(buf, 5))})
238 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
239 call term_sendkeys(buf, ' ')
240 call WaitForAssert({-> assert_equal(' 19 19', term_getline(buf, 5))})
241 call term_sendkeys(buf, "\<PageDown>")
242 call WaitForAssert({-> assert_equal(' 24 24', term_getline(buf, 5))})
243
244 " Down a page (half a screen) with d.
245 call term_sendkeys(buf, 'd')
246 call WaitForAssert({-> assert_equal(' 27 27', term_getline(buf, 5))})
247
248 " Down all the way with 'G'.
249 call term_sendkeys(buf, 'G')
250 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
251 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
252
253 " Up a line k, <BS> or <Up>.
254 call term_sendkeys(buf, 'k')
255 call WaitForAssert({-> assert_equal(' 99 99', term_getline(buf, 5))})
256 call term_sendkeys(buf, "\<BS>")
257 call WaitForAssert({-> assert_equal(' 98 98', term_getline(buf, 5))})
258 call term_sendkeys(buf, "\<Up>")
259 call WaitForAssert({-> assert_equal(' 97 97', term_getline(buf, 5))})
260
261 " Up a screen with b or <PageUp>.
262 call term_sendkeys(buf, 'b')
263 call WaitForAssert({-> assert_equal(' 92 92', term_getline(buf, 5))})
264 call term_sendkeys(buf, "\<PageUp>")
265 call WaitForAssert({-> assert_equal(' 87 87', term_getline(buf, 5))})
266
267 " Up a page (half a screen) with u.
268 call term_sendkeys(buf, 'u')
269 call WaitForAssert({-> assert_equal(' 84 84', term_getline(buf, 5))})
270
271 " Up all the way with 'g'.
272 call term_sendkeys(buf, 'g')
zeertzjqecdc82e2022-07-25 19:50:57 +0100273 call WaitForAssert({-> assert_equal(' 4 4', term_getline(buf, 5))})
274 call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 1))})
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100275 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
276
277 " All the way down. Pressing f should do nothing but pressing
278 " space should end the more prompt.
279 call term_sendkeys(buf, 'G')
280 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
281 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
282 call term_sendkeys(buf, 'f')
283 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
284 call term_sendkeys(buf, ' ')
285 call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))})
286
287 " Pressing g< shows the previous command output.
288 call term_sendkeys(buf, 'g<')
289 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
290 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
291
zeertzjq46af7bc2022-07-28 12:34:09 +0100292 " A command line that doesn't print text is appended to scrollback,
293 " even if it invokes a nested command line.
294 call term_sendkeys(buf, ":\<C-R>=':'\<CR>:\<CR>g<")
295 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 4))})
296 call WaitForAssert({-> assert_equal(':::', term_getline(buf, 5))})
297 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
298
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100299 call term_sendkeys(buf, ":%p#\n")
300 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))})
301 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
302
303 " Stop command output with q, <Esc> or CTRL-C.
304 call term_sendkeys(buf, 'q')
305 call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))})
306
Bram Moolenaarf4fcedc2021-03-15 18:36:20 +0100307 " Execute a : command from the more prompt
308 call term_sendkeys(buf, ":%p#\n")
309 call term_wait(buf)
310 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
311 call term_sendkeys(buf, ":")
312 call term_wait(buf)
313 call WaitForAssert({-> assert_equal(':', term_getline(buf, 6))})
314 call term_sendkeys(buf, "echo 'Hello'\n")
315 call term_wait(buf)
316 call WaitForAssert({-> assert_equal('Hello ', term_getline(buf, 5))})
317
Bram Moolenaar43c60ed2020-02-02 15:55:19 +0100318 call StopVimInTerminal(buf)
319endfunc
320
Bram Moolenaar838b7462022-09-26 15:19:56 +0100321" Test more-prompt scrollback
322func Test_message_more_scrollback()
Drew Vogelea67ba72025-05-07 22:05:17 +0200323 CheckScreendump
Bram Moolenaar838b7462022-09-26 15:19:56 +0100324 CheckRunVimInTerminal
325
326 let lines =<< trim END
327 set t_ut=
328 hi Normal ctermfg=15 ctermbg=0
329 for i in range(100)
330 echo i
331 endfor
332 END
333 call writefile(lines, 'XmoreScrollback', 'D')
334 let buf = RunVimInTerminal('-S XmoreScrollback', {'rows': 10})
335 call VerifyScreenDump(buf, 'Test_more_scrollback_1', {})
336
337 call term_sendkeys(buf, 'f')
338 call TermWait(buf)
339 call term_sendkeys(buf, 'b')
340 call VerifyScreenDump(buf, 'Test_more_scrollback_2', {})
341
342 call term_sendkeys(buf, 'q')
343 call TermWait(buf)
344 call StopVimInTerminal(buf)
345endfunc
346
Bram Moolenaar800cdbb2023-06-15 16:40:02 +0100347func Test_message_not_cleared_after_mode()
Drew Vogelea67ba72025-05-07 22:05:17 +0200348 CheckScreendump
Bram Moolenaar800cdbb2023-06-15 16:40:02 +0100349 CheckRunVimInTerminal
350
351 let lines =<< trim END
352 nmap <silent> gx :call DebugSilent('normal')<CR>
353 vmap <silent> gx :call DebugSilent('visual')<CR>
354 function DebugSilent(arg)
355 echomsg "from DebugSilent" a:arg
356 endfunction
357 set showmode
358 set cmdheight=1
Bram Moolenaarda51ad52023-06-15 18:44:50 +0100359 call test_settime(1)
360 call setline(1, ['one', 'NoSuchFile', 'three'])
Bram Moolenaar800cdbb2023-06-15 16:40:02 +0100361 END
362 call writefile(lines, 'XmessageMode', 'D')
363 let buf = RunVimInTerminal('-S XmessageMode', {'rows': 10})
364
365 call term_sendkeys(buf, 'gx')
366 call TermWait(buf)
367 call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_1', {})
368
369 " removing the mode message used to also clear the intended message
370 call term_sendkeys(buf, 'vEgx')
371 call TermWait(buf)
372 call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_2', {})
373
Bram Moolenaarda51ad52023-06-15 18:44:50 +0100374 " removing the mode message used to also clear the error message
375 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
376 call term_sendkeys(buf, '2GvEgf')
377 call TermWait(buf)
378 call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_3', {})
379
Bram Moolenaar800cdbb2023-06-15 16:40:02 +0100380 call StopVimInTerminal(buf)
381endfunc
382
zeertzjqfce1fa52025-02-27 19:19:36 +0100383func Test_mode_cleared_after_silent_message()
Drew Vogelea67ba72025-05-07 22:05:17 +0200384 CheckScreendump
zeertzjqfce1fa52025-02-27 19:19:36 +0100385 CheckRunVimInTerminal
386
387 let lines =<< trim END
388 edit XsilentMessageMode.txt
389 call setline(1, 'foobar')
390 autocmd TextChanged * silent update
391 END
392 call writefile(lines, 'XsilentMessageMode', 'D')
393 let buf = RunVimInTerminal('-S XsilentMessageMode', {'rows': 10})
394
395 call term_sendkeys(buf, 'v')
396 call TermWait(buf)
397 call VerifyScreenDump(buf, 'Test_mode_cleared_after_silent_message_1', {})
398
399 call term_sendkeys(buf, 'd')
400 call TermWait(buf)
401 call VerifyScreenDump(buf, 'Test_mode_cleared_after_silent_message_2', {})
402
403 call StopVimInTerminal(buf)
404 call delete('XsilentMessageMode.txt')
405endfunc
406
Bram Moolenaar11901392022-09-26 19:50:44 +0100407" Test verbose message before echo command
408func Test_echo_verbose_system()
Drew Vogelea67ba72025-05-07 22:05:17 +0200409 CheckScreendump
Bram Moolenaar11901392022-09-26 19:50:44 +0100410 CheckRunVimInTerminal
Bram Moolenaarf8027672022-09-27 15:55:43 +0100411 CheckUnix " needs the "seq" command
Drew Vogelf0ed0e62025-02-11 21:36:33 +0100412 CheckNotMac " the macos TMPDIR is too long for snapshot testing
Bram Moolenaar11901392022-09-26 19:50:44 +0100413
414 let buf = RunVimInTerminal('', {'rows': 10})
415 call term_sendkeys(buf, ":4 verbose echo system('seq 20')\<CR>")
416 " Note that the screendump is filtered to remove the name of the temp file
417 call VerifyScreenDump(buf, 'Test_verbose_system_1', {})
418
419 " display a page and go back, results in exactly the same view
420 call term_sendkeys(buf, ' ')
Bram Moolenaar19cf5252022-11-27 14:39:31 +0000421 call TermWait(buf, 50)
Bram Moolenaar11901392022-09-26 19:50:44 +0100422 call term_sendkeys(buf, 'b')
423 call VerifyScreenDump(buf, 'Test_verbose_system_1', {})
424
425 " do the same with 'cmdheight' set to 2
426 call term_sendkeys(buf, 'q')
427 call TermWait(buf)
428 call term_sendkeys(buf, ":set ch=2\<CR>")
429 call TermWait(buf)
430 call term_sendkeys(buf, ":4 verbose echo system('seq 20')\<CR>")
431 call VerifyScreenDump(buf, 'Test_verbose_system_2', {})
432
433 call term_sendkeys(buf, ' ')
Bram Moolenaar19cf5252022-11-27 14:39:31 +0000434 call TermWait(buf, 50)
Bram Moolenaar11901392022-09-26 19:50:44 +0100435 call term_sendkeys(buf, 'b')
436 call VerifyScreenDump(buf, 'Test_verbose_system_2', {})
437
438 call term_sendkeys(buf, 'q')
439 call TermWait(buf)
440 call StopVimInTerminal(buf)
441endfunc
442
Bram Moolenaar838b7462022-09-26 15:19:56 +0100443
Bram Moolenaar43c60ed2020-02-02 15:55:19 +0100444func Test_ask_yesno()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200445 CheckRunVimInTerminal
Bram Moolenaar43c60ed2020-02-02 15:55:19 +0100446 let buf = RunVimInTerminal('', {'rows': 6})
447 call term_sendkeys(buf, ":call setline(1, range(1, 2))\n")
448
449 call term_sendkeys(buf, ":2,1s/^/n/\n")
450 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
451 call term_sendkeys(buf, "n")
452 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))})
453 call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))})
454
455 call term_sendkeys(buf, ":2,1s/^/Esc/\n")
456 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
457 call term_sendkeys(buf, "\<Esc>")
458 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))})
459 call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))})
460
461 call term_sendkeys(buf, ":2,1s/^/y/\n")
462 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
463 call term_sendkeys(buf, "y")
464 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?y *2,1 *All$', term_getline(buf, 6))})
465 call WaitForAssert({-> assert_equal('y1', term_getline(buf, 1))})
466 call WaitForAssert({-> assert_equal('y2', term_getline(buf, 2))})
467
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100468 call StopVimInTerminal(buf)
469endfunc
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100470
471func Test_null()
472 echom test_null_list()
473 echom test_null_dict()
474 echom test_null_blob()
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100475 echom test_null_string()
Bram Moolenaar92b83cc2020-04-25 15:24:44 +0200476 echom test_null_function()
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100477 echom test_null_partial()
Bram Moolenaarda292b02020-01-08 19:27:40 +0100478 if has('job')
479 echom test_null_job()
480 echom test_null_channel()
481 endif
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100482endfunc
Bram Moolenaar92b83cc2020-04-25 15:24:44 +0200483
Bram Moolenaarb42c0d52020-05-29 22:41:41 +0200484func Test_mapping_at_hit_return_prompt()
485 nnoremap <C-B> :echo "hit ctrl-b"<CR>
486 call feedkeys(":ls\<CR>", "xt")
Bram Moolenaarfccd93f2020-05-31 22:06:51 +0200487 call feedkeys("\<*C-B>", "xt")
Bram Moolenaarb42c0d52020-05-29 22:41:41 +0200488 call assert_match('hit ctrl-b', Screenline(&lines - 1))
489 nunmap <C-B>
490endfunc
491
Bram Moolenaar3d30af82020-10-13 22:15:56 +0200492func Test_quit_long_message()
493 CheckScreendump
494
495 let content =<< trim END
496 echom range(9999)->join("\x01")
497 END
Bram Moolenaar124af712022-09-25 18:44:03 +0100498 call writefile(content, 'Xtest_quit_message', 'D')
499 let buf = RunVimInTerminal('-S Xtest_quit_message', #{rows: 10, wait_for_ruler: 0})
500 call WaitForAssert({-> assert_match('^-- More --', term_getline(buf, 10))})
Bram Moolenaar3d30af82020-10-13 22:15:56 +0200501 call term_sendkeys(buf, "q")
502 call VerifyScreenDump(buf, 'Test_quit_long_message', {})
503
504 " clean up
505 call StopVimInTerminal(buf)
Bram Moolenaar3d30af82020-10-13 22:15:56 +0200506endfunc
507
Bram Moolenaar2de53712021-12-19 11:06:35 +0000508" this was missing a terminating NUL
509func Test_echo_string_partial()
510 function CountSpaces()
511 endfunction
Yegappan Lakshmananbc404bf2021-12-19 19:19:31 +0000512 call assert_equal("function('CountSpaces', [{'ccccccccccc': ['ab', 'cd'], 'aaaaaaaaaaa': v:false, 'bbbbbbbbbbbb': ''}])", string(function('CountSpaces', [#{aaaaaaaaaaa: v:false, bbbbbbbbbbbb: '', ccccccccccc: ['ab', 'cd']}])))
Bram Moolenaar2de53712021-12-19 11:06:35 +0000513endfunc
514
zeertzjq40ed6712023-11-23 20:37:01 +0100515" Test that fileinfo is shown properly when 'cmdheight' has just decreased
516" due to switching tabpage and 'shortmess' doesn't contain 'o' or 'O'.
517func Test_fileinfo_tabpage_cmdheight()
518 CheckRunVimInTerminal
519
520 let content =<< trim END
521 set shortmess-=o
522 set shortmess-=O
523 set shortmess-=F
524 tabnew
525 set cmdheight=2
526 tabprev
527 edit Xfileinfo.txt
528 END
529
530 call writefile(content, 'Xtest_fileinfo_tabpage_cmdheight', 'D')
531 let buf = RunVimInTerminal('-S Xtest_fileinfo_tabpage_cmdheight', #{rows: 6})
532 call WaitForAssert({-> assert_match('^"Xfileinfo.txt" \[New\]', term_getline(buf, 6))})
533
534 " clean up
535 call StopVimInTerminal(buf)
536endfunc
537
Rob Pilling726f7f92022-01-20 14:44:38 +0000538" Message output was previously overwritten by the fileinfo display, shown
539" when switching buffers. If a buffer is switched to, then a message if
540" echoed, we should show the message, rather than overwriting it with
541" fileinfo.
542func Test_fileinfo_after_echo()
543 CheckScreendump
544
545 let content =<< trim END
546 file a.txt
547
548 hide edit b.txt
549 call setline(1, "hi")
550 setlocal modified
551
552 hide buffer a.txt
553
Bram Moolenaar9323ca52022-03-16 11:14:57 +0000554 autocmd CursorHold * buf b.txt | w | echo "'b' written"
Rob Pilling726f7f92022-01-20 14:44:38 +0000555 END
556
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100557 call writefile(content, 'Xtest_fileinfo_after_echo', 'D')
Rob Pilling726f7f92022-01-20 14:44:38 +0000558 let buf = RunVimInTerminal('-S Xtest_fileinfo_after_echo', #{rows: 6})
Bram Moolenaar9323ca52022-03-16 11:14:57 +0000559 call term_sendkeys(buf, ":set updatetime=50\<CR>")
560 call term_sendkeys(buf, "0$")
Rob Pilling726f7f92022-01-20 14:44:38 +0000561 call VerifyScreenDump(buf, 'Test_fileinfo_after_echo', {})
562
563 call term_sendkeys(buf, ":q\<CR>")
564
565 " clean up
566 call StopVimInTerminal(buf)
Yegappan Lakshmanan7e765a32022-01-24 11:40:37 +0000567 call delete('b.txt')
Rob Pilling726f7f92022-01-20 14:44:38 +0000568endfunc
569
Bram Moolenaar37fef162022-08-29 18:16:32 +0100570func Test_echowindow()
571 CheckScreendump
572
573 let lines =<< trim END
574 call setline(1, 'some text')
575 func ShowMessage(arg)
576 echowindow a:arg
577 endfunc
578 echowindow 'first line'
Bram Moolenaarb5b4f612022-09-01 16:43:17 +0100579 func ManyMessages()
580 for n in range(20)
581 echowindow 'line' n
582 endfor
583 endfunc
Bram Moolenaarcf0995d2022-09-11 21:36:17 +0100584
585 def TwoMessages()
586 popup_clear()
587 set cmdheight=2
588 redraw
589 timer_start(100, (_) => {
590 echowin 'message'
591 })
592 echo 'one'
593 echo 'two'
594 enddef
595
596 def ThreeMessages()
597 popup_clear()
598 redraw
599 timer_start(100, (_) => {
600 echowin 'later message'
601 })
602 echo 'one'
603 echo 'two'
604 echo 'three'
605 enddef
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100606
607 def HideWin()
608 popup_hide(popup_findecho())
609 enddef
Bram Moolenaar37fef162022-08-29 18:16:32 +0100610 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100611 call writefile(lines, 'XtestEchowindow', 'D')
Bram Moolenaar37fef162022-08-29 18:16:32 +0100612 let buf = RunVimInTerminal('-S XtestEchowindow', #{rows: 8})
613 call VerifyScreenDump(buf, 'Test_echowindow_1', {})
614
615 call term_sendkeys(buf, ":call ShowMessage('second line')\<CR>")
616 call VerifyScreenDump(buf, 'Test_echowindow_2', {})
617
618 call term_sendkeys(buf, ":call popup_clear()\<CR>")
619 call VerifyScreenDump(buf, 'Test_echowindow_3', {})
620
Bram Moolenaarb5b4f612022-09-01 16:43:17 +0100621 call term_sendkeys(buf, ":call ManyMessages()\<CR>")
622 call VerifyScreenDump(buf, 'Test_echowindow_4', {})
623
Bram Moolenaarcf0995d2022-09-11 21:36:17 +0100624 call term_sendkeys(buf, ":call TwoMessages()\<CR>")
625 call VerifyScreenDump(buf, 'Test_echowindow_5', {})
626
627 call term_sendkeys(buf, ":call ThreeMessages()\<CR>")
628 sleep 120m
629 call VerifyScreenDump(buf, 'Test_echowindow_6', {})
630
631 call term_sendkeys(buf, "\<CR>")
632 call VerifyScreenDump(buf, 'Test_echowindow_7', {})
633
Bram Moolenaar45690202022-09-26 12:57:11 +0100634 call term_sendkeys(buf, ":tabnew\<CR>")
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100635 call term_sendkeys(buf, ":7echowin 'more'\<CR>")
Bram Moolenaar45690202022-09-26 12:57:11 +0100636 call VerifyScreenDump(buf, 'Test_echowindow_8', {})
637
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100638 call term_sendkeys(buf, ":call HideWin()\<CR>")
639 call VerifyScreenDump(buf, 'Test_echowindow_9', {})
640
Bram Moolenaar37fef162022-08-29 18:16:32 +0100641 " clean up
642 call StopVimInTerminal(buf)
Bram Moolenaar37fef162022-08-29 18:16:32 +0100643endfunc
644
Yasuhiro Matsumotoa02a8a42022-09-02 12:16:21 +0100645" messages window should not be used while evaluating the :echowin argument
646func Test_echowin_eval()
647 CheckScreendump
648
649 let lines =<< trim END
650 func ShowMessage()
651 echo 123
652 return 'test'
653 endfunc
654 echowindow ShowMessage()
655 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100656 call writefile(lines, 'XtestEchowindow', 'D')
Yasuhiro Matsumotoa02a8a42022-09-02 12:16:21 +0100657 let buf = RunVimInTerminal('-S XtestEchowindow', #{rows: 8})
658 call VerifyScreenDump(buf, 'Test_echowin_eval', {})
659
660 " clean up
661 call StopVimInTerminal(buf)
Yasuhiro Matsumotoa02a8a42022-09-02 12:16:21 +0100662endfunc
663
Bram Moolenaar7cf58392022-09-09 20:19:40 +0100664" messages window should not be used for showing the mode
665func Test_echowin_showmode()
666 CheckScreendump
667
668 let lines =<< trim END
669 vim9script
670 setline(1, ['one', 'two'])
671 timer_start(100, (_) => {
672 echowin 'echo window'
673 })
674 normal V
675 END
676 call writefile(lines, 'XtestEchowinMode', 'D')
677 let buf = RunVimInTerminal('-S XtestEchowinMode', #{rows: 8})
678 call VerifyScreenDump(buf, 'Test_echowin_showmode', {})
679
680 " clean up
681 call StopVimInTerminal(buf)
682endfunc
683
Christian Brabandt51d4d842024-12-06 17:26:25 +0100684func Test_messagesopt_history()
685 " After setting 'messagesopt' "history" to 2 and outputting a message 4 times
686 " with :echomsg, is the number of output lines of :messages 2?
687 set messagesopt=hit-enter,history:2
688 echomsg 'foo'
689 echomsg 'bar'
690 echomsg 'baz'
691 echomsg 'foobar'
692 call assert_equal(['baz', 'foobar'], GetMessages())
693
694 " When the number of messages is 10 and 'messagesopt' "history" is changed to
695 " 5, is the number of output lines of :messages 5?
696 set messagesopt=hit-enter,history:10
697 for num in range(1, 10)
698 echomsg num
699 endfor
700 set messagesopt=hit-enter,history:5
701 call assert_equal(5, len(GetMessages()))
702
703 " Check empty list
704 set messagesopt=hit-enter,history:0
705 call assert_true(empty(GetMessages()))
706
707 set messagesopt&
708endfunc
709
710func Test_messagesopt_wait()
711 CheckRunVimInTerminal
712
713 let buf = RunVimInTerminal('', {'rows': 6, 'cols': 45})
714 call term_sendkeys(buf, ":set cmdheight=1\n")
715
716 " Check hit-enter prompt
717 call term_sendkeys(buf, ":set messagesopt=hit-enter,history:500\n")
zeertzjq8cc43da2024-12-07 16:09:08 +0100718 call term_sendkeys(buf, ":echo 'foo' | echo 'bar' | echo 'baz'\n")
Christian Brabandt51d4d842024-12-06 17:26:25 +0100719 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
720
721 " Check no hit-enter prompt when "wait:" is set
722 call term_sendkeys(buf, ":set messagesopt=wait:100,history:500\n")
zeertzjq8cc43da2024-12-07 16:09:08 +0100723 call term_sendkeys(buf, ":echo 'foo' | echo 'bar' | echo 'baz'\n")
Christian Brabandt51d4d842024-12-06 17:26:25 +0100724 call WaitForAssert({-> assert_equal(' 0,0-1 All', term_getline(buf, 6))})
725
726 " clean up
727 call StopVimInTerminal(buf)
728endfunc
Bram Moolenaar43568642022-08-28 13:02:45 +0100729
Bram Moolenaar92b83cc2020-04-25 15:24:44 +0200730" vim: shiftwidth=2 sts=2 expandtab