blob: ff3510ef6a39eefc83e62f860169ab65f06498c3 [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 Moolenaar32860432016-08-06 19:24:23 +020024 if !has('packages')
25 return
26 endif
Bram Moolenaarc79745a2019-05-20 22:12:34 +020027 let before =<< trim [CODE]
28 set nocp viminfo+=nviminfo
29 set guioptions+=M
30 let $HOME = "/does/not/exist"
31 set loadplugins
32 set rtp=Xhere,Xafter,Xanother
33 set packpath=Xhere,Xafter
34 set nomore
35 let g:sequence = ""
36 [CODE]
37
38 let after =<< trim [CODE]
39 redir! > Xtestout
40 scriptnames
41 redir END
42 redir! > Xsequence
43 echo g:sequence
44 redir END
45 quit
46 [CODE]
47
Bram Moolenaar66459b72016-08-06 19:01:55 +020048 call mkdir('Xhere/plugin', 'p')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020049 call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim')
50 call mkdir('Xanother/plugin', 'p')
51 call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020052 call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020053 call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020054
55 call mkdir('Xafter/plugin', 'p')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020056 call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020057
Bram Moolenaar472a0a82016-08-06 22:31:42 +020058 if RunVim(before, after, '')
Bram Moolenaar66459b72016-08-06 19:01:55 +020059
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020060 let lines = readfile('Xtestout')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020061 let expected = ['Xbefore.vim', 'here.vim', 'another.vim', 'foo.vim', 'later.vim', 'Xafter.vim']
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020062 let found = []
63 for line in lines
64 for one in expected
65 if line =~ one
66 call add(found, one)
67 endif
68 endfor
Bram Moolenaar66459b72016-08-06 19:01:55 +020069 endfor
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020070 call assert_equal(expected, found)
71 endif
Bram Moolenaar66459b72016-08-06 19:01:55 +020072
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020073 call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', ''))
74
Bram Moolenaar66459b72016-08-06 19:01:55 +020075 call delete('Xtestout')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020076 call delete('Xsequence')
Bram Moolenaar66459b72016-08-06 19:01:55 +020077 call delete('Xhere', 'rf')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020078 call delete('Xanother', 'rf')
Bram Moolenaar66459b72016-08-06 19:01:55 +020079 call delete('Xafter', 'rf')
80endfunc
Bram Moolenaar472a0a82016-08-06 22:31:42 +020081
Bram Moolenaarce876aa2017-06-04 17:47:42 +020082func Test_pack_in_rtp_when_plugins_run()
83 if !has('packages')
84 return
85 endif
Bram Moolenaarc79745a2019-05-20 22:12:34 +020086 let before =<< trim [CODE]
87 set nocp viminfo+=nviminfo
88 set guioptions+=M
89 let $HOME = "/does/not/exist"
90 set loadplugins
91 set rtp=Xhere
92 set packpath=Xhere
93 set nomore
94 [CODE]
95
Bram Moolenaarce876aa2017-06-04 17:47:42 +020096 let after = [
97 \ 'quit',
98 \ ]
99 call mkdir('Xhere/plugin', 'p')
100 call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim')
101 call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p')
102 call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim')
103
104 if RunVim(before, after, '')
105
106 let lines = filter(readfile('Xtestout'), '!empty(v:val)')
107 call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0))
108 call assert_match('autoloaded foo', get(lines, 1))
109 endif
110
111 call delete('Xtestout')
112 call delete('Xhere', 'rf')
113endfunc
114
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200115func Test_help_arg()
Bram Moolenaar3321e9d2016-08-06 23:03:59 +0200116 if !has('unix') && has('gui')
117 " this doesn't work with gvim on MS-Windows
118 return
119 endif
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200120 if RunVim([], [], '--help >Xtestout')
121 let lines = readfile('Xtestout')
122 call assert_true(len(lines) > 20)
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200123 call assert_match('Vi IMproved', lines[0])
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200124
125 " check if couple of lines are there
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200126 let found = []
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200127 for line in lines
128 if line =~ '-R.*Readonly mode'
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200129 call add(found, 'Readonly mode')
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200130 endif
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200131 " Watch out for a second --version line in the Gnome version.
132 if line =~ '--version.*Print version information and exit'
133 call add(found, "--version")
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200134 endif
135 endfor
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200136 call assert_equal(['Readonly mode', '--version'], found)
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200137 endif
138 call delete('Xtestout')
139endfunc
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200140
141func Test_compatible_args()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200142 let after =<< trim [CODE]
143 call writefile([string(&compatible)], "Xtestout")
144 set viminfo+=nviminfo
145 quit
146 [CODE]
147
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200148 if RunVim([], after, '-C')
149 let lines = readfile('Xtestout')
150 call assert_equal('1', lines[0])
151 endif
152
153 if RunVim([], after, '-N')
154 let lines = readfile('Xtestout')
155 call assert_equal('0', lines[0])
156 endif
157
158 call delete('Xtestout')
159endfunc
160
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200161" Test the -o[N] and -O[N] arguments to open N windows split
162" horizontally or vertically.
163func Test_o_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200164 let after =<< trim [CODE]
Bram Moolenaare96a2492019-06-25 04:12:16 +0200165 set cpo&vim
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200166 call writefile([winnr("$"),
167 \ winheight(1), winheight(2), &lines,
168 \ winwidth(1), winwidth(2), &columns,
169 \ bufname(winbufnr(1)), bufname(winbufnr(2))],
170 \ "Xtestout")
171 qall
172 [CODE]
173
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200174 if RunVim([], after, '-o2')
175 " Open 2 windows split horizontally. Expect:
176 " - 2 windows
177 " - both windows should have the same or almost the same height
178 " - sum of both windows height (+ 3 for both statusline and Ex command)
179 " should be equal to the number of lines
180 " - both windows should have the same width which should be equal to the
181 " number of columns
182 " - buffer of both windows should have no name
183 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
184 call assert_equal('2', wn)
185 call assert_inrange(0, 1, wh1 - wh2)
186 call assert_equal(string(wh1 + wh2 + 3), ln)
187 call assert_equal(ww1, ww2)
188 call assert_equal(ww1, cn)
189 call assert_equal('', bn1)
190 call assert_equal('', bn2)
191 endif
192
193 if RunVim([], after, '-o foo bar')
194 " Same expectations as for -o2 but buffer names should be foo and bar
195 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
196 call assert_equal('2', wn)
197 call assert_inrange(0, 1, wh1 - wh2)
198 call assert_equal(string(wh1 + wh2 + 3), ln)
199 call assert_equal(ww1, ww2)
200 call assert_equal(ww1, cn)
201 call assert_equal('foo', bn1)
202 call assert_equal('bar', bn2)
203 endif
204
205 if RunVim([], after, '-O2')
206 " Open 2 windows split vertically. Expect:
207 " - 2 windows
208 " - both windows should have the same or almost the same width
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200209 " - sum of both windows width (+ 1 for the separator) should be equal to
210 " the number of columns
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200211 " - both windows should have the same height
212 " - window height (+ 2 for the statusline and Ex command) should be equal
213 " to the number of lines
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200214 " - buffer of both windows should have no name
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200215 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
216 call assert_equal('2', wn)
217 call assert_inrange(0, 1, ww1 - ww2)
218 call assert_equal(string(ww1 + ww2 + 1), cn)
219 call assert_equal(wh1, wh2)
220 call assert_equal(string(wh1 + 2), ln)
221 call assert_equal('', bn1)
222 call assert_equal('', bn2)
223 endif
224
225 if RunVim([], after, '-O foo bar')
226 " Same expectations as for -O2 but buffer names should be foo and bar
227 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
228 call assert_equal('2', wn)
229 call assert_inrange(0, 1, ww1 - ww2)
230 call assert_equal(string(ww1 + ww2 + 1), cn)
231 call assert_equal(wh1, wh2)
232 call assert_equal(string(wh1 + 2), ln)
233 call assert_equal('foo', bn1)
234 call assert_equal('bar', bn2)
235 endif
236
237 call delete('Xtestout')
238endfunc
239
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200240" Test the -p[N] argument to open N tabpages.
241func Test_p_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200242 let after =<< trim [CODE]
243 call writefile(split(execute("tabs"), "\n"), "Xtestout")
244 qall
245 [CODE]
246
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200247 if RunVim([], after, '-p2')
248 let lines = readfile('Xtestout')
249 call assert_equal(4, len(lines))
250 call assert_equal('Tab page 1', lines[0])
251 call assert_equal('> [No Name]', lines[1])
252 call assert_equal('Tab page 2', lines[2])
253 call assert_equal(' [No Name]', lines[3])
254 endif
255
256 if RunVim([], after, '-p foo bar')
257 let lines = readfile('Xtestout')
258 call assert_equal(4, len(lines))
259 call assert_equal('Tab page 1', lines[0])
260 call assert_equal('> foo', lines[1])
261 call assert_equal('Tab page 2', lines[2])
262 call assert_equal(' bar', lines[3])
263 endif
264
265 call delete('Xtestout')
266endfunc
267
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200268" Test the -V[N] argument to set the 'verbose' option to [N]
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200269func Test_V_arg()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200270 " Can't catch the output of gvim.
271 CheckNotGui
272
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200273 let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq')
274 call assert_equal(" verbose=0\n", out)
275
276 let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq')
Bram Moolenaar7779ee32020-05-03 17:55:32 +0200277 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline \\d\\+: sourcing \"[\\./]*runtime[\\/]filetype\.vim\".*\n", out)
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200278 call assert_match(" verbose=2\n", out)
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200279
280 let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq')
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200281 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 +0200282endfunc
283
Bram Moolenaar54948182018-12-28 18:32:56 +0100284" Test the '-q [errorfile]' argument.
285func Test_q_arg()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100286 CheckFeature quickfix
287
Bram Moolenaar54948182018-12-28 18:32:56 +0100288 let source_file = has('win32') ? '..\memfile.c' : '../memfile.c'
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200289 let after =<< trim [CODE]
290 call writefile([&errorfile, string(getpos("."))], "Xtestout")
291 copen
292 w >> Xtestout
293 qall
294 [CODE]
Bram Moolenaar54948182018-12-28 18:32:56 +0100295
296 " Test with default argument '-q'.
297 call assert_equal('errors.err', &errorfile)
Bram Moolenaarb58a4b92019-05-27 23:36:21 +0200298 call writefile(["../memfile.c:208:5: error: expected ';' before '}' token"], 'errors.err')
Bram Moolenaar54948182018-12-28 18:32:56 +0100299 if RunVim([], after, '-q')
300 let lines = readfile('Xtestout')
301 call assert_equal(['errors.err',
Bram Moolenaarb58a4b92019-05-27 23:36:21 +0200302 \ '[0, 208, 5, 0]',
303 \ source_file . "|208 col 5| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100304 \ lines)
305 endif
306 call delete('Xtestout')
307 call delete('errors.err')
308
309 " Test with explicit argument '-q Xerrors' (with space).
Bram Moolenaarb58a4b92019-05-27 23:36:21 +0200310 call writefile(["../memfile.c:208:5: error: expected ';' before '}' token"], 'Xerrors')
Bram Moolenaar54948182018-12-28 18:32:56 +0100311 if RunVim([], after, '-q Xerrors')
312 let lines = readfile('Xtestout')
313 call assert_equal(['Xerrors',
Bram Moolenaarb58a4b92019-05-27 23:36:21 +0200314 \ '[0, 208, 5, 0]',
315 \ source_file . "|208 col 5| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100316 \ lines)
317 endif
318 call delete('Xtestout')
319
320 " Test with explicit argument '-qXerrors' (without space).
321 if RunVim([], after, '-qXerrors')
322 let lines = readfile('Xtestout')
323 call assert_equal(['Xerrors',
Bram Moolenaarb58a4b92019-05-27 23:36:21 +0200324 \ '[0, 208, 5, 0]',
325 \ source_file . "|208 col 5| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100326 \ lines)
327 endif
328
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200329 " Test with a non-existing error file (exits with value 3)
330 let out = system(GetVimCommand() .. ' -q xyz.err')
331 call assert_equal(3, v:shell_error)
332
Bram Moolenaar54948182018-12-28 18:32:56 +0100333 call delete('Xtestout')
334 call delete('Xerrors')
335endfunc
336
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200337" Test the -V[N]{filename} argument to set the 'verbose' option to N
338" and set 'verbosefile' to filename.
339func Test_V_file_arg()
Bram Moolenaar4841a7c2018-09-22 14:08:49 +0200340 if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq')
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200341 let out = join(readfile('Xverbosefile'), "\n")
342 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out)
343 call assert_match("\n verbose=2\n", out)
344 call assert_match("\n verbosefile=Xverbosefile", out)
345 endif
346
347 call delete('Xverbosefile')
348endfunc
349
350" Test the -m, -M and -R arguments:
351" -m resets 'write'
352" -M resets 'modifiable' and 'write'
353" -R sets 'readonly'
354func Test_m_M_R()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200355 let after =<< trim [CODE]
356 call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout")
357 qall
358 [CODE]
359
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200360 if RunVim([], after, '')
361 let lines = readfile('Xtestout')
362 call assert_equal(['1', '1', '0', '200'], lines)
363 endif
364 if RunVim([], after, '-m')
365 let lines = readfile('Xtestout')
366 call assert_equal(['0', '1', '0', '200'], lines)
367 endif
368 if RunVim([], after, '-M')
369 let lines = readfile('Xtestout')
370 call assert_equal(['0', '0', '0', '200'], lines)
371 endif
372 if RunVim([], after, '-R')
373 let lines = readfile('Xtestout')
374 call assert_equal(['1', '1', '1', '10000'], lines)
375 endif
376
377 call delete('Xtestout')
378endfunc
379
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200380" Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes).
381func Test_A_F_H_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200382 let after =<< trim [CODE]
383 call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout")
384 qall
385 [CODE]
386
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200387 " Use silent Ex mode to avoid the hit-Enter prompt for the warning that
388 " 'encoding' is not utf-8.
389 if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A')
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200390 let lines = readfile('Xtestout')
391 call assert_equal(['1', '1', '0', '0'], lines)
392 endif
393
394 if has('farsi') && RunVim([], after, '-F')
395 let lines = readfile('Xtestout')
396 call assert_equal(['1', '0', '1', '0'], lines)
397 endif
398
399 if has('rightleft') && RunVim([], after, '-H')
400 let lines = readfile('Xtestout')
401 call assert_equal(['1', '0', '0', '1'], lines)
402 endif
403
404 call delete('Xtestout')
405endfunc
406
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200407func Test_invalid_args()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200408 " must be able to get the output of Vim.
409 CheckUnix
410 CheckNotGui
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200411
412 for opt in ['-Y', '--does-not-exist']
413 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
414 call assert_equal(1, v:shell_error)
415 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
416 call assert_equal('Unknown option argument: "' .. opt .. '"', out[1])
417 call assert_equal('More info with: "vim -h"', out[2])
418 endfor
419
420 for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime']
421 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
422 call assert_equal(1, v:shell_error)
423 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
424 call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
425 call assert_equal('More info with: "vim -h"', out[2])
426 endfor
427
428 if has('clientserver')
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200429 for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr',
430 \ '--remote-tab', '--remote-tab-wait',
431 \ '--remote-tab-wait-silent', '--remote-tab-silent',
432 \ '--remote-wait', '--remote-wait-silent',
Bram Moolenaar27821262019-05-08 16:41:09 +0200433 \ '--servername',
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200434 \ ]
435 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
436 call assert_equal(1, v:shell_error)
437 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
438 call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
439 call assert_equal('More info with: "vim -h"', out[2])
440 endfor
441 endif
442
Bram Moolenaar240f7ab2019-05-08 17:58:15 +0200443 if has('gui_gtk')
Bram Moolenaar27821262019-05-08 16:41:09 +0200444 let out = split(system(GetVimCommand() .. ' --display'), "\n")
445 call assert_equal(1, v:shell_error)
446 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
447 call assert_equal('Argument missing after: "--display"', out[1])
448 call assert_equal('More info with: "vim -h"', out[2])
449 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200450
Bram Moolenaar5416b752019-05-08 18:36:43 +0200451 if has('xterm_clipboard')
Bram Moolenaar240f7ab2019-05-08 17:58:15 +0200452 let out = split(system(GetVimCommand() .. ' -display'), "\n")
453 call assert_equal(1, v:shell_error)
454 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
455 call assert_equal('Argument missing after: "-display"', out[1])
456 call assert_equal('More info with: "vim -h"', out[2])
457 endif
458
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200459 let out = split(system(GetVimCommand() .. ' -ix'), "\n")
460 call assert_equal(1, v:shell_error)
461 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
462 call assert_equal('Garbage after option argument: "-ix"', out[1])
463 call assert_equal('More info with: "vim -h"', out[2])
464
465 let out = split(system(GetVimCommand() .. ' - xxx'), "\n")
466 call assert_equal(1, v:shell_error)
467 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
468 call assert_equal('Too many edit arguments: "xxx"', out[1])
469 call assert_equal('More info with: "vim -h"', out[2])
470
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100471 if has('quickfix')
472 " Detect invalid repeated arguments '-t foo -t foo", '-q foo -q foo'.
473 for opt in ['-t', '-q']
474 let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n")
475 call assert_equal(1, v:shell_error)
476 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
477 call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1])
478 call assert_equal('More info with: "vim -h"', out[2])
479 endfor
480 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200481
482 for opt in [' -cq', ' --cmd q', ' +', ' -S foo']
483 let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n")
484 call assert_equal(1, v:shell_error)
485 " FIXME: The error message given by Vim is not ideal in case of repeated
486 " -S foo since it does not mention -S.
487 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
488 call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1])
489 call assert_equal('More info with: "vim -h"', out[2])
490 endfor
491
Bram Moolenaar27821262019-05-08 16:41:09 +0200492 if has('gui_gtk')
493 for opt in ['--socketid x', '--socketid 0xg']
494 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
495 call assert_equal(1, v:shell_error)
496 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
497 call assert_equal('Invalid argument for: "--socketid"', out[1])
498 call assert_equal('More info with: "vim -h"', out[2])
499 endfor
500 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200501endfunc
502
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200503func Test_file_args()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200504 let after =<< trim [CODE]
505 call writefile(argv(), "Xtestout")
506 qall
507 [CODE]
508
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200509 if RunVim([], after, '')
510 let lines = readfile('Xtestout')
511 call assert_equal(0, len(lines))
512 endif
513
514 if RunVim([], after, 'one')
515 let lines = readfile('Xtestout')
516 call assert_equal(1, len(lines))
517 call assert_equal('one', lines[0])
518 endif
519
520 if RunVim([], after, 'one two three')
521 let lines = readfile('Xtestout')
522 call assert_equal(3, len(lines))
523 call assert_equal('one', lines[0])
524 call assert_equal('two', lines[1])
525 call assert_equal('three', lines[2])
526 endif
527
528 if RunVim([], after, 'one -c echo two')
529 let lines = readfile('Xtestout')
530 call assert_equal(2, len(lines))
531 call assert_equal('one', lines[0])
532 call assert_equal('two', lines[1])
533 endif
534
535 if RunVim([], after, 'one -- -c echo two')
536 let lines = readfile('Xtestout')
537 call assert_equal(4, len(lines))
538 call assert_equal('one', lines[0])
539 call assert_equal('-c', lines[1])
540 call assert_equal('echo', lines[2])
541 call assert_equal('two', lines[3])
542 endif
543
544 call delete('Xtestout')
545endfunc
546
547func Test_startuptime()
548 if !has('startuptime')
549 return
550 endif
551 let after = ['qall']
552 if RunVim([], after, '--startuptime Xtestout one')
553 let lines = readfile('Xtestout')
554 let expected = ['--- VIM STARTING ---', 'parsing arguments',
555 \ 'shell init', 'inits 3', 'start termcap', 'opening buffers']
556 let found = []
557 for line in lines
558 for exp in expected
559 if line =~ exp
560 call add(found, exp)
561 endif
562 endfor
563 endfor
564 call assert_equal(expected, found)
565 endif
566 call delete('Xtestout')
567endfunc
Bram Moolenaar3a938382016-08-07 16:36:40 +0200568
569func Test_read_stdin()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200570 let after =<< trim [CODE]
571 write Xtestout
572 quit!
573 [CODE]
574
Bram Moolenaar3a938382016-08-07 16:36:40 +0200575 if RunVimPiped([], after, '-', 'echo something | ')
576 let lines = readfile('Xtestout')
Bram Moolenaare4a76ad2016-08-07 16:50:10 +0200577 " MS-Windows adds a space after the word
578 call assert_equal(['something'], split(lines[0]))
Bram Moolenaar3a938382016-08-07 16:36:40 +0200579 endif
580 call delete('Xtestout')
581endfunc
Bram Moolenaar08cab962017-03-04 14:37:18 +0100582
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +0100583func Test_set_shell()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200584 let after =<< trim [CODE]
585 call writefile([&shell], "Xtestout")
586 quit!
587 [CODE]
588
Bram Moolenaar2efc44b2019-10-05 12:09:32 +0200589 if has('win32')
590 let $SHELL = 'C:\with space\cmd.exe'
591 let expected = '"C:\with space\cmd.exe"'
592 else
593 let $SHELL = '/bin/with space/sh'
594 let expected = '/bin/with\ space/sh'
595 endif
596
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +0100597 if RunVimPiped([], after, '', '')
598 let lines = readfile('Xtestout')
Bram Moolenaar2efc44b2019-10-05 12:09:32 +0200599 call assert_equal(expected, lines[0])
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +0100600 endif
601 call delete('Xtestout')
602endfunc
603
Bram Moolenaar08cab962017-03-04 14:37:18 +0100604func Test_progpath()
605 " Tests normally run with "./vim" or "../vim", these must have been expanded
606 " to a full path.
607 if has('unix')
608 call assert_equal('/', v:progpath[0])
609 elseif has('win32')
610 call assert_equal(':', v:progpath[1])
611 call assert_match('[/\\]', v:progpath[2])
612 endif
613
614 " Only expect "vim" to appear in v:progname.
615 call assert_match('vim\c', v:progname)
616endfunc
Bram Moolenaard5d37532017-03-27 23:02:07 +0200617
618func Test_silent_ex_mode()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200619 " must be able to get the output of Vim.
620 CheckUnix
621 CheckNotGui
Bram Moolenaard5d37532017-03-27 23:02:07 +0200622
623 " This caused an ml_get error.
624 let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq')
625 call assert_notmatch('E315:', out)
626endfunc
Bram Moolenaar85045a72017-04-02 16:54:09 +0200627
628func Test_default_term()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200629 " must be able to get the output of Vim.
630 CheckUnix
631 CheckNotGui
Bram Moolenaar85045a72017-04-02 16:54:09 +0200632
633 let save_term = $TERM
Bram Moolenaar08f88b12017-04-02 17:21:16 +0200634 let $TERM = 'unknownxxx'
Bram Moolenaar85045a72017-04-02 16:54:09 +0200635 let out = system(GetVimCommand() . ' -c''set term'' -c cq')
636 call assert_match("defaulting to 'ansi'", out)
637 let $TERM = save_term
638endfunc
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200639
640func Test_zzz_startinsert()
641 " Test :startinsert
642 call writefile(['123456'], 'Xtestout')
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200643 let after =<< trim [CODE]
644 :startinsert
645 call feedkeys("foobar\<c-o>:wq\<cr>","t")
646 [CODE]
647
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200648 if RunVim([], after, 'Xtestout')
649 let lines = readfile('Xtestout')
650 call assert_equal(['foobar123456'], lines)
651 endif
652 " Test :startinsert!
653 call writefile(['123456'], 'Xtestout')
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200654 let after =<< trim [CODE]
655 :startinsert!
656 call feedkeys("foobar\<c-o>:wq\<cr>","t")
657 [CODE]
658
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200659 if RunVim([], after, 'Xtestout')
660 let lines = readfile('Xtestout')
661 call assert_equal(['123456foobar'], lines)
662 endif
663 call delete('Xtestout')
664endfunc
Bram Moolenaar97c2c052019-02-22 13:42:07 +0100665
666func Test_issue_3969()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200667 " Can't catch the output of gvim.
668 CheckNotGui
669
Bram Moolenaar97c2c052019-02-22 13:42:07 +0100670 " Check that message is not truncated.
671 let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq')
672 call assert_equal('hello', out)
673endfunc
Bram Moolenaarc75e8122019-04-21 15:55:10 +0200674
675func Test_start_with_tabs()
676 if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +0200677 throw 'Skipped: cannot make screendumps'
Bram Moolenaarc75e8122019-04-21 15:55:10 +0200678 endif
679
680 let buf = RunVimInTerminal('-p a b c', {})
681 call VerifyScreenDump(buf, 'Test_start_with_tabs', {})
682
683 " clean up
684 call StopVimInTerminal(buf)
685endfunc
Bram Moolenaar69bf6342019-10-29 04:16:57 +0100686
687func Test_v_argv()
688 " Can't catch the output of gvim.
689 CheckNotGui
690
691 let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q')
692 let list = out->split("', '")
693 call assert_match('vim', list[0])
694 let idx = index(list, 'arg1')
695 call assert_true(idx > 2)
696 call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:])
697endfunc
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200698
699" Test for the "-r" recovery mode option
700func Test_r_arg()
701 " Can't catch the output of gvim.
702 CheckNotGui
703 CheckUnix
704 CheckEnglish
705 let cmd = GetVimCommand()
706 " There can be swap files anywhere, only check for the headers.
707 let expected =<< trim END
708 Swap files found:.*
709 In current directory:.*
710 In directory \~/tmp:.*
711 In directory /var/tmp:.*
712 In directory /tmp:.*
713 END
714 call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', ''))
715endfunc
716
717" Test for the '-t' option to jump to a tag
718func Test_t_arg()
719 let before =<< trim [CODE]
720 set tags=Xtags
721 [CODE]
722 let after =<< trim [CODE]
723 let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.')
724 call writefile([s], "Xtestout")
725 qall
726 [CODE]
727
728 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
729 \ "first\tXfile1\t/^ \\zsfirst$/",
730 \ "second\tXfile1\t/^ \\zssecond$/",
731 \ "third\tXfile1\t/^ \\zsthird$/"],
732 \ 'Xtags')
733 call writefile([' first', ' second', ' third'], 'Xfile1')
734
735 if RunVim(before, after, '-t second')
736 call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'))
737 call delete('Xtestout')
738 endif
739
740 call delete('Xtags')
741 call delete('Xfile1')
742endfunc
743
744" Test for entering the insert mode on startup
745func Test_start_insertmode()
746 let before =<< trim [CODE]
747 set insertmode
748 [CODE]
749 let after =<< trim [CODE]
750 call writefile(['insertmode=' .. &insertmode], 'Xtestout')
751 qall
752 [CODE]
753 if RunVim(before, after, '')
754 call assert_equal(['insertmode=1'], readfile('Xtestout'))
755 call delete('Xtestout')
756 endif
757endfunc
758
759" Test for enabling the binary mode on startup
760func Test_b_arg()
761 let after =<< trim [CODE]
762 call writefile(['binary=' .. &binary], 'Xtestout')
763 qall
764 [CODE]
765 if RunVim([], after, '-b')
766 call assert_equal(['binary=1'], readfile('Xtestout'))
767 call delete('Xtestout')
768 endif
769endfunc
770
771" Test for enabling the lisp mode on startup
772func Test_l_arg()
773 let after =<< trim [CODE]
774 let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch
775 call writefile([s], 'Xtestout')
776 qall
777 [CODE]
778 if RunVim([], after, '-l')
779 call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout'))
780 call delete('Xtestout')
781 endif
782endfunc
783
784" Test for specifying a non-existing vimrc file using "-u"
785func Test_missing_vimrc()
786 if !CanRunVimInTerminal()
787 throw 'Skipped: cannot run vim in terminal'
788 endif
789 let after =<< trim [CODE]
790 call assert_match('^E282:', v:errmsg)
791 call writefile(v:errors, 'Xtestout')
792 [CODE]
793 call writefile(after, 'Xafter')
794
795 let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter'
796 let buf = term_start(cmd, {'term_rows' : 10})
797 call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200798 call TermWait(buf)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200799 call term_sendkeys(buf, "\n:")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200800 call TermWait(buf)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200801 call WaitForAssert({-> assert_match(':', term_getline(buf, 10))})
802 call StopVimInTerminal(buf)
803 call assert_equal([], readfile('Xtestout'))
804 call delete('Xafter')
805 call delete('Xtestout')
806endfunc
807
808" Test for using the $VIMINIT environment variable
809func Test_VIMINIT()
810 let after =<< trim [CODE]
811 call assert_equal(1, exists('viminit_found'))
812 call assert_equal('yes', viminit_found)
813 call writefile(v:errors, 'Xtestout')
814 qall
815 [CODE]
816 call writefile(after, 'Xafter')
817 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
818 call setenv('VIMINIT', 'let viminit_found="yes"')
819 exe "silent !" . cmd
820 call assert_equal([], readfile('Xtestout'))
821 call delete('Xtestout')
822 call delete('Xafter')
823endfunc
824
825" Test for using the $EXINIT environment variable
826func Test_EXINIT()
827 let after =<< trim [CODE]
828 call assert_equal(1, exists('exinit_found'))
829 call assert_equal('yes', exinit_found)
830 call writefile(v:errors, 'Xtestout')
831 qall
832 [CODE]
833 call writefile(after, 'Xafter')
834 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
835 call setenv('EXINIT', 'let exinit_found="yes"')
836 exe "silent !" . cmd
837 call assert_equal([], readfile('Xtestout'))
838 call delete('Xtestout')
839 call delete('Xafter')
840endfunc
841
842" Test for using the 'exrc' option
843func Test_exrc()
844 let after =<< trim [CODE]
845 call assert_equal(1, &exrc)
846 call assert_equal(1, &secure)
847 call assert_equal(37, exrc_found)
848 call writefile(v:errors, 'Xtestout')
849 qall
850 [CODE]
851 call mkdir('Xdir')
852 call writefile(['let exrc_found=37'], 'Xdir/.exrc')
853 call writefile(after, 'Xdir/Xafter')
854 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xdir" --cmd "set enc=utf8 exrc secure"'
855 exe "silent !" . cmd
856 call assert_equal([], readfile('Xdir/Xtestout'))
857 call delete('Xdir', 'rf')
858endfunc
859
860" Test for starting Vim with a non-terminal as input/output
861func Test_io_not_a_terminal()
862 " Can't catch the output of gvim.
863 CheckNotGui
864 CheckUnix
865 CheckEnglish
866 let l = systemlist(GetVimProg() .. ' --ttyfail')
867 call assert_equal(['Vim: Warning: Output is not to a terminal',
868 \ 'Vim: Warning: Input is not from a terminal'], l)
869endfunc
870
871" Test for the "-w scriptout" argument
872func Test_w_arg()
873 " Can't catch the output of gvim.
874 CheckNotGui
875 call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'b')
876 if RunVim([], [], '-s Xscriptin -w Xscriptout')
877 call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout'))
878 call delete('Xscriptout')
879 endif
880 call delete('Xscriptin')
881
882 " Test for failing to open the script output file. This test works only when
883 " the language is English.
884 if v:lang == "C" || v:lang =~ '^[Ee]n'
885 call mkdir("Xdir")
886 let m = system(GetVimCommand() .. " -w Xdir")
887 call assert_equal("Cannot open for script output: \"Xdir\"\n", m)
888 call delete("Xdir", 'rf')
889 endif
890endfunc
891
892" Test for the "-s scriptin" argument
893func Test_s_arg()
894 " Can't catch the output of gvim.
895 CheckNotGui
896 CheckEnglish
897 " Test for failing to open the script input file.
898 let m = system(GetVimCommand() .. " -s abcxyz")
899 call assert_equal("Cannot open for reading: \"abcxyz\"\n", m)
900
901 call writefile([], 'Xinput')
902 let m = system(GetVimCommand() .. " -s Xinput -s Xinput")
903 call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m)
904 call delete('Xinput')
905endfunc
906
907" Test for the "-n" (no swap file) argument
908func Test_n_arg()
909 let after =<< trim [CODE]
910 call assert_equal(0, &updatecount)
911 call writefile(v:errors, 'Xtestout')
912 qall
913 [CODE]
914 if RunVim([], after, '-n')
915 call assert_equal([], readfile('Xtestout'))
916 call delete('Xtestout')
917 endif
918 call delete('Xafter')
919endfunc
920
921" Test for the "-h" (help) argument
922func Test_h_arg()
923 " Can't catch the output of gvim.
924 CheckNotGui
925 let l = systemlist(GetVimProg() .. ' -h')
926 call assert_match('^VIM - Vi IMproved', l[0])
927 let l = systemlist(GetVimProg() .. ' -?')
928 call assert_match('^VIM - Vi IMproved', l[0])
929endfunc
930
931" Test for the "-F" (farsi) argument
932func Test_F_arg()
933 " Can't catch the output of gvim.
934 CheckNotGui
935 let l = systemlist(GetVimProg() .. ' -F')
936 call assert_match('^E27:', l[0])
937endfunc
938
939" Test for the "-E" (improved Ex mode) argument
940func Test_E_arg()
941 let after =<< trim [CODE]
942 call assert_equal('cv', mode(1))
943 call writefile(v:errors, 'Xtestout')
944 qall
945 [CODE]
946 if RunVim([], after, '-E')
947 call assert_equal([], readfile('Xtestout'))
948 call delete('Xtestout')
949 endif
950 call delete('Xafter')
951endfunc
952
953" Test for too many edit argument errors
954func Test_too_many_edit_args()
955 " Can't catch the output of gvim.
956 CheckNotGui
957 CheckEnglish
958 let l = systemlist(GetVimProg() .. ' - -')
959 call assert_match('^Too many edit arguments: "-"', l[1])
960endfunc
961
962" vim: shiftwidth=2 sts=2 expandtab