blob: c16e4ae27de3b22a17bf831c2969f3a063b37b77 [file] [log] [blame]
Bram Moolenaar66459b72016-08-06 19:01:55 +02001" Tests for startup.
Bram Moolenaarb9a46fe2016-07-29 18:13:42 +02002
Bram Moolenaar66459b72016-08-06 19:01:55 +02003source shared.vim
Bram Moolenaarc75e8122019-04-21 15:55:10 +02004source screendump.vim
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02005source term_util.vim
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02006source check.vim
Bram Moolenaar66459b72016-08-06 19:01:55 +02007
8" Check that loading startup.vim works.
Bram Moolenaarb9a46fe2016-07-29 18:13:42 +02009func Test_startup_script()
10 set compatible
11 source $VIMRUNTIME/defaults.vim
12
13 call assert_equal(0, &compatible)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +020014 " Restore some options, so that the following tests doesn't break
15 set nomore
16 set noshowmode
Bram Moolenaarb9a46fe2016-07-29 18:13:42 +020017endfunc
Bram Moolenaar66459b72016-08-06 19:01:55 +020018
19" Verify the order in which plugins are loaded:
20" 1. plugins in non-after directories
21" 2. packages
22" 3. plugins in after directories
23func Test_after_comes_later()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020024 CheckFeature packages
Bram Moolenaarc79745a2019-05-20 22:12:34 +020025 let before =<< trim [CODE]
26 set nocp viminfo+=nviminfo
27 set guioptions+=M
28 let $HOME = "/does/not/exist"
29 set loadplugins
30 set rtp=Xhere,Xafter,Xanother
31 set packpath=Xhere,Xafter
32 set nomore
33 let g:sequence = ""
34 [CODE]
35
36 let after =<< trim [CODE]
37 redir! > Xtestout
38 scriptnames
39 redir END
40 redir! > Xsequence
41 echo g:sequence
42 redir END
43 quit
44 [CODE]
45
Bram Moolenaar56564962022-10-10 22:39:42 +010046 call mkdir('Xhere/plugin', 'pR')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020047 call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim')
Bram Moolenaar56564962022-10-10 22:39:42 +010048 call mkdir('Xanother/plugin', 'pR')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020049 call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020050 call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020051 call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020052
Bram Moolenaar56564962022-10-10 22:39:42 +010053 call mkdir('Xafter/plugin', 'pR')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020054 call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020055
Bram Moolenaar472a0a82016-08-06 22:31:42 +020056 if RunVim(before, after, '')
Bram Moolenaar66459b72016-08-06 19:01:55 +020057
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020058 let lines = readfile('Xtestout')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020059 let expected = ['Xbefore.vim', 'here.vim', 'another.vim', 'foo.vim', 'later.vim', 'Xafter.vim']
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020060 let found = []
61 for line in lines
62 for one in expected
63 if line =~ one
64 call add(found, one)
65 endif
66 endfor
Bram Moolenaar66459b72016-08-06 19:01:55 +020067 endfor
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020068 call assert_equal(expected, found)
69 endif
Bram Moolenaar66459b72016-08-06 19:01:55 +020070
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020071 call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', ''))
72
Bram Moolenaar66459b72016-08-06 19:01:55 +020073 call delete('Xtestout')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020074 call delete('Xsequence')
Bram Moolenaar66459b72016-08-06 19:01:55 +020075endfunc
Bram Moolenaar472a0a82016-08-06 22:31:42 +020076
Bram Moolenaarce876aa2017-06-04 17:47:42 +020077func Test_pack_in_rtp_when_plugins_run()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020078 CheckFeature packages
Bram Moolenaarc79745a2019-05-20 22:12:34 +020079 let before =<< trim [CODE]
80 set nocp viminfo+=nviminfo
81 set guioptions+=M
82 let $HOME = "/does/not/exist"
83 set loadplugins
84 set rtp=Xhere
85 set packpath=Xhere
86 set nomore
87 [CODE]
88
Bram Moolenaarce876aa2017-06-04 17:47:42 +020089 let after = [
90 \ 'quit',
91 \ ]
Bram Moolenaar56564962022-10-10 22:39:42 +010092 call mkdir('Xhere/plugin', 'pR')
Bram Moolenaarce876aa2017-06-04 17:47:42 +020093 call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim')
94 call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p')
95 call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim')
96
97 if RunVim(before, after, '')
98
99 let lines = filter(readfile('Xtestout'), '!empty(v:val)')
100 call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0))
101 call assert_match('autoloaded foo', get(lines, 1))
102 endif
103
104 call delete('Xtestout')
Bram Moolenaarce876aa2017-06-04 17:47:42 +0200105endfunc
106
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200107func Test_help_arg()
Bram Moolenaarf8c52e82021-03-17 12:27:23 +0100108 " This does not work with a GUI-only binary, such as on MS-Windows.
109 CheckAnyOf Unix NotGui
Bram Moolenaar240309c2021-03-14 16:20:37 +0100110
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200111 if RunVim([], [], '--help >Xtestout')
112 let lines = readfile('Xtestout')
113 call assert_true(len(lines) > 20)
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200114 call assert_match('Vi IMproved', lines[0])
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200115
116 " check if couple of lines are there
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200117 let found = []
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200118 for line in lines
119 if line =~ '-R.*Readonly mode'
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200120 call add(found, 'Readonly mode')
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200121 endif
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200122 " Watch out for a second --version line in the Gnome version.
123 if line =~ '--version.*Print version information and exit'
124 call add(found, "--version")
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200125 endif
126 endfor
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200127 call assert_equal(['Readonly mode', '--version'], found)
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200128 endif
129 call delete('Xtestout')
130endfunc
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200131
132func Test_compatible_args()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200133 let after =<< trim [CODE]
134 call writefile([string(&compatible)], "Xtestout")
135 set viminfo+=nviminfo
136 quit
137 [CODE]
138
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200139 if RunVim([], after, '-C')
140 let lines = readfile('Xtestout')
141 call assert_equal('1', lines[0])
142 endif
143
144 if RunVim([], after, '-N')
145 let lines = readfile('Xtestout')
146 call assert_equal('0', lines[0])
147 endif
148
149 call delete('Xtestout')
150endfunc
151
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200152" Test the -o[N] and -O[N] arguments to open N windows split
153" horizontally or vertically.
154func Test_o_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200155 let after =<< trim [CODE]
Bram Moolenaare96a2492019-06-25 04:12:16 +0200156 set cpo&vim
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200157 call writefile([winnr("$"),
158 \ winheight(1), winheight(2), &lines,
159 \ winwidth(1), winwidth(2), &columns,
160 \ bufname(winbufnr(1)), bufname(winbufnr(2))],
161 \ "Xtestout")
162 qall
163 [CODE]
164
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200165 if RunVim([], after, '-o2')
166 " Open 2 windows split horizontally. Expect:
167 " - 2 windows
168 " - both windows should have the same or almost the same height
169 " - sum of both windows height (+ 3 for both statusline and Ex command)
170 " should be equal to the number of lines
171 " - both windows should have the same width which should be equal to the
172 " number of columns
173 " - buffer of both windows should have no name
174 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
175 call assert_equal('2', wn)
176 call assert_inrange(0, 1, wh1 - wh2)
177 call assert_equal(string(wh1 + wh2 + 3), ln)
178 call assert_equal(ww1, ww2)
179 call assert_equal(ww1, cn)
180 call assert_equal('', bn1)
181 call assert_equal('', bn2)
182 endif
183
184 if RunVim([], after, '-o foo bar')
185 " Same expectations as for -o2 but buffer names should be foo and bar
186 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
187 call assert_equal('2', wn)
188 call assert_inrange(0, 1, wh1 - wh2)
189 call assert_equal(string(wh1 + wh2 + 3), ln)
190 call assert_equal(ww1, ww2)
191 call assert_equal(ww1, cn)
192 call assert_equal('foo', bn1)
193 call assert_equal('bar', bn2)
194 endif
195
196 if RunVim([], after, '-O2')
197 " Open 2 windows split vertically. Expect:
198 " - 2 windows
199 " - both windows should have the same or almost the same width
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200200 " - sum of both windows width (+ 1 for the separator) should be equal to
201 " the number of columns
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200202 " - both windows should have the same height
203 " - window height (+ 2 for the statusline and Ex command) should be equal
204 " to the number of lines
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200205 " - buffer of both windows should have no name
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200206 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
207 call assert_equal('2', wn)
208 call assert_inrange(0, 1, ww1 - ww2)
209 call assert_equal(string(ww1 + ww2 + 1), cn)
210 call assert_equal(wh1, wh2)
211 call assert_equal(string(wh1 + 2), ln)
212 call assert_equal('', bn1)
213 call assert_equal('', bn2)
214 endif
215
216 if RunVim([], after, '-O foo bar')
217 " Same expectations as for -O2 but buffer names should be foo and bar
218 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
219 call assert_equal('2', wn)
220 call assert_inrange(0, 1, ww1 - ww2)
221 call assert_equal(string(ww1 + ww2 + 1), cn)
222 call assert_equal(wh1, wh2)
223 call assert_equal(string(wh1 + 2), ln)
224 call assert_equal('foo', bn1)
225 call assert_equal('bar', bn2)
226 endif
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200227 call delete('Xtestout')
228endfunc
229
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200230" Test the -p[N] argument to open N tabpages.
231func Test_p_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200232 let after =<< trim [CODE]
233 call writefile(split(execute("tabs"), "\n"), "Xtestout")
234 qall
235 [CODE]
236
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200237 if RunVim([], after, '-p2')
238 let lines = readfile('Xtestout')
239 call assert_equal(4, len(lines))
240 call assert_equal('Tab page 1', lines[0])
241 call assert_equal('> [No Name]', lines[1])
242 call assert_equal('Tab page 2', lines[2])
243 call assert_equal(' [No Name]', lines[3])
244 endif
245
246 if RunVim([], after, '-p foo bar')
247 let lines = readfile('Xtestout')
248 call assert_equal(4, len(lines))
249 call assert_equal('Tab page 1', lines[0])
250 call assert_equal('> foo', lines[1])
251 call assert_equal('Tab page 2', lines[2])
252 call assert_equal(' bar', lines[3])
253 endif
254
255 call delete('Xtestout')
256endfunc
257
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200258" Test the -V[N] argument to set the 'verbose' option to [N]
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200259func Test_V_arg()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200260 " Can't catch the output of gvim.
261 CheckNotGui
262
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200263 let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq')
264 call assert_equal(" verbose=0\n", out)
265
266 let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq')
Bram Moolenaar4515bcd2020-05-03 18:21:04 +0200267 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline \\d\\+: sourcing \"[^\"]*runtime[\\/]filetype\.vim\".*\n", out)
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200268 call assert_match(" verbose=2\n", out)
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200269
270 let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq')
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200271 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline 1: \" The default vimrc file\..* verbose=15\n", out)
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200272endfunc
273
Christian Brabandt1d3a14e2021-05-29 19:53:50 +0200274" Test that an error is shown when the defaults.vim file could not be read
Bram Moolenaara83d0602021-06-02 16:49:32 +0200275func Test_defaults_error()
276 " Can't catch the output of gvim.
277 CheckNotGui
278 CheckNotMSWindows
279 " For unknown reasons freeing all memory does not work here, even though
280 " EXITFREE is defined.
281 CheckNotAsan
282
283 let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' --clean -cq')
284 call assert_match("E1187: Failed to source defaults.vim", out)
285
286 let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' -u DEFAULTS -cq')
287 call assert_match("E1187: Failed to source defaults.vim", out)
288endfunc
Christian Brabandt1d3a14e2021-05-29 19:53:50 +0200289
Bram Moolenaar54948182018-12-28 18:32:56 +0100290" Test the '-q [errorfile]' argument.
291func Test_q_arg()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100292 CheckFeature quickfix
293
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200294 let lines =<< trim END
295 /* some file with an error */
296 main() {
297 functionCall(arg; arg, arg);
298 return 666
299 }
300 END
Bram Moolenaar56564962022-10-10 22:39:42 +0100301 call writefile(lines, 'Xbadfile.c', 'D')
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200302
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200303 let after =<< trim [CODE]
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100304 call writefile([&errorfile, string(getpos("."))], "XtestoutQarg")
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200305 copen
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100306 w >> XtestoutQarg
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200307 qall
308 [CODE]
Bram Moolenaar54948182018-12-28 18:32:56 +0100309
310 " Test with default argument '-q'.
311 call assert_equal('errors.err', &errorfile)
Bram Moolenaar56564962022-10-10 22:39:42 +0100312 call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'errors.err', 'D')
Bram Moolenaar54948182018-12-28 18:32:56 +0100313 if RunVim([], after, '-q')
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100314 let lines = readfile('XtestoutQarg')
Bram Moolenaar54948182018-12-28 18:32:56 +0100315 call assert_equal(['errors.err',
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200316 \ '[0, 4, 12, 0]',
317 \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100318 \ lines)
319 endif
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100320 call delete('XtestoutQarg')
Bram Moolenaar54948182018-12-28 18:32:56 +0100321
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100322 " Test with explicit argument '-q XerrorsQarg' (with space).
Bram Moolenaar56564962022-10-10 22:39:42 +0100323 call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'XerrorsQarg', 'D')
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100324 if RunVim([], after, '-q XerrorsQarg')
325 let lines = readfile('XtestoutQarg')
326 call assert_equal(['XerrorsQarg',
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200327 \ '[0, 4, 12, 0]',
328 \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100329 \ lines)
330 endif
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100331 call delete('XtestoutQarg')
Bram Moolenaar54948182018-12-28 18:32:56 +0100332
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100333 " Test with explicit argument '-qXerrorsQarg' (without space).
334 if RunVim([], after, '-qXerrorsQarg')
335 let lines = readfile('XtestoutQarg')
336 call assert_equal(['XerrorsQarg',
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200337 \ '[0, 4, 12, 0]',
338 \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100339 \ lines)
340 endif
341
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200342 " Test with a non-existing error file (exits with value 3)
343 let out = system(GetVimCommand() .. ' -q xyz.err')
344 call assert_equal(3, v:shell_error)
345
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100346 call delete('XtestoutQarg')
Bram Moolenaar54948182018-12-28 18:32:56 +0100347endfunc
348
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200349" Test the -V[N]{filename} argument to set the 'verbose' option to N
350" and set 'verbosefile' to filename.
351func Test_V_file_arg()
Bram Moolenaar4841a7c2018-09-22 14:08:49 +0200352 if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq')
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200353 let out = join(readfile('Xverbosefile'), "\n")
354 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out)
355 call assert_match("\n verbose=2\n", out)
356 call assert_match("\n verbosefile=Xverbosefile", out)
357 endif
358
359 call delete('Xverbosefile')
360endfunc
361
362" Test the -m, -M and -R arguments:
363" -m resets 'write'
364" -M resets 'modifiable' and 'write'
365" -R sets 'readonly'
366func Test_m_M_R()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200367 let after =<< trim [CODE]
368 call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout")
369 qall
370 [CODE]
371
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200372 if RunVim([], after, '')
373 let lines = readfile('Xtestout')
374 call assert_equal(['1', '1', '0', '200'], lines)
375 endif
376 if RunVim([], after, '-m')
377 let lines = readfile('Xtestout')
378 call assert_equal(['0', '1', '0', '200'], lines)
379 endif
380 if RunVim([], after, '-M')
381 let lines = readfile('Xtestout')
382 call assert_equal(['0', '0', '0', '200'], lines)
383 endif
384 if RunVim([], after, '-R')
385 let lines = readfile('Xtestout')
386 call assert_equal(['1', '1', '1', '10000'], lines)
387 endif
388
389 call delete('Xtestout')
390endfunc
391
zeertzjqf0300fc2023-02-28 16:02:35 +0000392" Test the -A and -H arguments (Arabic and Hebrew modes).
393func Test_A_H_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200394 let after =<< trim [CODE]
Bram Moolenaar9ce79152022-10-12 11:54:34 +0100395 call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout")
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200396 qall
397 [CODE]
398
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200399 " Use silent Ex mode to avoid the hit-Enter prompt for the warning that
400 " 'encoding' is not utf-8.
401 if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A')
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200402 let lines = readfile('Xtestout')
403 call assert_equal(['1', '1', '0', '0'], lines)
404 endif
405
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200406 if has('rightleft') && RunVim([], after, '-H')
407 let lines = readfile('Xtestout')
408 call assert_equal(['1', '0', '0', '1'], lines)
409 endif
Bram Moolenaar9ce79152022-10-12 11:54:34 +0100410
411 call delete('Xtestout')
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200412endfunc
413
Bram Moolenaar240309c2021-03-14 16:20:37 +0100414" Test the --echo-wid argument (for GTK GUI only).
415func Test_echo_wid()
416 CheckCanRunGui
417 CheckFeature gui_gtk
418
419 if RunVim([], [], '-g --echo-wid -cq >Xtest_echo_wid')
420 let lines = readfile('Xtest_echo_wid')
421 call assert_equal(1, len(lines))
422 call assert_match('^WID: \d\+$', lines[0])
423 endif
424
425 call delete('Xtest_echo_wid')
426endfunction
427
428" Test the -reverse and +reverse arguments (for GUI only).
429func Test_reverse()
430 CheckCanRunGui
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100431 CheckAnyOf Feature:gui_gtk Feature:gui_motif
Bram Moolenaar240309c2021-03-14 16:20:37 +0100432
433 let after =<< trim [CODE]
434 call writefile([&background], "Xtest_reverse")
435 qall
436 [CODE]
437 if RunVim([], after, '-f -g -reverse')
438 let lines = readfile('Xtest_reverse')
439 call assert_equal(['dark'], lines)
440 endif
441 if RunVim([], after, '-f -g +reverse')
442 let lines = readfile('Xtest_reverse')
443 call assert_equal(['light'], lines)
444 endif
445
446 call delete('Xtest_reverse')
447endfunc
448
449" Test the -background and -foreground arguments (for GUI only).
450func Test_background_foreground()
451 CheckCanRunGui
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100452 CheckAnyOf Feature:gui_gtk Feature:gui_motif
Bram Moolenaar240309c2021-03-14 16:20:37 +0100453
454 " Is there a better way to check the effect of -background & -foreground
455 " other than merely looking at &background (dark or light)?
456 let after =<< trim [CODE]
457 call writefile([&background], "Xtest_fg_bg")
458 qall
459 [CODE]
460 if RunVim([], after, '-f -g -background darkred -foreground yellow')
461 let lines = readfile('Xtest_fg_bg')
462 call assert_equal(['dark'], lines)
463 endif
464 if RunVim([], after, '-f -g -background ivory -foreground darkgreen')
465 let lines = readfile('Xtest_fg_bg')
466 call assert_equal(['light'], lines)
467 endif
468
469 call delete('Xtest_fg_bg')
470endfunc
471
472" Test the -font argument (for GUI only).
473func Test_font()
474 CheckCanRunGui
475 CheckNotMSWindows
476
477 if has('gui_gtk')
478 let font = 'Courier 14'
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100479 elseif has('gui_motif')
Bram Moolenaar240309c2021-03-14 16:20:37 +0100480 let font = '-misc-fixed-bold-*'
481 else
482 throw 'Skipped: test does not set a valid font for this GUI'
483 endif
484
485 let after =<< trim [CODE]
486 call writefile([&guifont], "Xtest_font")
487 qall
488 [CODE]
489
490 if RunVim([], after, '--nofork -g -font "' .. font .. '"')
491 let lines = readfile('Xtest_font')
492 call assert_equal([font], lines)
493 endif
494
495 call delete('Xtest_font')
496endfunc
497
498" Test the -geometry argument (for GUI only).
499func Test_geometry()
500 CheckCanRunGui
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100501 CheckAnyOf Feature:gui_gtk Feature:gui_motif
Bram Moolenaar240309c2021-03-14 16:20:37 +0100502
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100503 if has('gui_motif')
504 " FIXME: With GUI Motif the value of getwinposx(),
Bram Moolenaar240309c2021-03-14 16:20:37 +0100505 " getwinposy() and getwinpos() do not match exactly the
506 " value given in -geometry. Why?
507 " So only check &columns and &lines for those GUIs.
508 let after =<< trim [CODE]
509 call writefile([&columns, &lines], "Xtest_geometry")
510 qall
511 [CODE]
512 if RunVim([], after, '-f -g -geometry 31x13+41+43')
513 let lines = readfile('Xtest_geometry')
514 call assert_equal(['31', '13'], lines)
515 endif
516 else
517 let after =<< trim [CODE]
518 call writefile([&columns, &lines, getwinposx(), getwinposy(), string(getwinpos())], "Xtest_geometry")
519 qall
520 [CODE]
lilydjwg6e0a18f2024-01-29 20:54:28 +0100521 " Hide menu because gtk insists to make the window wide enough to show it completely
Bram Moolenaarfa04eae2022-06-21 14:38:40 +0100522 " Some window managers have a bar at the top that pushes windows down,
523 " need to use at least 130, let's do 150
lilydjwg6e0a18f2024-01-29 20:54:28 +0100524 if RunVim(['set guioptions-=m'], after, '-f -g -geometry 31x13+41+150')
Bram Moolenaar240309c2021-03-14 16:20:37 +0100525 let lines = readfile('Xtest_geometry')
Bram Moolenaarb376aa22021-10-11 16:08:32 +0100526 " Depending on the GUI library and the windowing system the final size
527 " might be a bit different, allow for some tolerance. Tuned based on
528 " actual failures.
Bram Moolenaar3d031a02021-10-11 22:57:34 +0100529 call assert_inrange(31, 35, str2nr(lines[0]))
lilydjwg94ff09a2024-01-29 20:14:01 +0100530 " for some reason, the window may contain fewer lines than requested
531 " for GTK, so allow some tolerance
532 call assert_inrange(8, 13, str2nr(lines[1]))
lilydjwg6e0a18f2024-01-29 20:54:28 +0100533 " on Wayland there is no way to set or retrieve window positions
534 if empty($WAYLAND_DISPLAY)
535 call assert_equal('41', lines[2])
536 call assert_equal('150', lines[3])
537 call assert_equal('[41, 150]', lines[4])
538 endif
Bram Moolenaar240309c2021-03-14 16:20:37 +0100539 endif
540 endif
541
542 call delete('Xtest_geometry')
543endfunc
544
545" Test the -iconic argument (for GUI only).
546func Test_iconic()
547 CheckCanRunGui
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100548 CheckAnyOf Feature:gui_gtk Feature:gui_motif
Bram Moolenaar240309c2021-03-14 16:20:37 +0100549
550 call RunVim([], [], '-f -g -iconic -cq')
551
552 " TODO: currently only start vim iconified, but does not
553 " check that vim is iconified. How could this be checked?
554endfunc
555
556
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200557func Test_invalid_args()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200558 " must be able to get the output of Vim.
559 CheckUnix
560 CheckNotGui
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200561
562 for opt in ['-Y', '--does-not-exist']
563 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
564 call assert_equal(1, v:shell_error)
565 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
566 call assert_equal('Unknown option argument: "' .. opt .. '"', out[1])
567 call assert_equal('More info with: "vim -h"', out[2])
568 endfor
569
570 for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime']
571 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
572 call assert_equal(1, v:shell_error)
573 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
574 call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
575 call assert_equal('More info with: "vim -h"', out[2])
576 endfor
577
578 if has('clientserver')
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200579 for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr',
580 \ '--remote-tab', '--remote-tab-wait',
581 \ '--remote-tab-wait-silent', '--remote-tab-silent',
582 \ '--remote-wait', '--remote-wait-silent',
Bram Moolenaar27821262019-05-08 16:41:09 +0200583 \ '--servername',
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200584 \ ]
585 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
586 call assert_equal(1, v:shell_error)
587 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
588 call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
589 call assert_equal('More info with: "vim -h"', out[2])
590 endfor
591 endif
592
Bram Moolenaar240f7ab2019-05-08 17:58:15 +0200593 if has('gui_gtk')
Bram Moolenaar27821262019-05-08 16:41:09 +0200594 let out = split(system(GetVimCommand() .. ' --display'), "\n")
595 call assert_equal(1, v:shell_error)
596 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
597 call assert_equal('Argument missing after: "--display"', out[1])
598 call assert_equal('More info with: "vim -h"', out[2])
599 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200600
Bram Moolenaar5416b752019-05-08 18:36:43 +0200601 if has('xterm_clipboard')
Bram Moolenaar240f7ab2019-05-08 17:58:15 +0200602 let out = split(system(GetVimCommand() .. ' -display'), "\n")
603 call assert_equal(1, v:shell_error)
604 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
605 call assert_equal('Argument missing after: "-display"', out[1])
606 call assert_equal('More info with: "vim -h"', out[2])
607 endif
608
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200609 let out = split(system(GetVimCommand() .. ' -ix'), "\n")
610 call assert_equal(1, v:shell_error)
611 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
612 call assert_equal('Garbage after option argument: "-ix"', out[1])
613 call assert_equal('More info with: "vim -h"', out[2])
614
615 let out = split(system(GetVimCommand() .. ' - xxx'), "\n")
616 call assert_equal(1, v:shell_error)
617 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
618 call assert_equal('Too many edit arguments: "xxx"', out[1])
619 call assert_equal('More info with: "vim -h"', out[2])
620
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100621 if has('quickfix')
Dominique Pelled176ca32021-09-09 20:45:34 +0200622 " Detect invalid repeated arguments '-t foo -t foo', '-q foo -q foo'.
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100623 for opt in ['-t', '-q']
624 let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n")
625 call assert_equal(1, v:shell_error)
626 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
627 call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1])
628 call assert_equal('More info with: "vim -h"', out[2])
629 endfor
630 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200631
632 for opt in [' -cq', ' --cmd q', ' +', ' -S foo']
633 let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n")
634 call assert_equal(1, v:shell_error)
635 " FIXME: The error message given by Vim is not ideal in case of repeated
636 " -S foo since it does not mention -S.
637 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
638 call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1])
639 call assert_equal('More info with: "vim -h"', out[2])
640 endfor
641
Bram Moolenaar27821262019-05-08 16:41:09 +0200642 if has('gui_gtk')
Dominique Pelle6d37e8e2021-05-06 17:36:55 +0200643 let out = split(system(GetVimCommand() .. ' --socketid'), "\n")
644 call assert_equal(1, v:shell_error)
645 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
646 call assert_equal('Argument missing after: "--socketid"', out[1])
647 call assert_equal('More info with: "vim -h"', out[2])
648
Bram Moolenaar27821262019-05-08 16:41:09 +0200649 for opt in ['--socketid x', '--socketid 0xg']
650 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
651 call assert_equal(1, v:shell_error)
652 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
653 call assert_equal('Invalid argument for: "--socketid"', out[1])
654 call assert_equal('More info with: "vim -h"', out[2])
655 endfor
Dominique Pelle6d37e8e2021-05-06 17:36:55 +0200656
Bram Moolenaar27821262019-05-08 16:41:09 +0200657 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200658endfunc
659
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200660func Test_file_args()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200661 let after =<< trim [CODE]
662 call writefile(argv(), "Xtestout")
663 qall
664 [CODE]
665
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200666 if RunVim([], after, '')
667 let lines = readfile('Xtestout')
668 call assert_equal(0, len(lines))
669 endif
670
671 if RunVim([], after, 'one')
672 let lines = readfile('Xtestout')
673 call assert_equal(1, len(lines))
674 call assert_equal('one', lines[0])
675 endif
676
677 if RunVim([], after, 'one two three')
678 let lines = readfile('Xtestout')
679 call assert_equal(3, len(lines))
680 call assert_equal('one', lines[0])
681 call assert_equal('two', lines[1])
682 call assert_equal('three', lines[2])
683 endif
684
685 if RunVim([], after, 'one -c echo two')
686 let lines = readfile('Xtestout')
687 call assert_equal(2, len(lines))
688 call assert_equal('one', lines[0])
689 call assert_equal('two', lines[1])
690 endif
691
692 if RunVim([], after, 'one -- -c echo two')
693 let lines = readfile('Xtestout')
694 call assert_equal(4, len(lines))
695 call assert_equal('one', lines[0])
696 call assert_equal('-c', lines[1])
697 call assert_equal('echo', lines[2])
698 call assert_equal('two', lines[3])
699 endif
700
701 call delete('Xtestout')
702endfunc
703
704func Test_startuptime()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200705 CheckFeature startuptime
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200706 let after = ['qall']
707 if RunVim([], after, '--startuptime Xtestout one')
708 let lines = readfile('Xtestout')
709 let expected = ['--- VIM STARTING ---', 'parsing arguments',
710 \ 'shell init', 'inits 3', 'start termcap', 'opening buffers']
711 let found = []
712 for line in lines
713 for exp in expected
714 if line =~ exp
715 call add(found, exp)
716 endif
717 endfor
718 endfor
719 call assert_equal(expected, found)
720 endif
721 call delete('Xtestout')
722endfunc
Bram Moolenaar3a938382016-08-07 16:36:40 +0200723
Bram Moolenaarc9a9a0a2022-04-12 15:09:23 +0100724func Test_log()
725 CheckFeature channel
726
727 call assert_false(filereadable('Xlogfile'))
728 let after = ['qall']
729 if RunVim([], after, '--log Xlogfile')
730 call assert_equal(1, readfile('Xlogfile')
731 \ ->filter({i, l -> l =~ '==== start log session'})
732 \ ->len())
733 " second time appends to the log
734 if RunVim([], after, '--log Xlogfile')
735 call assert_equal(2, readfile('Xlogfile')
736 \ ->filter({i, l -> l =~ '==== start log session'})
737 \ ->len())
738 endif
739 endif
740 call delete('Xlogfile')
741endfunc
742
Hirohito Higashic5654b82025-02-10 20:55:17 +0100743func Test_log_nonexistent()
744 " this used to crash Vim
745 CheckFeature channel
746 let result = join(systemlist(GetVimCommand() .. ' --log /X/Xlogfile -c qa!'))
747 call assert_match("E484: Can't open file", result)
748endfunc
749
Bram Moolenaar3a938382016-08-07 16:36:40 +0200750func Test_read_stdin()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200751 let after =<< trim [CODE]
752 write Xtestout
753 quit!
754 [CODE]
755
Bram Moolenaar3a938382016-08-07 16:36:40 +0200756 if RunVimPiped([], after, '-', 'echo something | ')
757 let lines = readfile('Xtestout')
Bram Moolenaare4a76ad2016-08-07 16:50:10 +0200758 " MS-Windows adds a space after the word
759 call assert_equal(['something'], split(lines[0]))
Bram Moolenaar3a938382016-08-07 16:36:40 +0200760 endif
761 call delete('Xtestout')
762endfunc
Bram Moolenaar08cab962017-03-04 14:37:18 +0100763
764func Test_progpath()
765 " Tests normally run with "./vim" or "../vim", these must have been expanded
766 " to a full path.
767 if has('unix')
768 call assert_equal('/', v:progpath[0])
769 elseif has('win32')
770 call assert_equal(':', v:progpath[1])
771 call assert_match('[/\\]', v:progpath[2])
772 endif
773
774 " Only expect "vim" to appear in v:progname.
775 call assert_match('vim\c', v:progname)
776endfunc
Bram Moolenaard5d37532017-03-27 23:02:07 +0200777
778func Test_silent_ex_mode()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200779 " must be able to get the output of Vim.
780 CheckUnix
781 CheckNotGui
Bram Moolenaard5d37532017-03-27 23:02:07 +0200782
783 " This caused an ml_get error.
784 let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq')
785 call assert_notmatch('E315:', out)
786endfunc
Bram Moolenaar85045a72017-04-02 16:54:09 +0200787
788func Test_default_term()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200789 " must be able to get the output of Vim.
790 CheckUnix
791 CheckNotGui
Bram Moolenaar85045a72017-04-02 16:54:09 +0200792
793 let save_term = $TERM
Bram Moolenaar08f88b12017-04-02 17:21:16 +0200794 let $TERM = 'unknownxxx'
Bram Moolenaar85045a72017-04-02 16:54:09 +0200795 let out = system(GetVimCommand() . ' -c''set term'' -c cq')
796 call assert_match("defaulting to 'ansi'", out)
797 let $TERM = save_term
798endfunc
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200799
800func Test_zzz_startinsert()
801 " Test :startinsert
Bram Moolenaar56564962022-10-10 22:39:42 +0100802 call writefile(['123456'], 'Xtestout', 'D')
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200803 let after =<< trim [CODE]
804 :startinsert
805 call feedkeys("foobar\<c-o>:wq\<cr>","t")
806 [CODE]
807
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200808 if RunVim([], after, 'Xtestout')
809 let lines = readfile('Xtestout')
810 call assert_equal(['foobar123456'], lines)
811 endif
812 " Test :startinsert!
813 call writefile(['123456'], 'Xtestout')
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200814 let after =<< trim [CODE]
815 :startinsert!
816 call feedkeys("foobar\<c-o>:wq\<cr>","t")
817 [CODE]
818
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200819 if RunVim([], after, 'Xtestout')
820 let lines = readfile('Xtestout')
821 call assert_equal(['123456foobar'], lines)
822 endif
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200823endfunc
Bram Moolenaar97c2c052019-02-22 13:42:07 +0100824
825func Test_issue_3969()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200826 " Can't catch the output of gvim.
827 CheckNotGui
828
Bram Moolenaar97c2c052019-02-22 13:42:07 +0100829 " Check that message is not truncated.
830 let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq')
831 call assert_equal('hello', out)
832endfunc
Bram Moolenaarc75e8122019-04-21 15:55:10 +0200833
834func Test_start_with_tabs()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200835 CheckRunVimInTerminal
Bram Moolenaarc75e8122019-04-21 15:55:10 +0200836
837 let buf = RunVimInTerminal('-p a b c', {})
838 call VerifyScreenDump(buf, 'Test_start_with_tabs', {})
839
840 " clean up
841 call StopVimInTerminal(buf)
842endfunc
Bram Moolenaar69bf6342019-10-29 04:16:57 +0100843
Bram Moolenaard1f34e62022-01-07 19:24:20 +0000844func Test_start_in_minimal_window()
845 CheckRunVimInTerminal
846
847 let buf = RunVimInTerminal('-c "set nomore"', {'cols': 12, 'rows': 2, 'keep_t_u7': 1})
848 call term_sendkeys(buf, "ahello\<Esc>")
849 call WaitForAssert({-> assert_match('^hello', term_getline(buf, 1))})
850
851 " clean up
852 call StopVimInTerminal(buf)
853endfunc
854
Bram Moolenaar69bf6342019-10-29 04:16:57 +0100855func Test_v_argv()
856 " Can't catch the output of gvim.
857 CheckNotGui
858
859 let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q')
860 let list = out->split("', '")
861 call assert_match('vim', list[0])
862 let idx = index(list, 'arg1')
863 call assert_true(idx > 2)
864 call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:])
865endfunc
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200866
867" Test for the "-r" recovery mode option
868func Test_r_arg()
869 " Can't catch the output of gvim.
870 CheckNotGui
871 CheckUnix
872 CheckEnglish
873 let cmd = GetVimCommand()
874 " There can be swap files anywhere, only check for the headers.
875 let expected =<< trim END
876 Swap files found:.*
877 In current directory:.*
878 In directory \~/tmp:.*
879 In directory /var/tmp:.*
880 In directory /tmp:.*
881 END
882 call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', ''))
883endfunc
884
885" Test for the '-t' option to jump to a tag
886func Test_t_arg()
887 let before =<< trim [CODE]
888 set tags=Xtags
889 [CODE]
890 let after =<< trim [CODE]
891 let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.')
892 call writefile([s], "Xtestout")
893 qall
894 [CODE]
895
896 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
897 \ "first\tXfile1\t/^ \\zsfirst$/",
898 \ "second\tXfile1\t/^ \\zssecond$/",
899 \ "third\tXfile1\t/^ \\zsthird$/"],
Bram Moolenaar56564962022-10-10 22:39:42 +0100900 \ 'Xtags', 'D')
901 call writefile([' first', ' second', ' third'], 'Xfile1', 'D')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200902
Bram Moolenaara2b3e7d2021-03-26 17:24:34 +0100903 for t_arg in ['-t second', '-tsecond']
Dominique Pelled176ca32021-09-09 20:45:34 +0200904 if RunVim(before, after, t_arg)
Bram Moolenaara2b3e7d2021-03-26 17:24:34 +0100905 call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'), t_arg)
906 call delete('Xtestout')
907 endif
908 endfor
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200909endfunc
910
Bram Moolenaar1f33e0a2020-12-19 13:32:07 +0100911" Test the '-T' argument which sets the 'term' option.
912func Test_T_arg()
913 CheckNotGui
914 let after =<< trim [CODE]
915 call writefile([&term], "Xtest_T_arg")
916 qall
917 [CODE]
918
919 for t in ['builtin_dumb', 'builtin_ansi']
920 if RunVim([], after, '-T ' .. t)
921 let lines = readfile('Xtest_T_arg')
922 call assert_equal([t], lines)
923 endif
924 endfor
925
926 call delete('Xtest_T_arg')
927endfunc
928
929" Test the '-x' argument to read/write encrypted files.
930func Test_x_arg()
931 CheckRunVimInTerminal
932 CheckFeature cryptv
933
934 " Create an encrypted file Xtest_x_arg.
935 let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
936 call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
937 call term_sendkeys(buf, "foo\n")
938 call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
939 call term_sendkeys(buf, "foo\n")
940 call WaitForAssert({-> assert_match(' All$', term_getline(buf, 10))})
941 call term_sendkeys(buf, "itest\<Esc>:w\<Enter>")
942 call WaitForAssert({-> assert_match('"Xtest_x_arg" \[New\]\[blowfish2\] 1L, 5B written',
943 \ term_getline(buf, 10))})
944 call StopVimInTerminal(buf)
945
946 " Read the encrypted file and check that it contains the expected content "test"
947 let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
948 call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
949 call term_sendkeys(buf, "foo\n")
950 call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
951 call term_sendkeys(buf, "foo\n")
952 call WaitForAssert({-> assert_match('^test', term_getline(buf, 1))})
953 call StopVimInTerminal(buf)
954
955 call delete('Xtest_x_arg')
956endfunc
957
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200958" Test for entering the insert mode on startup
959func Test_start_insertmode()
960 let before =<< trim [CODE]
961 set insertmode
962 [CODE]
963 let after =<< trim [CODE]
964 call writefile(['insertmode=' .. &insertmode], 'Xtestout')
965 qall
966 [CODE]
967 if RunVim(before, after, '')
968 call assert_equal(['insertmode=1'], readfile('Xtestout'))
969 call delete('Xtestout')
970 endif
971endfunc
972
973" Test for enabling the binary mode on startup
974func Test_b_arg()
975 let after =<< trim [CODE]
976 call writefile(['binary=' .. &binary], 'Xtestout')
977 qall
978 [CODE]
979 if RunVim([], after, '-b')
980 call assert_equal(['binary=1'], readfile('Xtestout'))
981 call delete('Xtestout')
982 endif
983endfunc
984
985" Test for enabling the lisp mode on startup
986func Test_l_arg()
987 let after =<< trim [CODE]
988 let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch
989 call writefile([s], 'Xtestout')
990 qall
991 [CODE]
992 if RunVim([], after, '-l')
993 call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout'))
994 call delete('Xtestout')
995 endif
996endfunc
997
998" Test for specifying a non-existing vimrc file using "-u"
999func Test_missing_vimrc()
Bram Moolenaar494e9062020-05-31 21:28:02 +02001000 CheckRunVimInTerminal
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001001 let after =<< trim [CODE]
1002 call assert_match('^E282:', v:errmsg)
1003 call writefile(v:errors, 'Xtestout')
1004 [CODE]
Bram Moolenaar56564962022-10-10 22:39:42 +01001005 call writefile(after, 'Xafter', 'D')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001006
1007 let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter'
1008 let buf = term_start(cmd, {'term_rows' : 10})
1009 call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001010 call TermWait(buf)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001011 call term_sendkeys(buf, "\n:")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001012 call TermWait(buf)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001013 call WaitForAssert({-> assert_match(':', term_getline(buf, 10))})
1014 call StopVimInTerminal(buf)
1015 call assert_equal([], readfile('Xtestout'))
Bram Moolenaar56564962022-10-10 22:39:42 +01001016
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001017 call delete('Xtestout')
1018endfunc
1019
1020" Test for using the $VIMINIT environment variable
1021func Test_VIMINIT()
1022 let after =<< trim [CODE]
1023 call assert_equal(1, exists('viminit_found'))
1024 call assert_equal('yes', viminit_found)
1025 call writefile(v:errors, 'Xtestout')
1026 qall
1027 [CODE]
Bram Moolenaar56564962022-10-10 22:39:42 +01001028 call writefile(after, 'Xafter', 'D')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001029 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1030 call setenv('VIMINIT', 'let viminit_found="yes"')
1031 exe "silent !" . cmd
1032 call assert_equal([], readfile('Xtestout'))
Bram Moolenaar56564962022-10-10 22:39:42 +01001033
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001034 call delete('Xtestout')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001035endfunc
1036
1037" Test for using the $EXINIT environment variable
1038func Test_EXINIT()
1039 let after =<< trim [CODE]
1040 call assert_equal(1, exists('exinit_found'))
1041 call assert_equal('yes', exinit_found)
1042 call writefile(v:errors, 'Xtestout')
1043 qall
1044 [CODE]
Bram Moolenaar56564962022-10-10 22:39:42 +01001045 call writefile(after, 'Xafter', 'D')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001046 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1047 call setenv('EXINIT', 'let exinit_found="yes"')
1048 exe "silent !" . cmd
1049 call assert_equal([], readfile('Xtestout'))
Bram Moolenaar56564962022-10-10 22:39:42 +01001050
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001051 call delete('Xtestout')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001052endfunc
1053
1054" Test for using the 'exrc' option
1055func Test_exrc()
1056 let after =<< trim [CODE]
1057 call assert_equal(1, &exrc)
1058 call assert_equal(1, &secure)
1059 call assert_equal(37, exrc_found)
1060 call writefile(v:errors, 'Xtestout')
1061 qall
1062 [CODE]
Bram Moolenaar56564962022-10-10 22:39:42 +01001063 call mkdir('Xrcdir', 'R')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001064 call writefile(['let exrc_found=37'], 'Xrcdir/.exrc')
1065 call writefile(after, 'Xrcdir/Xafter')
1066 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xrcdir" --cmd "set enc=utf8 exrc secure"'
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001067 exe "silent !" . cmd
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001068 call assert_equal([], readfile('Xrcdir/Xtestout'))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001069endfunc
1070
1071" Test for starting Vim with a non-terminal as input/output
1072func Test_io_not_a_terminal()
1073 " Can't catch the output of gvim.
1074 CheckNotGui
1075 CheckUnix
1076 CheckEnglish
1077 let l = systemlist(GetVimProg() .. ' --ttyfail')
1078 call assert_equal(['Vim: Warning: Output is not to a terminal',
1079 \ 'Vim: Warning: Input is not from a terminal'], l)
1080endfunc
1081
Bram Moolenaar7007e312021-03-27 12:11:33 +01001082" Test for --not-a-term avoiding escape codes.
1083func Test_not_a_term()
1084 CheckUnix
1085 CheckNotGui
1086
1087 if &shellredir =~ '%s'
1088 let redir = printf(&shellredir, 'Xvimout')
1089 else
1090 let redir = &shellredir .. ' Xvimout'
1091 endif
1092
1093 " Without --not-a-term there are a few escape sequences.
1094 " This will take 2 seconds because of the missing --not-a-term
1095 let cmd = GetVimProg() .. ' --cmd quit ' .. redir
1096 exe "silent !" . cmd
1097 call assert_match("\<Esc>", readfile('Xvimout')->join())
1098 call delete('Xvimout')
1099
1100 " With --not-a-term there are no escape sequences.
1101 let cmd = GetVimProg() .. ' --not-a-term --cmd quit ' .. redir
1102 exe "silent !" . cmd
1103 call assert_notmatch("\<Esc>", readfile('Xvimout')->join())
1104 call delete('Xvimout')
1105endfunc
1106
Bram Moolenaar5939c352022-09-24 12:50:45 +01001107" Test quitting with CTRL-C when output is redirected.
1108func Test_redirect_Ctrl_C()
1109 CheckUnix
1110 CheckNotGui
1111 CheckRunVimInTerminal
1112
1113 let buf = Run_shell_in_terminal({})
1114 " Wait for the shell to display a prompt
1115 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
1116
1117 call term_sendkeys(buf, GetVimProg() .. " | grep word\<CR>")
1118 call WaitForAssert({-> assert_match("Output is not to a terminal", getline(1, 4)->join())})
1119 " wait for the hard coded delay, otherwise the CTRL-C interrupts startup
1120 sleep 2
1121 call term_sendkeys(buf, "\<C-C>")
1122 sleep 100m
1123 call term_sendkeys(buf, "exit\<CR>")
1124 call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
1125
1126 exe buf . 'bwipe!'
1127 unlet g:job
1128endfunc
1129
Bram Moolenaar7007e312021-03-27 12:11:33 +01001130
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001131" Test for the "-w scriptout" argument
1132func Test_w_arg()
1133 " Can't catch the output of gvim.
1134 CheckNotGui
Bram Moolenaar0a1a6a12021-03-26 14:14:18 +01001135
Bram Moolenaar56564962022-10-10 22:39:42 +01001136 call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'bD')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001137 if RunVim([], [], '-s Xscriptin -w Xscriptout')
1138 call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout'))
1139 call delete('Xscriptout')
1140 endif
1141 call delete('Xscriptin')
1142
1143 " Test for failing to open the script output file. This test works only when
1144 " the language is English.
1145 if v:lang == "C" || v:lang =~ '^[Ee]n'
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001146 call mkdir("Xargdir")
1147 let m = system(GetVimCommand() .. " -w Xargdir")
1148 call assert_equal("Cannot open for script output: \"Xargdir\"\n", m)
1149 call delete("Xargdir", 'rf')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001150 endif
Bram Moolenaar0a1a6a12021-03-26 14:14:18 +01001151
1152 " A number argument sets the 'window' option
1153 call writefile(["iwindow \<C-R>=&window\<CR>\<Esc>:wq! Xresult\<CR>"], 'Xscriptin', 'b')
Bram Moolenaara2b3e7d2021-03-26 17:24:34 +01001154 for w_arg in ['-w 17', '-w17']
1155 if RunVim([], [], '-s Xscriptin ' .. w_arg)
1156 call assert_equal(["window 17"], readfile('Xresult'), w_arg)
1157 call delete('Xresult')
1158 endif
1159 endfor
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001160endfunc
1161
1162" Test for the "-s scriptin" argument
1163func Test_s_arg()
1164 " Can't catch the output of gvim.
1165 CheckNotGui
1166 CheckEnglish
1167 " Test for failing to open the script input file.
1168 let m = system(GetVimCommand() .. " -s abcxyz")
1169 call assert_equal("Cannot open for reading: \"abcxyz\"\n", m)
1170
Bram Moolenaar56564962022-10-10 22:39:42 +01001171 call writefile([], 'Xinput', 'D')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001172 let m = system(GetVimCommand() .. " -s Xinput -s Xinput")
1173 call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001174endfunc
1175
1176" Test for the "-n" (no swap file) argument
1177func Test_n_arg()
1178 let after =<< trim [CODE]
1179 call assert_equal(0, &updatecount)
1180 call writefile(v:errors, 'Xtestout')
1181 qall
1182 [CODE]
1183 if RunVim([], after, '-n')
1184 call assert_equal([], readfile('Xtestout'))
1185 call delete('Xtestout')
1186 endif
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001187endfunc
1188
1189" Test for the "-h" (help) argument
1190func Test_h_arg()
1191 " Can't catch the output of gvim.
1192 CheckNotGui
1193 let l = systemlist(GetVimProg() .. ' -h')
1194 call assert_match('^VIM - Vi IMproved', l[0])
1195 let l = systemlist(GetVimProg() .. ' -?')
1196 call assert_match('^VIM - Vi IMproved', l[0])
1197endfunc
1198
1199" Test for the "-F" (farsi) argument
1200func Test_F_arg()
1201 " Can't catch the output of gvim.
1202 CheckNotGui
1203 let l = systemlist(GetVimProg() .. ' -F')
1204 call assert_match('^E27:', l[0])
1205endfunc
1206
1207" Test for the "-E" (improved Ex mode) argument
1208func Test_E_arg()
1209 let after =<< trim [CODE]
1210 call assert_equal('cv', mode(1))
1211 call writefile(v:errors, 'Xtestout')
1212 qall
1213 [CODE]
1214 if RunVim([], after, '-E')
1215 call assert_equal([], readfile('Xtestout'))
1216 call delete('Xtestout')
1217 endif
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001218endfunc
1219
Bram Moolenaarc5cf3692021-03-20 22:16:56 +01001220" Test for the "-D" (debugger) argument
1221func Test_D_arg()
1222 CheckRunVimInTerminal
1223
1224 let cmd = GetVimCommandCleanTerm() .. ' -D'
1225 let buf = term_start(cmd, {'term_rows' : 10})
1226 call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
1227
1228 call WaitForAssert({-> assert_equal('Entering Debug mode. Type "cont" to continue.',
1229 \ term_getline(buf, 7))})
1230 call WaitForAssert({-> assert_equal('>', term_getline(buf, 10))})
1231
1232 call StopVimInTerminal(buf)
1233endfunc
1234
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001235" Test for too many edit argument errors
1236func Test_too_many_edit_args()
1237 " Can't catch the output of gvim.
1238 CheckNotGui
1239 CheckEnglish
1240 let l = systemlist(GetVimProg() .. ' - -')
1241 call assert_match('^Too many edit arguments: "-"', l[1])
1242endfunc
1243
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001244" Test starting vim with various names: vim, ex, view, evim, etc.
1245func Test_progname()
1246 CheckUnix
1247
Bram Moolenaar56564962022-10-10 22:39:42 +01001248 call mkdir('Xprogname', 'pD')
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001249 call writefile(['silent !date',
1250 \ 'call writefile([mode(1), '
1251 \ .. '&insertmode, &diff, &readonly, &updatecount, '
1252 \ .. 'join(split(execute("message"), "\n")[1:])], "Xprogname_out")',
1253 \ 'qall'], 'Xprogname_after')
1254
1255 " +---------------------------------------------- progname
1256 " | +--------------------------------- mode(1)
1257 " | | +--------------------------- &insertmode
1258 " | | | +---------------------- &diff
1259 " | | | | +----------------- &readonly
1260 " | | | | | +-------- &updatecount
1261 " | | | | | | +--- :messages
1262 " | | | | | | |
1263 let expectations = {
1264 \ 'vim': ['n', '0', '0', '0', '200', ''],
1265 \ 'gvim': ['n', '0', '0', '0', '200', ''],
1266 \ 'ex': ['ce', '0', '0', '0', '200', ''],
1267 \ 'exim': ['cv', '0', '0', '0', '200', ''],
1268 \ 'view': ['n', '0', '0', '1', '10000', ''],
1269 \ 'gview': ['n', '0', '0', '1', '10000', ''],
1270 \ 'evim': ['n', '1', '0', '0', '200', ''],
1271 \ 'eview': ['n', '1', '0', '1', '10000', ''],
1272 \ 'rvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1273 \ 'rgvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1274 \ 'rview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1275 \ 'rgview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1276 \ 'vimdiff': ['n', '0', '1', '0', '200', ''],
1277 \ 'gvimdiff': ['n', '0', '1', '0', '200', '']}
1278
1279 let prognames = ['vim', 'gvim', 'ex', 'exim', 'view', 'gview',
1280 \ 'evim', 'eview', 'rvim', 'rgvim', 'rview', 'rgview',
1281 \ 'vimdiff', 'gvimdiff']
1282
1283 for progname in prognames
Bram Moolenaar240309c2021-03-14 16:20:37 +01001284 let run_with_gui = (progname =~# 'g') || (has('gui') && (progname ==# 'evim' || progname ==# 'eview'))
1285
1286 if empty($DISPLAY) && run_with_gui
1287 " Can't run gvim, gview (etc.) if $DISPLAY is not setup.
1288 continue
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001289 endif
1290
1291 exe 'silent !ln -s -f ' ..exepath(GetVimProg()) .. ' Xprogname/' .. progname
1292
1293 let stdout_stderr = ''
1294 if progname =~# 'g'
1295 let stdout_stderr = system('Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after')
1296 else
1297 exe 'sil !Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after'
1298 endif
1299
1300 if progname =~# 'g' && !has('gui')
1301 call assert_equal("E25: GUI cannot be used: Not enabled at compile time\n", stdout_stderr, progname)
1302 else
Bram Moolenaar240309c2021-03-14 16:20:37 +01001303 " GUI motif can output some warnings like this:
1304 " Warning:
1305 " Name: subMenu
1306 " Class: XmCascadeButton
1307 " Illegal mnemonic character; Could not convert X KEYSYM to a keycode
1308 " So don't check that stderr is empty with GUI Motif.
1309 if run_with_gui && !has('gui_motif')
1310 call assert_equal('', stdout_stderr, progname)
1311 endif
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001312 call assert_equal(expectations[progname], readfile('Xprogname_out'), progname)
1313 endif
1314
1315 call delete('Xprogname/' .. progname)
1316 call delete('Xprogname_out')
1317 endfor
1318
1319 call delete('Xprogname_after')
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001320endfunc
1321
Yegappan Lakshmanan36f96a52021-05-13 18:33:16 +02001322" Test for doing a write from .vimrc
1323func Test_write_in_vimrc()
Bram Moolenaar56564962022-10-10 22:39:42 +01001324 call writefile(['silent! write'], 'Xvimrc', 'D')
Yegappan Lakshmanan36f96a52021-05-13 18:33:16 +02001325 let after =<< trim [CODE]
1326 call assert_match('E32: ', v:errmsg)
1327 call writefile(v:errors, 'Xtestout')
1328 qall
1329 [CODE]
1330 if RunVim([], after, '-u Xvimrc')
1331 call assert_equal([], readfile('Xtestout'))
1332 call delete('Xtestout')
1333 endif
Yegappan Lakshmanan36f96a52021-05-13 18:33:16 +02001334endfunc
1335
Bram Moolenaara97c3632021-06-15 22:39:11 +02001336func Test_echo_true_in_cmd()
Bram Moolenaarb90ac5e2021-06-16 10:59:36 +02001337 CheckNotGui
1338
Bram Moolenaara97c3632021-06-15 22:39:11 +02001339 let lines =<< trim END
1340 echo v:true
1341 call writefile(['done'], 'Xresult')
Bram Moolenaar55b6b602021-06-15 23:05:59 +02001342 quit
Bram Moolenaara97c3632021-06-15 22:39:11 +02001343 END
Bram Moolenaar56564962022-10-10 22:39:42 +01001344 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar55b6b602021-06-15 23:05:59 +02001345 if RunVim([], [], '--cmd "source Xscript"')
Bram Moolenaara97c3632021-06-15 22:39:11 +02001346 call assert_equal(['done'], readfile('Xresult'))
1347 endif
Bram Moolenaar56564962022-10-10 22:39:42 +01001348
Bram Moolenaara97c3632021-06-15 22:39:11 +02001349 call delete('Xresult')
Bram Moolenaara97c3632021-06-15 22:39:11 +02001350endfunc
1351
Bram Moolenaard3710cf2021-10-04 23:13:13 +01001352func Test_rename_buffer_on_startup()
Bram Moolenaar6d197982021-10-05 01:19:53 +01001353 CheckUnix
1354
Bram Moolenaard3710cf2021-10-04 23:13:13 +01001355 let lines =<< trim END
1356 call writefile(['done'], 'Xresult')
1357 qa!
1358 END
Bram Moolenaar56564962022-10-10 22:39:42 +01001359 call writefile(lines, 'Xscript', 'D')
Bram Moolenaard3710cf2021-10-04 23:13:13 +01001360 if RunVim([], [], "--clean -e -s --cmd 'file x|new|file x' --cmd 'so Xscript'")
1361 call assert_equal(['done'], readfile('Xresult'))
1362 endif
Bram Moolenaar56564962022-10-10 22:39:42 +01001363
Bram Moolenaard3710cf2021-10-04 23:13:13 +01001364 call delete('Xresult')
1365endfunc
1366
Christian Brabandtba9aed42023-10-14 11:38:12 +02001367" Test that -cq works as expected
1368func Test_cq_zero_exmode()
Christian Brabandtc2900092023-10-17 18:10:13 +02001369 CheckFeature channel
1370
Christian Brabandtba9aed42023-10-14 11:38:12 +02001371 let logfile = 'Xcq_log.txt'
1372 let out = system(GetVimCommand() .. ' --clean --log ' .. logfile .. ' -es -X -c "argdelete foobar" -c"7cq"')
1373 call assert_equal(8, v:shell_error)
1374 let log = filter(readfile(logfile), {idx, val -> val =~ "E480"})
1375 call assert_match('E480: No match: foobar', log[0])
1376 call delete(logfile)
1377
1378 " wrap-around on Unix
1379 let out = system(GetVimCommand() .. ' --clean --log ' .. logfile .. ' -es -X -c "argdelete foobar" -c"255cq"')
1380 if !has('win32')
1381 call assert_equal(0, v:shell_error)
1382 else
1383 call assert_equal(256, v:shell_error)
1384 endif
1385 let log = filter(readfile(logfile), {idx, val -> val =~ "E480"})
1386 call assert_match('E480: No match: foobar', log[0])
1387 call delete('Xcq_log.txt')
1388endfunc
Bram Moolenaard3710cf2021-10-04 23:13:13 +01001389
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001390" vim: shiftwidth=2 sts=2 expandtab