blob: e1eab59ebac3b5b6c2dca9171b60e7c8b100768d [file] [log] [blame]
Bram Moolenaar461a7fc2018-12-22 13:28:07 +01001" Tests for :messages, :echomsg, :echoerr
Bram Moolenaar451f8492016-04-14 17:16:22 +02002
Bram Moolenaar494e9062020-05-31 21:28:02 +02003source check.vim
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +02004source shared.vim
Bram Moolenaarc6d539b2019-12-28 17:10:46 +01005source term_util.vim
Bram Moolenaarb42c0d52020-05-29 22:41:41 +02006source view_util.vim
Bram Moolenaar3d30af82020-10-13 22:15:56 +02007source screendump.vim
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +02008
Bram Moolenaar49b2fb32020-04-25 17:13:56 +02009func Test_messages()
Bram Moolenaar451f8492016-04-14 17:16:22 +020010 let oldmore = &more
11 try
12 set nomore
13
14 let arr = map(range(10), '"hello" . v:val')
15 for s in arr
16 echomsg s | redraw
17 endfor
Bram Moolenaar451f8492016-04-14 17:16:22 +020018
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020019 " get last two messages
Bram Moolenaar451f8492016-04-14 17:16:22 +020020 redir => result
21 2messages | redraw
22 redir END
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020023 let msg_list = split(result, "\n")
24 call assert_equal(["hello8", "hello9"], msg_list)
Bram Moolenaar451f8492016-04-14 17:16:22 +020025
26 " clear messages without last one
27 1messages clear
Bram Moolenaar49b2fb32020-04-25 17:13:56 +020028 let msg_list = GetMessages()
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020029 call assert_equal(['hello9'], msg_list)
Bram Moolenaar451f8492016-04-14 17:16:22 +020030
31 " clear all messages
32 messages clear
Bram Moolenaar49b2fb32020-04-25 17:13:56 +020033 let msg_list = GetMessages()
34 call assert_equal([], msg_list)
Bram Moolenaar451f8492016-04-14 17:16:22 +020035 finally
36 let &more = oldmore
37 endtry
Bram Moolenaar067297e2020-04-13 19:55:50 +020038
39 call assert_fails('message 1', 'E474:')
Bram Moolenaar49b2fb32020-04-25 17:13:56 +020040endfunc
Bram Moolenaar2abad542018-05-19 14:43:45 +020041
Bram Moolenaarf52f9ea2018-06-27 20:49:44 +020042" Patch 7.4.1696 defined the "clearmode()" function for clearing the mode
Bram Moolenaar2abad542018-05-19 14:43:45 +020043" indicator (e.g., "-- INSERT --") when ":stopinsert" is invoked. Message
44" output could then be disturbed when 'cmdheight' was greater than one.
45" This test ensures that the bugfix for this issue remains in place.
Bram Moolenaar1e115362019-01-09 23:01:02 +010046func Test_stopinsert_does_not_break_message_output()
Bram Moolenaar2abad542018-05-19 14:43:45 +020047 set cmdheight=2
48 redraw!
49
50 stopinsert | echo 'test echo'
51 call assert_equal(116, screenchar(&lines - 1, 1))
52 call assert_equal(32, screenchar(&lines, 1))
53 redraw!
54
55 stopinsert | echomsg 'test echomsg'
56 call assert_equal(116, screenchar(&lines - 1, 1))
57 call assert_equal(32, screenchar(&lines, 1))
58 redraw!
59
60 set cmdheight&
Bram Moolenaar1e115362019-01-09 23:01:02 +010061endfunc
Bram Moolenaarb513d302018-12-02 14:55:08 +010062
63func Test_message_completion()
64 call feedkeys(":message \<C-A>\<C-B>\"\<CR>", 'tx')
65 call assert_equal('"message clear', @:)
66endfunc
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010067
68func Test_echomsg()
69 call assert_equal("\nhello", execute(':echomsg "hello"'))
70 call assert_equal("\n", execute(':echomsg ""'))
71 call assert_equal("\n12345", execute(':echomsg 12345'))
72 call assert_equal("\n[]", execute(':echomsg []'))
73 call assert_equal("\n[1, 2, 3]", execute(':echomsg [1, 2, 3]'))
Bram Moolenaardb950e42020-04-22 19:13:19 +020074 call assert_equal("\n[1, 2, []]", execute(':echomsg [1, 2, test_null_list()]'))
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010075 call assert_equal("\n{}", execute(':echomsg {}'))
76 call assert_equal("\n{'a': 1, 'b': 2}", execute(':echomsg {"a": 1, "b": 2}'))
Bram Moolenaar73e28dc2022-09-17 21:08:33 +010077 call assert_equal("\n1.23", execute(':echomsg 1.23'))
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010078 call assert_match("function('<lambda>\\d*')", execute(':echomsg {-> 1234}'))
79endfunc
80
81func Test_echoerr()
82 call test_ignore_error('IgNoRe')
83 call assert_equal("\nIgNoRe hello", execute(':echoerr "IgNoRe hello"'))
84 call assert_equal("\n12345 IgNoRe", execute(':echoerr 12345 "IgNoRe"'))
85 call assert_equal("\n[1, 2, 'IgNoRe']", execute(':echoerr [1, 2, "IgNoRe"]'))
86 call assert_equal("\n{'IgNoRe': 2, 'a': 1}", execute(':echoerr {"a": 1, "IgNoRe": 2}'))
Bram Moolenaar73e28dc2022-09-17 21:08:33 +010087 call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"'))
Bram Moolenaarce90e362019-09-08 18:58:44 +020088 eval '<lambda>'->test_ignore_error()
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010089 call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}'))
90 call test_ignore_error('RESET')
91endfunc
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +020092
93func Test_mode_message_at_leaving_insert_by_ctrl_c()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020094 CheckFeature terminal
95 CheckNotGui
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +020096
97 " Set custom statusline built by user-defined function.
98 let testfile = 'Xtest.vim'
Bram Moolenaare7eb9272019-06-24 00:58:07 +020099 let lines =<< trim END
100 func StatusLine() abort
101 return ""
102 endfunc
103 set statusline=%!StatusLine()
104 set laststatus=2
105 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100106 call writefile(lines, testfile, 'D')
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +0200107
108 let rows = 10
109 let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200110 call TermWait(buf, 100)
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +0200111 call assert_equal('run', job_status(term_getjob(buf)))
112
113 call term_sendkeys(buf, "i")
114 call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))})
115 call term_sendkeys(buf, "\<C-C>")
116 call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))})
117
118 call term_sendkeys(buf, ":qall!\<CR>")
119 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))})
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100120
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +0200121 exe buf . 'bwipe!'
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +0200122endfunc
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200123
124func Test_mode_message_at_leaving_insert_with_esc_mapped()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200125 CheckFeature terminal
126 CheckNotGui
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200127
128 " Set custom statusline built by user-defined function.
129 let testfile = 'Xtest.vim'
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200130 let lines =<< trim END
131 set laststatus=2
132 inoremap <Esc> <Esc>00
133 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100134 call writefile(lines, testfile, 'D')
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200135
136 let rows = 10
137 let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200138 call WaitForAssert({-> assert_match('0,0-1\s*All$', term_getline(buf, rows - 1))})
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200139 call assert_equal('run', job_status(term_getjob(buf)))
140
141 call term_sendkeys(buf, "i")
142 call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))})
143 call term_sendkeys(buf, "\<Esc>")
144 call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))})
145
146 call term_sendkeys(buf, ":qall!\<CR>")
147 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))})
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100148
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200149 exe buf . 'bwipe!'
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200150endfunc
Bram Moolenaar37f4cbd2019-08-23 20:58:45 +0200151
152func Test_echospace()
153 set noruler noshowcmd laststatus=1
154 call assert_equal(&columns - 1, v:echospace)
155 split
156 call assert_equal(&columns - 1, v:echospace)
157 set ruler
158 call assert_equal(&columns - 1, v:echospace)
159 close
160 call assert_equal(&columns - 19, v:echospace)
161 set showcmd noruler
162 call assert_equal(&columns - 12, v:echospace)
163 set showcmd ruler
164 call assert_equal(&columns - 29, v:echospace)
Sam-programs062141b2024-02-29 17:40:29 +0100165 set showcmdloc=statusline
166 call assert_equal(&columns - 19, v:echospace)
167 set showcmdloc=tabline
168 call assert_equal(&columns - 19, v:echospace)
zeertzjqc27fcf42024-03-01 23:01:43 +0100169 call assert_fails('set showcmdloc=leap', 'E474:')
170 call assert_equal(&columns - 19, v:echospace)
171 set showcmdloc=last
172 call assert_equal(&columns - 29, v:echospace)
173 call assert_fails('set showcmdloc=jump', 'E474:')
174 call assert_equal(&columns - 29, v:echospace)
Bram Moolenaar37f4cbd2019-08-23 20:58:45 +0200175
Sam-programs062141b2024-02-29 17:40:29 +0100176 set ruler& showcmd& showcmdloc&
Bram Moolenaar37f4cbd2019-08-23 20:58:45 +0200177endfunc
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100178
zeertzjqbdedd2b2022-09-20 12:45:15 +0100179func Test_warning_scroll()
180 CheckRunVimInTerminal
181 let lines =<< trim END
182 call test_override('ui_delay', 50)
183 set noruler
184 set readonly
185 undo
186 END
187 call writefile(lines, 'XTestWarningScroll', 'D')
188 let buf = RunVimInTerminal('', #{rows: 8})
189
190 " When the warning comes from a script, messages are scrolled so that the
191 " stacktrace is visible.
192 call term_sendkeys(buf, ":source XTestWarningScroll\n")
193 " only match the final colon in the line that shows the source
194 call WaitForAssert({-> assert_match(':$', term_getline(buf, 5))})
195 call WaitForAssert({-> assert_equal('line 4:W10: Warning: Changing a readonly file', term_getline(buf, 6))})
196 call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 7))})
197 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 8))})
198 call term_sendkeys(buf, "\n")
199
200 " When the warning does not come from a script, messages are not scrolled.
201 call term_sendkeys(buf, ":enew\n")
202 call term_sendkeys(buf, ":set readonly\n")
203 call term_sendkeys(buf, 'u')
204 call WaitForAssert({-> assert_equal('W10: Warning: Changing a readonly file', term_getline(buf, 8))})
205 call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 8))})
206
207 " clean up
208 call StopVimInTerminal(buf)
209endfunc
210
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100211" Test more-prompt (see :help more-prompt).
212func Test_message_more()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200213 CheckRunVimInTerminal
Christian Brabandt51d4d842024-12-06 17:26:25 +0100214
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100215 let buf = RunVimInTerminal('', {'rows': 6})
216 call term_sendkeys(buf, ":call setline(1, range(1, 100))\n")
217
zeertzjq46af7bc2022-07-28 12:34:09 +0100218 call term_sendkeys(buf, ":%pfoo\<C-H>\<C-H>\<C-H>#")
219 call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 6))})
220 call term_sendkeys(buf, "\n")
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100221 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))})
222 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
223
224 call term_sendkeys(buf, '?')
225 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))})
226 call WaitForAssert({-> assert_equal('-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit ', term_getline(buf, 6))})
227
228 " Down a line with j, <CR>, <NL> or <Down>.
229 call term_sendkeys(buf, "j")
230 call WaitForAssert({-> assert_equal(' 6 6', term_getline(buf, 5))})
231 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
232 call term_sendkeys(buf, "\<NL>")
233 call WaitForAssert({-> assert_equal(' 7 7', term_getline(buf, 5))})
234 call term_sendkeys(buf, "\<CR>")
235 call WaitForAssert({-> assert_equal(' 8 8', term_getline(buf, 5))})
236 call term_sendkeys(buf, "\<Down>")
237 call WaitForAssert({-> assert_equal(' 9 9', term_getline(buf, 5))})
238
239 " Down a screen with <Space>, f, or <PageDown>.
240 call term_sendkeys(buf, 'f')
241 call WaitForAssert({-> assert_equal(' 14 14', term_getline(buf, 5))})
242 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
243 call term_sendkeys(buf, ' ')
244 call WaitForAssert({-> assert_equal(' 19 19', term_getline(buf, 5))})
245 call term_sendkeys(buf, "\<PageDown>")
246 call WaitForAssert({-> assert_equal(' 24 24', term_getline(buf, 5))})
247
248 " Down a page (half a screen) with d.
249 call term_sendkeys(buf, 'd')
250 call WaitForAssert({-> assert_equal(' 27 27', term_getline(buf, 5))})
251
252 " Down all the way with 'G'.
253 call term_sendkeys(buf, 'G')
254 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
255 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
256
257 " Up a line k, <BS> or <Up>.
258 call term_sendkeys(buf, 'k')
259 call WaitForAssert({-> assert_equal(' 99 99', term_getline(buf, 5))})
260 call term_sendkeys(buf, "\<BS>")
261 call WaitForAssert({-> assert_equal(' 98 98', term_getline(buf, 5))})
262 call term_sendkeys(buf, "\<Up>")
263 call WaitForAssert({-> assert_equal(' 97 97', term_getline(buf, 5))})
264
265 " Up a screen with b or <PageUp>.
266 call term_sendkeys(buf, 'b')
267 call WaitForAssert({-> assert_equal(' 92 92', term_getline(buf, 5))})
268 call term_sendkeys(buf, "\<PageUp>")
269 call WaitForAssert({-> assert_equal(' 87 87', term_getline(buf, 5))})
270
271 " Up a page (half a screen) with u.
272 call term_sendkeys(buf, 'u')
273 call WaitForAssert({-> assert_equal(' 84 84', term_getline(buf, 5))})
274
275 " Up all the way with 'g'.
276 call term_sendkeys(buf, 'g')
zeertzjqecdc82e2022-07-25 19:50:57 +0100277 call WaitForAssert({-> assert_equal(' 4 4', term_getline(buf, 5))})
278 call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 1))})
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100279 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
280
281 " All the way down. Pressing f should do nothing but pressing
282 " space should end the more prompt.
283 call term_sendkeys(buf, 'G')
284 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
285 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
286 call term_sendkeys(buf, 'f')
287 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
288 call term_sendkeys(buf, ' ')
289 call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))})
290
291 " Pressing g< shows the previous command output.
292 call term_sendkeys(buf, 'g<')
293 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
294 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
295
zeertzjq46af7bc2022-07-28 12:34:09 +0100296 " A command line that doesn't print text is appended to scrollback,
297 " even if it invokes a nested command line.
298 call term_sendkeys(buf, ":\<C-R>=':'\<CR>:\<CR>g<")
299 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 4))})
300 call WaitForAssert({-> assert_equal(':::', term_getline(buf, 5))})
301 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
302
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100303 call term_sendkeys(buf, ":%p#\n")
304 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))})
305 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
306
307 " Stop command output with q, <Esc> or CTRL-C.
308 call term_sendkeys(buf, 'q')
309 call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))})
310
Bram Moolenaarf4fcedc2021-03-15 18:36:20 +0100311 " Execute a : command from the more prompt
312 call term_sendkeys(buf, ":%p#\n")
313 call term_wait(buf)
314 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
315 call term_sendkeys(buf, ":")
316 call term_wait(buf)
317 call WaitForAssert({-> assert_equal(':', term_getline(buf, 6))})
318 call term_sendkeys(buf, "echo 'Hello'\n")
319 call term_wait(buf)
320 call WaitForAssert({-> assert_equal('Hello ', term_getline(buf, 5))})
321
Bram Moolenaar43c60ed2020-02-02 15:55:19 +0100322 call StopVimInTerminal(buf)
323endfunc
324
Bram Moolenaar838b7462022-09-26 15:19:56 +0100325" Test more-prompt scrollback
326func Test_message_more_scrollback()
Drew Vogelea67ba72025-05-07 22:05:17 +0200327 CheckScreendump
Bram Moolenaar838b7462022-09-26 15:19:56 +0100328 CheckRunVimInTerminal
329
330 let lines =<< trim END
331 set t_ut=
332 hi Normal ctermfg=15 ctermbg=0
333 for i in range(100)
334 echo i
335 endfor
336 END
337 call writefile(lines, 'XmoreScrollback', 'D')
338 let buf = RunVimInTerminal('-S XmoreScrollback', {'rows': 10})
339 call VerifyScreenDump(buf, 'Test_more_scrollback_1', {})
340
341 call term_sendkeys(buf, 'f')
342 call TermWait(buf)
343 call term_sendkeys(buf, 'b')
344 call VerifyScreenDump(buf, 'Test_more_scrollback_2', {})
345
346 call term_sendkeys(buf, 'q')
347 call TermWait(buf)
348 call StopVimInTerminal(buf)
349endfunc
350
Bram Moolenaar800cdbb2023-06-15 16:40:02 +0100351func Test_message_not_cleared_after_mode()
Drew Vogelea67ba72025-05-07 22:05:17 +0200352 CheckScreendump
Bram Moolenaar800cdbb2023-06-15 16:40:02 +0100353 CheckRunVimInTerminal
354
355 let lines =<< trim END
356 nmap <silent> gx :call DebugSilent('normal')<CR>
357 vmap <silent> gx :call DebugSilent('visual')<CR>
358 function DebugSilent(arg)
359 echomsg "from DebugSilent" a:arg
360 endfunction
361 set showmode
362 set cmdheight=1
Bram Moolenaarda51ad52023-06-15 18:44:50 +0100363 call test_settime(1)
364 call setline(1, ['one', 'NoSuchFile', 'three'])
Bram Moolenaar800cdbb2023-06-15 16:40:02 +0100365 END
366 call writefile(lines, 'XmessageMode', 'D')
367 let buf = RunVimInTerminal('-S XmessageMode', {'rows': 10})
368
369 call term_sendkeys(buf, 'gx')
370 call TermWait(buf)
371 call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_1', {})
372
373 " removing the mode message used to also clear the intended message
374 call term_sendkeys(buf, 'vEgx')
375 call TermWait(buf)
376 call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_2', {})
377
Bram Moolenaarda51ad52023-06-15 18:44:50 +0100378 " removing the mode message used to also clear the error message
379 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
380 call term_sendkeys(buf, '2GvEgf')
381 call TermWait(buf)
382 call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_3', {})
383
Bram Moolenaar800cdbb2023-06-15 16:40:02 +0100384 call StopVimInTerminal(buf)
385endfunc
386
zeertzjqfce1fa52025-02-27 19:19:36 +0100387func Test_mode_cleared_after_silent_message()
Drew Vogelea67ba72025-05-07 22:05:17 +0200388 CheckScreendump
zeertzjqfce1fa52025-02-27 19:19:36 +0100389 CheckRunVimInTerminal
390
391 let lines =<< trim END
392 edit XsilentMessageMode.txt
393 call setline(1, 'foobar')
394 autocmd TextChanged * silent update
395 END
396 call writefile(lines, 'XsilentMessageMode', 'D')
397 let buf = RunVimInTerminal('-S XsilentMessageMode', {'rows': 10})
398
399 call term_sendkeys(buf, 'v')
400 call TermWait(buf)
401 call VerifyScreenDump(buf, 'Test_mode_cleared_after_silent_message_1', {})
402
403 call term_sendkeys(buf, 'd')
404 call TermWait(buf)
405 call VerifyScreenDump(buf, 'Test_mode_cleared_after_silent_message_2', {})
406
407 call StopVimInTerminal(buf)
408 call delete('XsilentMessageMode.txt')
409endfunc
410
Bram Moolenaar11901392022-09-26 19:50:44 +0100411" Test verbose message before echo command
412func Test_echo_verbose_system()
Drew Vogelea67ba72025-05-07 22:05:17 +0200413 CheckScreendump
Bram Moolenaar11901392022-09-26 19:50:44 +0100414 CheckRunVimInTerminal
Bram Moolenaarf8027672022-09-27 15:55:43 +0100415 CheckUnix " needs the "seq" command
Drew Vogelf0ed0e62025-02-11 21:36:33 +0100416 CheckNotMac " the macos TMPDIR is too long for snapshot testing
Bram Moolenaar11901392022-09-26 19:50:44 +0100417
418 let buf = RunVimInTerminal('', {'rows': 10})
419 call term_sendkeys(buf, ":4 verbose echo system('seq 20')\<CR>")
420 " Note that the screendump is filtered to remove the name of the temp file
421 call VerifyScreenDump(buf, 'Test_verbose_system_1', {})
422
423 " display a page and go back, results in exactly the same view
424 call term_sendkeys(buf, ' ')
Bram Moolenaar19cf5252022-11-27 14:39:31 +0000425 call TermWait(buf, 50)
Bram Moolenaar11901392022-09-26 19:50:44 +0100426 call term_sendkeys(buf, 'b')
427 call VerifyScreenDump(buf, 'Test_verbose_system_1', {})
428
429 " do the same with 'cmdheight' set to 2
430 call term_sendkeys(buf, 'q')
431 call TermWait(buf)
432 call term_sendkeys(buf, ":set ch=2\<CR>")
433 call TermWait(buf)
434 call term_sendkeys(buf, ":4 verbose echo system('seq 20')\<CR>")
435 call VerifyScreenDump(buf, 'Test_verbose_system_2', {})
436
437 call term_sendkeys(buf, ' ')
Bram Moolenaar19cf5252022-11-27 14:39:31 +0000438 call TermWait(buf, 50)
Bram Moolenaar11901392022-09-26 19:50:44 +0100439 call term_sendkeys(buf, 'b')
440 call VerifyScreenDump(buf, 'Test_verbose_system_2', {})
441
442 call term_sendkeys(buf, 'q')
443 call TermWait(buf)
444 call StopVimInTerminal(buf)
445endfunc
446
Bram Moolenaar838b7462022-09-26 15:19:56 +0100447
Bram Moolenaar43c60ed2020-02-02 15:55:19 +0100448func Test_ask_yesno()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200449 CheckRunVimInTerminal
Bram Moolenaar43c60ed2020-02-02 15:55:19 +0100450 let buf = RunVimInTerminal('', {'rows': 6})
451 call term_sendkeys(buf, ":call setline(1, range(1, 2))\n")
452
453 call term_sendkeys(buf, ":2,1s/^/n/\n")
454 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
455 call term_sendkeys(buf, "n")
456 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))})
457 call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))})
458
459 call term_sendkeys(buf, ":2,1s/^/Esc/\n")
460 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
461 call term_sendkeys(buf, "\<Esc>")
462 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))})
463 call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))})
464
465 call term_sendkeys(buf, ":2,1s/^/y/\n")
466 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
467 call term_sendkeys(buf, "y")
468 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?y *2,1 *All$', term_getline(buf, 6))})
469 call WaitForAssert({-> assert_equal('y1', term_getline(buf, 1))})
470 call WaitForAssert({-> assert_equal('y2', term_getline(buf, 2))})
471
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100472 call StopVimInTerminal(buf)
473endfunc
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100474
475func Test_null()
476 echom test_null_list()
477 echom test_null_dict()
478 echom test_null_blob()
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100479 echom test_null_string()
Bram Moolenaar92b83cc2020-04-25 15:24:44 +0200480 echom test_null_function()
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100481 echom test_null_partial()
Bram Moolenaarda292b02020-01-08 19:27:40 +0100482 if has('job')
483 echom test_null_job()
484 echom test_null_channel()
485 endif
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100486endfunc
Bram Moolenaar92b83cc2020-04-25 15:24:44 +0200487
Bram Moolenaarb42c0d52020-05-29 22:41:41 +0200488func Test_mapping_at_hit_return_prompt()
489 nnoremap <C-B> :echo "hit ctrl-b"<CR>
490 call feedkeys(":ls\<CR>", "xt")
Bram Moolenaarfccd93f2020-05-31 22:06:51 +0200491 call feedkeys("\<*C-B>", "xt")
Bram Moolenaarb42c0d52020-05-29 22:41:41 +0200492 call assert_match('hit ctrl-b', Screenline(&lines - 1))
493 nunmap <C-B>
494endfunc
495
Bram Moolenaar3d30af82020-10-13 22:15:56 +0200496func Test_quit_long_message()
497 CheckScreendump
498
499 let content =<< trim END
500 echom range(9999)->join("\x01")
501 END
Bram Moolenaar124af712022-09-25 18:44:03 +0100502 call writefile(content, 'Xtest_quit_message', 'D')
503 let buf = RunVimInTerminal('-S Xtest_quit_message', #{rows: 10, wait_for_ruler: 0})
504 call WaitForAssert({-> assert_match('^-- More --', term_getline(buf, 10))})
Bram Moolenaar3d30af82020-10-13 22:15:56 +0200505 call term_sendkeys(buf, "q")
506 call VerifyScreenDump(buf, 'Test_quit_long_message', {})
507
508 " clean up
509 call StopVimInTerminal(buf)
Bram Moolenaar3d30af82020-10-13 22:15:56 +0200510endfunc
511
Bram Moolenaar2de53712021-12-19 11:06:35 +0000512" this was missing a terminating NUL
513func Test_echo_string_partial()
514 function CountSpaces()
515 endfunction
Yegappan Lakshmananbc404bf2021-12-19 19:19:31 +0000516 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 +0000517endfunc
518
zeertzjq40ed6712023-11-23 20:37:01 +0100519" Test that fileinfo is shown properly when 'cmdheight' has just decreased
520" due to switching tabpage and 'shortmess' doesn't contain 'o' or 'O'.
521func Test_fileinfo_tabpage_cmdheight()
522 CheckRunVimInTerminal
523
524 let content =<< trim END
525 set shortmess-=o
526 set shortmess-=O
527 set shortmess-=F
528 tabnew
529 set cmdheight=2
530 tabprev
531 edit Xfileinfo.txt
532 END
533
534 call writefile(content, 'Xtest_fileinfo_tabpage_cmdheight', 'D')
535 let buf = RunVimInTerminal('-S Xtest_fileinfo_tabpage_cmdheight', #{rows: 6})
536 call WaitForAssert({-> assert_match('^"Xfileinfo.txt" \[New\]', term_getline(buf, 6))})
537
538 " clean up
539 call StopVimInTerminal(buf)
540endfunc
541
Rob Pilling726f7f92022-01-20 14:44:38 +0000542" Message output was previously overwritten by the fileinfo display, shown
543" when switching buffers. If a buffer is switched to, then a message if
544" echoed, we should show the message, rather than overwriting it with
545" fileinfo.
546func Test_fileinfo_after_echo()
547 CheckScreendump
548
549 let content =<< trim END
550 file a.txt
551
552 hide edit b.txt
553 call setline(1, "hi")
554 setlocal modified
555
556 hide buffer a.txt
557
Bram Moolenaar9323ca52022-03-16 11:14:57 +0000558 autocmd CursorHold * buf b.txt | w | echo "'b' written"
Rob Pilling726f7f92022-01-20 14:44:38 +0000559 END
560
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100561 call writefile(content, 'Xtest_fileinfo_after_echo', 'D')
Rob Pilling726f7f92022-01-20 14:44:38 +0000562 let buf = RunVimInTerminal('-S Xtest_fileinfo_after_echo', #{rows: 6})
Bram Moolenaar9323ca52022-03-16 11:14:57 +0000563 call term_sendkeys(buf, ":set updatetime=50\<CR>")
564 call term_sendkeys(buf, "0$")
Rob Pilling726f7f92022-01-20 14:44:38 +0000565 call VerifyScreenDump(buf, 'Test_fileinfo_after_echo', {})
566
567 call term_sendkeys(buf, ":q\<CR>")
568
569 " clean up
570 call StopVimInTerminal(buf)
Yegappan Lakshmanan7e765a32022-01-24 11:40:37 +0000571 call delete('b.txt')
Rob Pilling726f7f92022-01-20 14:44:38 +0000572endfunc
573
Bram Moolenaar37fef162022-08-29 18:16:32 +0100574func Test_echowindow()
575 CheckScreendump
576
577 let lines =<< trim END
578 call setline(1, 'some text')
579 func ShowMessage(arg)
580 echowindow a:arg
581 endfunc
582 echowindow 'first line'
Bram Moolenaarb5b4f612022-09-01 16:43:17 +0100583 func ManyMessages()
584 for n in range(20)
585 echowindow 'line' n
586 endfor
587 endfunc
Bram Moolenaarcf0995d2022-09-11 21:36:17 +0100588
589 def TwoMessages()
590 popup_clear()
591 set cmdheight=2
592 redraw
593 timer_start(100, (_) => {
594 echowin 'message'
595 })
596 echo 'one'
597 echo 'two'
598 enddef
599
600 def ThreeMessages()
601 popup_clear()
602 redraw
603 timer_start(100, (_) => {
604 echowin 'later message'
605 })
606 echo 'one'
607 echo 'two'
608 echo 'three'
609 enddef
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100610
611 def HideWin()
612 popup_hide(popup_findecho())
613 enddef
Bram Moolenaar37fef162022-08-29 18:16:32 +0100614 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100615 call writefile(lines, 'XtestEchowindow', 'D')
Bram Moolenaar37fef162022-08-29 18:16:32 +0100616 let buf = RunVimInTerminal('-S XtestEchowindow', #{rows: 8})
617 call VerifyScreenDump(buf, 'Test_echowindow_1', {})
618
619 call term_sendkeys(buf, ":call ShowMessage('second line')\<CR>")
620 call VerifyScreenDump(buf, 'Test_echowindow_2', {})
621
622 call term_sendkeys(buf, ":call popup_clear()\<CR>")
623 call VerifyScreenDump(buf, 'Test_echowindow_3', {})
624
Bram Moolenaarb5b4f612022-09-01 16:43:17 +0100625 call term_sendkeys(buf, ":call ManyMessages()\<CR>")
626 call VerifyScreenDump(buf, 'Test_echowindow_4', {})
627
Bram Moolenaarcf0995d2022-09-11 21:36:17 +0100628 call term_sendkeys(buf, ":call TwoMessages()\<CR>")
629 call VerifyScreenDump(buf, 'Test_echowindow_5', {})
630
631 call term_sendkeys(buf, ":call ThreeMessages()\<CR>")
632 sleep 120m
633 call VerifyScreenDump(buf, 'Test_echowindow_6', {})
634
635 call term_sendkeys(buf, "\<CR>")
636 call VerifyScreenDump(buf, 'Test_echowindow_7', {})
637
Bram Moolenaar45690202022-09-26 12:57:11 +0100638 call term_sendkeys(buf, ":tabnew\<CR>")
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100639 call term_sendkeys(buf, ":7echowin 'more'\<CR>")
Bram Moolenaar45690202022-09-26 12:57:11 +0100640 call VerifyScreenDump(buf, 'Test_echowindow_8', {})
641
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100642 call term_sendkeys(buf, ":call HideWin()\<CR>")
643 call VerifyScreenDump(buf, 'Test_echowindow_9', {})
644
Bram Moolenaar37fef162022-08-29 18:16:32 +0100645 " clean up
646 call StopVimInTerminal(buf)
Bram Moolenaar37fef162022-08-29 18:16:32 +0100647endfunc
648
Yasuhiro Matsumotoa02a8a42022-09-02 12:16:21 +0100649" messages window should not be used while evaluating the :echowin argument
650func Test_echowin_eval()
651 CheckScreendump
652
653 let lines =<< trim END
654 func ShowMessage()
655 echo 123
656 return 'test'
657 endfunc
658 echowindow ShowMessage()
659 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100660 call writefile(lines, 'XtestEchowindow', 'D')
Yasuhiro Matsumotoa02a8a42022-09-02 12:16:21 +0100661 let buf = RunVimInTerminal('-S XtestEchowindow', #{rows: 8})
662 call VerifyScreenDump(buf, 'Test_echowin_eval', {})
663
664 " clean up
665 call StopVimInTerminal(buf)
Yasuhiro Matsumotoa02a8a42022-09-02 12:16:21 +0100666endfunc
667
Bram Moolenaar7cf58392022-09-09 20:19:40 +0100668" messages window should not be used for showing the mode
669func Test_echowin_showmode()
670 CheckScreendump
671
672 let lines =<< trim END
673 vim9script
674 setline(1, ['one', 'two'])
675 timer_start(100, (_) => {
676 echowin 'echo window'
677 })
678 normal V
679 END
680 call writefile(lines, 'XtestEchowinMode', 'D')
681 let buf = RunVimInTerminal('-S XtestEchowinMode', #{rows: 8})
682 call VerifyScreenDump(buf, 'Test_echowin_showmode', {})
683
684 " clean up
685 call StopVimInTerminal(buf)
686endfunc
687
Christian Brabandt51d4d842024-12-06 17:26:25 +0100688func Test_messagesopt_history()
689 " After setting 'messagesopt' "history" to 2 and outputting a message 4 times
690 " with :echomsg, is the number of output lines of :messages 2?
691 set messagesopt=hit-enter,history:2
692 echomsg 'foo'
693 echomsg 'bar'
694 echomsg 'baz'
695 echomsg 'foobar'
696 call assert_equal(['baz', 'foobar'], GetMessages())
697
698 " When the number of messages is 10 and 'messagesopt' "history" is changed to
699 " 5, is the number of output lines of :messages 5?
700 set messagesopt=hit-enter,history:10
701 for num in range(1, 10)
702 echomsg num
703 endfor
704 set messagesopt=hit-enter,history:5
705 call assert_equal(5, len(GetMessages()))
706
707 " Check empty list
708 set messagesopt=hit-enter,history:0
709 call assert_true(empty(GetMessages()))
710
711 set messagesopt&
712endfunc
713
714func Test_messagesopt_wait()
715 CheckRunVimInTerminal
716
717 let buf = RunVimInTerminal('', {'rows': 6, 'cols': 45})
718 call term_sendkeys(buf, ":set cmdheight=1\n")
719
720 " Check hit-enter prompt
721 call term_sendkeys(buf, ":set messagesopt=hit-enter,history:500\n")
zeertzjq8cc43da2024-12-07 16:09:08 +0100722 call term_sendkeys(buf, ":echo 'foo' | echo 'bar' | echo 'baz'\n")
Christian Brabandt51d4d842024-12-06 17:26:25 +0100723 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
724
725 " Check no hit-enter prompt when "wait:" is set
726 call term_sendkeys(buf, ":set messagesopt=wait:100,history:500\n")
zeertzjq8cc43da2024-12-07 16:09:08 +0100727 call term_sendkeys(buf, ":echo 'foo' | echo 'bar' | echo 'baz'\n")
Christian Brabandt51d4d842024-12-06 17:26:25 +0100728 call WaitForAssert({-> assert_equal(' 0,0-1 All', term_getline(buf, 6))})
729
730 " clean up
731 call StopVimInTerminal(buf)
732endfunc
Bram Moolenaar43568642022-08-28 13:02:45 +0100733
Bram Moolenaar92b83cc2020-04-25 15:24:44 +0200734" vim: shiftwidth=2 sts=2 expandtab