blob: 8f494a8507e267ec5a5a11ee0cbaa8a1d2f06958 [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 Moolenaar66459b72016-08-06 19:01:55 +02005
6" Check that loading startup.vim works.
Bram Moolenaarb9a46fe2016-07-29 18:13:42 +02007func Test_startup_script()
8 set compatible
9 source $VIMRUNTIME/defaults.vim
10
11 call assert_equal(0, &compatible)
12endfunc
Bram Moolenaar66459b72016-08-06 19:01:55 +020013
14" Verify the order in which plugins are loaded:
15" 1. plugins in non-after directories
16" 2. packages
17" 3. plugins in after directories
18func Test_after_comes_later()
Bram Moolenaar32860432016-08-06 19:24:23 +020019 if !has('packages')
20 return
21 endif
Bram Moolenaar66459b72016-08-06 19:01:55 +020022 let before = [
Bram Moolenaar446cce62016-08-06 21:37:27 +020023 \ 'set nocp viminfo+=nviminfo',
24 \ 'set guioptions+=M',
Bram Moolenaar66459b72016-08-06 19:01:55 +020025 \ 'let $HOME = "/does/not/exist"',
26 \ 'set loadplugins',
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020027 \ 'set rtp=Xhere,Xafter,Xanother',
Bram Moolenaar66459b72016-08-06 19:01:55 +020028 \ 'set packpath=Xhere,Xafter',
29 \ 'set nomore',
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020030 \ 'let g:sequence = ""',
Bram Moolenaar66459b72016-08-06 19:01:55 +020031 \ ]
32 let after = [
33 \ 'redir! > Xtestout',
34 \ 'scriptnames',
35 \ 'redir END',
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020036 \ 'redir! > Xsequence',
37 \ 'echo g:sequence',
38 \ 'redir END',
Bram Moolenaar66459b72016-08-06 19:01:55 +020039 \ 'quit',
40 \ ]
41 call mkdir('Xhere/plugin', 'p')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020042 call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim')
43 call mkdir('Xanother/plugin', 'p')
44 call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020045 call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020046 call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020047
48 call mkdir('Xafter/plugin', 'p')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020049 call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020050
Bram Moolenaar472a0a82016-08-06 22:31:42 +020051 if RunVim(before, after, '')
Bram Moolenaar66459b72016-08-06 19:01:55 +020052
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020053 let lines = readfile('Xtestout')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020054 let expected = ['Xbefore.vim', 'here.vim', 'another.vim', 'foo.vim', 'later.vim', 'Xafter.vim']
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020055 let found = []
56 for line in lines
57 for one in expected
58 if line =~ one
59 call add(found, one)
60 endif
61 endfor
Bram Moolenaar66459b72016-08-06 19:01:55 +020062 endfor
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020063 call assert_equal(expected, found)
64 endif
Bram Moolenaar66459b72016-08-06 19:01:55 +020065
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020066 call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', ''))
67
Bram Moolenaar66459b72016-08-06 19:01:55 +020068 call delete('Xtestout')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020069 call delete('Xsequence')
Bram Moolenaar66459b72016-08-06 19:01:55 +020070 call delete('Xhere', 'rf')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020071 call delete('Xanother', 'rf')
Bram Moolenaar66459b72016-08-06 19:01:55 +020072 call delete('Xafter', 'rf')
73endfunc
Bram Moolenaar472a0a82016-08-06 22:31:42 +020074
Bram Moolenaarce876aa2017-06-04 17:47:42 +020075func Test_pack_in_rtp_when_plugins_run()
76 if !has('packages')
77 return
78 endif
79 let before = [
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 \ ]
88 let after = [
89 \ 'quit',
90 \ ]
91 call mkdir('Xhere/plugin', 'p')
92 call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim')
93 call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p')
94 call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim')
95
96 if RunVim(before, after, '')
97
98 let lines = filter(readfile('Xtestout'), '!empty(v:val)')
99 call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0))
100 call assert_match('autoloaded foo', get(lines, 1))
101 endif
102
103 call delete('Xtestout')
104 call delete('Xhere', 'rf')
105endfunc
106
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200107func Test_help_arg()
Bram Moolenaar3321e9d2016-08-06 23:03:59 +0200108 if !has('unix') && has('gui')
109 " this doesn't work with gvim on MS-Windows
110 return
111 endif
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200112 if RunVim([], [], '--help >Xtestout')
113 let lines = readfile('Xtestout')
114 call assert_true(len(lines) > 20)
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200115 call assert_match('Vi IMproved', lines[0])
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200116
117 " check if couple of lines are there
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200118 let found = []
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200119 for line in lines
120 if line =~ '-R.*Readonly mode'
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200121 call add(found, 'Readonly mode')
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200122 endif
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200123 " Watch out for a second --version line in the Gnome version.
124 if line =~ '--version.*Print version information and exit'
125 call add(found, "--version")
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200126 endif
127 endfor
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200128 call assert_equal(['Readonly mode', '--version'], found)
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200129 endif
130 call delete('Xtestout')
131endfunc
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200132
133func Test_compatible_args()
134 let after = [
135 \ 'call writefile([string(&compatible)], "Xtestout")',
136 \ 'set viminfo+=nviminfo',
137 \ 'quit',
138 \ ]
139 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()
155 let after = [
156 \ 'call writefile([winnr("$"),
157 \ winheight(1), winheight(2), &lines,
158 \ winwidth(1), winwidth(2), &columns,
159 \ bufname(winbufnr(1)), bufname(winbufnr(2))],
160 \ "Xtestout")',
161 \ 'qall',
162 \ ]
163 if RunVim([], after, '-o2')
164 " Open 2 windows split horizontally. Expect:
165 " - 2 windows
166 " - both windows should have the same or almost the same height
167 " - sum of both windows height (+ 3 for both statusline and Ex command)
168 " should be equal to the number of lines
169 " - both windows should have the same width which should be equal to the
170 " number of columns
171 " - buffer of both windows should have no name
172 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
173 call assert_equal('2', wn)
174 call assert_inrange(0, 1, wh1 - wh2)
175 call assert_equal(string(wh1 + wh2 + 3), ln)
176 call assert_equal(ww1, ww2)
177 call assert_equal(ww1, cn)
178 call assert_equal('', bn1)
179 call assert_equal('', bn2)
180 endif
181
182 if RunVim([], after, '-o foo bar')
183 " Same expectations as for -o2 but buffer names should be foo and bar
184 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
185 call assert_equal('2', wn)
186 call assert_inrange(0, 1, wh1 - wh2)
187 call assert_equal(string(wh1 + wh2 + 3), ln)
188 call assert_equal(ww1, ww2)
189 call assert_equal(ww1, cn)
190 call assert_equal('foo', bn1)
191 call assert_equal('bar', bn2)
192 endif
193
194 if RunVim([], after, '-O2')
195 " Open 2 windows split vertically. Expect:
196 " - 2 windows
197 " - both windows should have the same or almost the same width
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200198 " - sum of both windows width (+ 1 for the separator) should be equal to
199 " the number of columns
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200200 " - both windows should have the same height
201 " - window height (+ 2 for the statusline and Ex command) should be equal
202 " to the number of lines
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200203 " - buffer of both windows should have no name
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200204 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
205 call assert_equal('2', wn)
206 call assert_inrange(0, 1, ww1 - ww2)
207 call assert_equal(string(ww1 + ww2 + 1), cn)
208 call assert_equal(wh1, wh2)
209 call assert_equal(string(wh1 + 2), ln)
210 call assert_equal('', bn1)
211 call assert_equal('', bn2)
212 endif
213
214 if RunVim([], after, '-O foo bar')
215 " Same expectations as for -O2 but buffer names should be foo and bar
216 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
217 call assert_equal('2', wn)
218 call assert_inrange(0, 1, ww1 - ww2)
219 call assert_equal(string(ww1 + ww2 + 1), cn)
220 call assert_equal(wh1, wh2)
221 call assert_equal(string(wh1 + 2), ln)
222 call assert_equal('foo', bn1)
223 call assert_equal('bar', bn2)
224 endif
225
226 call delete('Xtestout')
227endfunc
228
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200229" Test the -p[N] argument to open N tabpages.
230func Test_p_arg()
231 let after = [
232 \ 'call writefile(split(execute("tabs"), "\n"), "Xtestout")',
233 \ 'qall',
234 \ ]
235 if RunVim([], after, '-p2')
236 let lines = readfile('Xtestout')
237 call assert_equal(4, len(lines))
238 call assert_equal('Tab page 1', lines[0])
239 call assert_equal('> [No Name]', lines[1])
240 call assert_equal('Tab page 2', lines[2])
241 call assert_equal(' [No Name]', lines[3])
242 endif
243
244 if RunVim([], after, '-p foo bar')
245 let lines = readfile('Xtestout')
246 call assert_equal(4, len(lines))
247 call assert_equal('Tab page 1', lines[0])
248 call assert_equal('> foo', lines[1])
249 call assert_equal('Tab page 2', lines[2])
250 call assert_equal(' bar', lines[3])
251 endif
252
253 call delete('Xtestout')
254endfunc
255
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200256" Test the -V[N] argument to set the 'verbose' option to [N]
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200257func Test_V_arg()
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200258 if has('gui_running')
259 " Can't catch the output of gvim.
260 return
261 endif
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200262 let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq')
263 call assert_equal(" verbose=0\n", out)
264
265 let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq')
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200266 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nSearching for \"filetype\.vim\".*\n", out)
267 call assert_match(" verbose=2\n", out)
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200268
269 let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq')
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200270 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 +0200271endfunc
272
Bram Moolenaar54948182018-12-28 18:32:56 +0100273" Test the '-q [errorfile]' argument.
274func Test_q_arg()
275 let source_file = has('win32') ? '..\memfile.c' : '../memfile.c'
276 let after = [
277 \ 'call writefile([&errorfile, string(getpos("."))], "Xtestout")',
278 \ 'copen',
279 \ 'w >> Xtestout',
280 \ 'qall'
281 \ ]
282
283 " Test with default argument '-q'.
284 call assert_equal('errors.err', &errorfile)
285 call writefile(["../memfile.c:1482:5: error: expected ';' before '}' token"], 'errors.err')
286 if RunVim([], after, '-q')
287 let lines = readfile('Xtestout')
288 call assert_equal(['errors.err',
289 \ '[0, 1482, 5, 0]',
290 \ source_file . "|1482 col 5| error: expected ';' before '}' token"],
291 \ lines)
292 endif
293 call delete('Xtestout')
294 call delete('errors.err')
295
296 " Test with explicit argument '-q Xerrors' (with space).
297 call writefile(["../memfile.c:1482:5: error: expected ';' before '}' token"], 'Xerrors')
298 if RunVim([], after, '-q Xerrors')
299 let lines = readfile('Xtestout')
300 call assert_equal(['Xerrors',
301 \ '[0, 1482, 5, 0]',
302 \ source_file . "|1482 col 5| error: expected ';' before '}' token"],
303 \ lines)
304 endif
305 call delete('Xtestout')
306
307 " Test with explicit argument '-qXerrors' (without space).
308 if RunVim([], after, '-qXerrors')
309 let lines = readfile('Xtestout')
310 call assert_equal(['Xerrors',
311 \ '[0, 1482, 5, 0]',
312 \ source_file . "|1482 col 5| error: expected ';' before '}' token"],
313 \ lines)
314 endif
315
316 call delete('Xtestout')
317 call delete('Xerrors')
318endfunc
319
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200320" Test the -V[N]{filename} argument to set the 'verbose' option to N
321" and set 'verbosefile' to filename.
322func Test_V_file_arg()
Bram Moolenaar4841a7c2018-09-22 14:08:49 +0200323 if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq')
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200324 let out = join(readfile('Xverbosefile'), "\n")
325 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out)
326 call assert_match("\n verbose=2\n", out)
327 call assert_match("\n verbosefile=Xverbosefile", out)
328 endif
329
330 call delete('Xverbosefile')
331endfunc
332
333" Test the -m, -M and -R arguments:
334" -m resets 'write'
335" -M resets 'modifiable' and 'write'
336" -R sets 'readonly'
337func Test_m_M_R()
338 let after = [
339 \ 'call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout")',
340 \ 'qall',
341 \ ]
342 if RunVim([], after, '')
343 let lines = readfile('Xtestout')
344 call assert_equal(['1', '1', '0', '200'], lines)
345 endif
346 if RunVim([], after, '-m')
347 let lines = readfile('Xtestout')
348 call assert_equal(['0', '1', '0', '200'], lines)
349 endif
350 if RunVim([], after, '-M')
351 let lines = readfile('Xtestout')
352 call assert_equal(['0', '0', '0', '200'], lines)
353 endif
354 if RunVim([], after, '-R')
355 let lines = readfile('Xtestout')
356 call assert_equal(['1', '1', '1', '10000'], lines)
357 endif
358
359 call delete('Xtestout')
360endfunc
361
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200362" Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes).
363func Test_A_F_H_arg()
364 let after = [
365 \ 'call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout")',
366 \ 'qall',
367 \ ]
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200368 " Use silent Ex mode to avoid the hit-Enter prompt for the warning that
369 " 'encoding' is not utf-8.
370 if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A')
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200371 let lines = readfile('Xtestout')
372 call assert_equal(['1', '1', '0', '0'], lines)
373 endif
374
375 if has('farsi') && RunVim([], after, '-F')
376 let lines = readfile('Xtestout')
377 call assert_equal(['1', '0', '1', '0'], lines)
378 endif
379
380 if has('rightleft') && RunVim([], after, '-H')
381 let lines = readfile('Xtestout')
382 call assert_equal(['1', '0', '0', '1'], lines)
383 endif
384
385 call delete('Xtestout')
386endfunc
387
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200388func Test_invalid_args()
389 if !has('unix') || has('gui_running')
390 " can't get output of Vim.
391 return
392 endif
393
394 for opt in ['-Y', '--does-not-exist']
395 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
396 call assert_equal(1, v:shell_error)
397 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
398 call assert_equal('Unknown option argument: "' .. opt .. '"', out[1])
399 call assert_equal('More info with: "vim -h"', out[2])
400 endfor
401
402 for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime']
403 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
404 call assert_equal(1, v:shell_error)
405 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
406 call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
407 call assert_equal('More info with: "vim -h"', out[2])
408 endfor
409
410 if has('clientserver')
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200411 for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr',
412 \ '--remote-tab', '--remote-tab-wait',
413 \ '--remote-tab-wait-silent', '--remote-tab-silent',
414 \ '--remote-wait', '--remote-wait-silent',
Bram Moolenaar27821262019-05-08 16:41:09 +0200415 \ '--servername',
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200416 \ ]
417 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
418 call assert_equal(1, v:shell_error)
419 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
420 call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
421 call assert_equal('More info with: "vim -h"', out[2])
422 endfor
423 endif
424
Bram Moolenaar240f7ab2019-05-08 17:58:15 +0200425 if has('gui_gtk')
Bram Moolenaar27821262019-05-08 16:41:09 +0200426 let out = split(system(GetVimCommand() .. ' --display'), "\n")
427 call assert_equal(1, v:shell_error)
428 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
429 call assert_equal('Argument missing after: "--display"', out[1])
430 call assert_equal('More info with: "vim -h"', out[2])
431 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200432
Bram Moolenaar5416b752019-05-08 18:36:43 +0200433 if has('xterm_clipboard')
Bram Moolenaar240f7ab2019-05-08 17:58:15 +0200434 let out = split(system(GetVimCommand() .. ' -display'), "\n")
435 call assert_equal(1, v:shell_error)
436 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
437 call assert_equal('Argument missing after: "-display"', out[1])
438 call assert_equal('More info with: "vim -h"', out[2])
439 endif
440
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200441 let out = split(system(GetVimCommand() .. ' -ix'), "\n")
442 call assert_equal(1, v:shell_error)
443 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
444 call assert_equal('Garbage after option argument: "-ix"', out[1])
445 call assert_equal('More info with: "vim -h"', out[2])
446
447 let out = split(system(GetVimCommand() .. ' - xxx'), "\n")
448 call assert_equal(1, v:shell_error)
449 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
450 call assert_equal('Too many edit arguments: "xxx"', out[1])
451 call assert_equal('More info with: "vim -h"', out[2])
452
453 " Detect invalid repeated arguments '-t foo -t foo", '-q foo -q foo'.
454 for opt in ['-t', '-q']
455 let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n")
456 call assert_equal(1, v:shell_error)
457 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
458 call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1])
459 call assert_equal('More info with: "vim -h"', out[2])
460 endfor
461
462 for opt in [' -cq', ' --cmd q', ' +', ' -S foo']
463 let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n")
464 call assert_equal(1, v:shell_error)
465 " FIXME: The error message given by Vim is not ideal in case of repeated
466 " -S foo since it does not mention -S.
467 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
468 call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1])
469 call assert_equal('More info with: "vim -h"', out[2])
470 endfor
471
Bram Moolenaar27821262019-05-08 16:41:09 +0200472 if has('gui_gtk')
473 for opt in ['--socketid x', '--socketid 0xg']
474 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
475 call assert_equal(1, v:shell_error)
476 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
477 call assert_equal('Invalid argument for: "--socketid"', out[1])
478 call assert_equal('More info with: "vim -h"', out[2])
479 endfor
480 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200481endfunc
482
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200483func Test_file_args()
484 let after = [
485 \ 'call writefile(argv(), "Xtestout")',
486 \ 'qall',
487 \ ]
488 if RunVim([], after, '')
489 let lines = readfile('Xtestout')
490 call assert_equal(0, len(lines))
491 endif
492
493 if RunVim([], after, 'one')
494 let lines = readfile('Xtestout')
495 call assert_equal(1, len(lines))
496 call assert_equal('one', lines[0])
497 endif
498
499 if RunVim([], after, 'one two three')
500 let lines = readfile('Xtestout')
501 call assert_equal(3, len(lines))
502 call assert_equal('one', lines[0])
503 call assert_equal('two', lines[1])
504 call assert_equal('three', lines[2])
505 endif
506
507 if RunVim([], after, 'one -c echo two')
508 let lines = readfile('Xtestout')
509 call assert_equal(2, len(lines))
510 call assert_equal('one', lines[0])
511 call assert_equal('two', lines[1])
512 endif
513
514 if RunVim([], after, 'one -- -c echo two')
515 let lines = readfile('Xtestout')
516 call assert_equal(4, len(lines))
517 call assert_equal('one', lines[0])
518 call assert_equal('-c', lines[1])
519 call assert_equal('echo', lines[2])
520 call assert_equal('two', lines[3])
521 endif
522
523 call delete('Xtestout')
524endfunc
525
526func Test_startuptime()
527 if !has('startuptime')
528 return
529 endif
530 let after = ['qall']
531 if RunVim([], after, '--startuptime Xtestout one')
532 let lines = readfile('Xtestout')
533 let expected = ['--- VIM STARTING ---', 'parsing arguments',
534 \ 'shell init', 'inits 3', 'start termcap', 'opening buffers']
535 let found = []
536 for line in lines
537 for exp in expected
538 if line =~ exp
539 call add(found, exp)
540 endif
541 endfor
542 endfor
543 call assert_equal(expected, found)
544 endif
545 call delete('Xtestout')
546endfunc
Bram Moolenaar3a938382016-08-07 16:36:40 +0200547
548func Test_read_stdin()
549 let after = [
550 \ 'write Xtestout',
551 \ 'quit!',
552 \ ]
553 if RunVimPiped([], after, '-', 'echo something | ')
554 let lines = readfile('Xtestout')
Bram Moolenaare4a76ad2016-08-07 16:50:10 +0200555 " MS-Windows adds a space after the word
556 call assert_equal(['something'], split(lines[0]))
Bram Moolenaar3a938382016-08-07 16:36:40 +0200557 endif
558 call delete('Xtestout')
559endfunc
Bram Moolenaar08cab962017-03-04 14:37:18 +0100560
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +0100561func Test_set_shell()
562 let after = [
563 \ 'call writefile([&shell], "Xtestout")',
564 \ 'quit!',
565 \ ]
566 let $SHELL = '/bin/with space/sh'
567 if RunVimPiped([], after, '', '')
568 let lines = readfile('Xtestout')
569 " MS-Windows adds a space after the word
570 call assert_equal('/bin/with\ space/sh', lines[0])
571 endif
572 call delete('Xtestout')
573endfunc
574
Bram Moolenaar08cab962017-03-04 14:37:18 +0100575func Test_progpath()
576 " Tests normally run with "./vim" or "../vim", these must have been expanded
577 " to a full path.
578 if has('unix')
579 call assert_equal('/', v:progpath[0])
580 elseif has('win32')
581 call assert_equal(':', v:progpath[1])
582 call assert_match('[/\\]', v:progpath[2])
583 endif
584
585 " Only expect "vim" to appear in v:progname.
586 call assert_match('vim\c', v:progname)
587endfunc
Bram Moolenaard5d37532017-03-27 23:02:07 +0200588
589func Test_silent_ex_mode()
590 if !has('unix') || has('gui_running')
591 " can't get output of Vim.
592 return
593 endif
594
595 " This caused an ml_get error.
596 let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq')
597 call assert_notmatch('E315:', out)
598endfunc
Bram Moolenaar85045a72017-04-02 16:54:09 +0200599
600func Test_default_term()
601 if !has('unix') || has('gui_running')
602 " can't get output of Vim.
603 return
604 endif
605
606 let save_term = $TERM
Bram Moolenaar08f88b12017-04-02 17:21:16 +0200607 let $TERM = 'unknownxxx'
Bram Moolenaar85045a72017-04-02 16:54:09 +0200608 let out = system(GetVimCommand() . ' -c''set term'' -c cq')
609 call assert_match("defaulting to 'ansi'", out)
610 let $TERM = save_term
611endfunc
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200612
613func Test_zzz_startinsert()
614 " Test :startinsert
615 call writefile(['123456'], 'Xtestout')
616 let after = [
617 \ ':startinsert',
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200618 \ 'call feedkeys("foobar\<c-o>:wq\<cr>","t")'
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200619 \ ]
620 if RunVim([], after, 'Xtestout')
621 let lines = readfile('Xtestout')
622 call assert_equal(['foobar123456'], lines)
623 endif
624 " Test :startinsert!
625 call writefile(['123456'], 'Xtestout')
626 let after = [
627 \ ':startinsert!',
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200628 \ 'call feedkeys("foobar\<c-o>:wq\<cr>","t")'
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200629 \ ]
630 if RunVim([], after, 'Xtestout')
631 let lines = readfile('Xtestout')
632 call assert_equal(['123456foobar'], lines)
633 endif
634 call delete('Xtestout')
635endfunc
Bram Moolenaar97c2c052019-02-22 13:42:07 +0100636
637func Test_issue_3969()
638 if has('gui_running')
639 " Can't catch the output of gvim.
640 return
641 endif
642 " Check that message is not truncated.
643 let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq')
644 call assert_equal('hello', out)
645endfunc
Bram Moolenaarc75e8122019-04-21 15:55:10 +0200646
647func Test_start_with_tabs()
648 if !CanRunVimInTerminal()
649 return
650 endif
651
652 let buf = RunVimInTerminal('-p a b c', {})
653 call VerifyScreenDump(buf, 'Test_start_with_tabs', {})
654
655 " clean up
656 call StopVimInTerminal(buf)
657endfunc