blob: e8be19120b64681354df12c2ddd7c9349c83efa1 [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 Moolenaar66459b72016-08-06 19:01:55 +020046 call mkdir('Xhere/plugin', 'p')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020047 call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim')
48 call mkdir('Xanother/plugin', 'p')
49 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
53 call mkdir('Xafter/plugin', 'p')
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 +020075 call delete('Xhere', 'rf')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020076 call delete('Xanother', 'rf')
Bram Moolenaar66459b72016-08-06 19:01:55 +020077 call delete('Xafter', 'rf')
78endfunc
Bram Moolenaar472a0a82016-08-06 22:31:42 +020079
Bram Moolenaarce876aa2017-06-04 17:47:42 +020080func Test_pack_in_rtp_when_plugins_run()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020081 CheckFeature packages
Bram Moolenaarc79745a2019-05-20 22:12:34 +020082 let before =<< trim [CODE]
83 set nocp viminfo+=nviminfo
84 set guioptions+=M
85 let $HOME = "/does/not/exist"
86 set loadplugins
87 set rtp=Xhere
88 set packpath=Xhere
89 set nomore
90 [CODE]
91
Bram Moolenaarce876aa2017-06-04 17:47:42 +020092 let after = [
93 \ 'quit',
94 \ ]
95 call mkdir('Xhere/plugin', 'p')
96 call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim')
97 call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p')
98 call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim')
99
100 if RunVim(before, after, '')
101
102 let lines = filter(readfile('Xtestout'), '!empty(v:val)')
103 call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0))
104 call assert_match('autoloaded foo', get(lines, 1))
105 endif
106
107 call delete('Xtestout')
108 call delete('Xhere', 'rf')
109endfunc
110
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200111func Test_help_arg()
Bram Moolenaar240309c2021-03-14 16:20:37 +0100112 CheckNotMSWindows
113
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200114 if RunVim([], [], '--help >Xtestout')
115 let lines = readfile('Xtestout')
116 call assert_true(len(lines) > 20)
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200117 call assert_match('Vi IMproved', lines[0])
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200118
119 " check if couple of lines are there
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200120 let found = []
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200121 for line in lines
122 if line =~ '-R.*Readonly mode'
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200123 call add(found, 'Readonly mode')
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200124 endif
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200125 " Watch out for a second --version line in the Gnome version.
126 if line =~ '--version.*Print version information and exit'
127 call add(found, "--version")
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200128 endif
129 endfor
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200130 call assert_equal(['Readonly mode', '--version'], found)
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200131 endif
132 call delete('Xtestout')
133endfunc
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200134
135func Test_compatible_args()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200136 let after =<< trim [CODE]
137 call writefile([string(&compatible)], "Xtestout")
138 set viminfo+=nviminfo
139 quit
140 [CODE]
141
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200142 if RunVim([], after, '-C')
143 let lines = readfile('Xtestout')
144 call assert_equal('1', lines[0])
145 endif
146
147 if RunVim([], after, '-N')
148 let lines = readfile('Xtestout')
149 call assert_equal('0', lines[0])
150 endif
151
152 call delete('Xtestout')
153endfunc
154
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200155" Test the -o[N] and -O[N] arguments to open N windows split
156" horizontally or vertically.
157func Test_o_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200158 let after =<< trim [CODE]
Bram Moolenaare96a2492019-06-25 04:12:16 +0200159 set cpo&vim
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200160 call writefile([winnr("$"),
161 \ winheight(1), winheight(2), &lines,
162 \ winwidth(1), winwidth(2), &columns,
163 \ bufname(winbufnr(1)), bufname(winbufnr(2))],
164 \ "Xtestout")
165 qall
166 [CODE]
167
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200168 if RunVim([], after, '-o2')
169 " Open 2 windows split horizontally. Expect:
170 " - 2 windows
171 " - both windows should have the same or almost the same height
172 " - sum of both windows height (+ 3 for both statusline and Ex command)
173 " should be equal to the number of lines
174 " - both windows should have the same width which should be equal to the
175 " number of columns
176 " - buffer of both windows should have no name
177 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
178 call assert_equal('2', wn)
179 call assert_inrange(0, 1, wh1 - wh2)
180 call assert_equal(string(wh1 + wh2 + 3), ln)
181 call assert_equal(ww1, ww2)
182 call assert_equal(ww1, cn)
183 call assert_equal('', bn1)
184 call assert_equal('', bn2)
185 endif
186
187 if RunVim([], after, '-o foo bar')
188 " Same expectations as for -o2 but buffer names should be foo and bar
189 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
190 call assert_equal('2', wn)
191 call assert_inrange(0, 1, wh1 - wh2)
192 call assert_equal(string(wh1 + wh2 + 3), ln)
193 call assert_equal(ww1, ww2)
194 call assert_equal(ww1, cn)
195 call assert_equal('foo', bn1)
196 call assert_equal('bar', bn2)
197 endif
198
199 if RunVim([], after, '-O2')
200 " Open 2 windows split vertically. Expect:
201 " - 2 windows
202 " - both windows should have the same or almost the same width
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200203 " - sum of both windows width (+ 1 for the separator) should be equal to
204 " the number of columns
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200205 " - both windows should have the same height
206 " - window height (+ 2 for the statusline and Ex command) should be equal
207 " to the number of lines
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200208 " - buffer of both windows should have no name
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200209 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
210 call assert_equal('2', wn)
211 call assert_inrange(0, 1, ww1 - ww2)
212 call assert_equal(string(ww1 + ww2 + 1), cn)
213 call assert_equal(wh1, wh2)
214 call assert_equal(string(wh1 + 2), ln)
215 call assert_equal('', bn1)
216 call assert_equal('', bn2)
217 endif
218
219 if RunVim([], after, '-O foo bar')
220 " Same expectations as for -O2 but buffer names should be foo and bar
221 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
222 call assert_equal('2', wn)
223 call assert_inrange(0, 1, ww1 - ww2)
224 call assert_equal(string(ww1 + ww2 + 1), cn)
225 call assert_equal(wh1, wh2)
226 call assert_equal(string(wh1 + 2), ln)
227 call assert_equal('foo', bn1)
228 call assert_equal('bar', bn2)
229 endif
230
231 call delete('Xtestout')
232endfunc
233
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200234" Test the -p[N] argument to open N tabpages.
235func Test_p_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200236 let after =<< trim [CODE]
237 call writefile(split(execute("tabs"), "\n"), "Xtestout")
238 qall
239 [CODE]
240
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200241 if RunVim([], after, '-p2')
242 let lines = readfile('Xtestout')
243 call assert_equal(4, len(lines))
244 call assert_equal('Tab page 1', lines[0])
245 call assert_equal('> [No Name]', lines[1])
246 call assert_equal('Tab page 2', lines[2])
247 call assert_equal(' [No Name]', lines[3])
248 endif
249
250 if RunVim([], after, '-p foo bar')
251 let lines = readfile('Xtestout')
252 call assert_equal(4, len(lines))
253 call assert_equal('Tab page 1', lines[0])
254 call assert_equal('> foo', lines[1])
255 call assert_equal('Tab page 2', lines[2])
256 call assert_equal(' bar', lines[3])
257 endif
258
259 call delete('Xtestout')
260endfunc
261
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200262" Test the -V[N] argument to set the 'verbose' option to [N]
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200263func Test_V_arg()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200264 " Can't catch the output of gvim.
265 CheckNotGui
266
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200267 let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq')
268 call assert_equal(" verbose=0\n", out)
269
270 let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq')
Bram Moolenaar4515bcd2020-05-03 18:21:04 +0200271 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline \\d\\+: sourcing \"[^\"]*runtime[\\/]filetype\.vim\".*\n", out)
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200272 call assert_match(" verbose=2\n", out)
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200273
274 let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq')
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200275 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 +0200276endfunc
277
Bram Moolenaar54948182018-12-28 18:32:56 +0100278" Test the '-q [errorfile]' argument.
279func Test_q_arg()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100280 CheckFeature quickfix
281
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200282 let lines =<< trim END
283 /* some file with an error */
284 main() {
285 functionCall(arg; arg, arg);
286 return 666
287 }
288 END
289 call writefile(lines, 'Xbadfile.c')
290
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200291 let after =<< trim [CODE]
292 call writefile([&errorfile, string(getpos("."))], "Xtestout")
293 copen
294 w >> Xtestout
295 qall
296 [CODE]
Bram Moolenaar54948182018-12-28 18:32:56 +0100297
298 " Test with default argument '-q'.
299 call assert_equal('errors.err', &errorfile)
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200300 call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'errors.err')
Bram Moolenaar54948182018-12-28 18:32:56 +0100301 if RunVim([], after, '-q')
302 let lines = readfile('Xtestout')
303 call assert_equal(['errors.err',
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200304 \ '[0, 4, 12, 0]',
305 \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100306 \ lines)
307 endif
308 call delete('Xtestout')
309 call delete('errors.err')
310
311 " Test with explicit argument '-q Xerrors' (with space).
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200312 call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'Xerrors')
Bram Moolenaar54948182018-12-28 18:32:56 +0100313 if RunVim([], after, '-q Xerrors')
314 let lines = readfile('Xtestout')
315 call assert_equal(['Xerrors',
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
320 call delete('Xtestout')
321
322 " Test with explicit argument '-qXerrors' (without space).
323 if RunVim([], after, '-qXerrors')
324 let lines = readfile('Xtestout')
325 call assert_equal(['Xerrors',
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200326 \ '[0, 4, 12, 0]',
327 \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100328 \ lines)
329 endif
330
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200331 " Test with a non-existing error file (exits with value 3)
332 let out = system(GetVimCommand() .. ' -q xyz.err')
333 call assert_equal(3, v:shell_error)
334
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200335 call delete('Xbadfile.c')
Bram Moolenaar54948182018-12-28 18:32:56 +0100336 call delete('Xtestout')
337 call delete('Xerrors')
338endfunc
339
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200340" Test the -V[N]{filename} argument to set the 'verbose' option to N
341" and set 'verbosefile' to filename.
342func Test_V_file_arg()
Bram Moolenaar4841a7c2018-09-22 14:08:49 +0200343 if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq')
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200344 let out = join(readfile('Xverbosefile'), "\n")
345 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out)
346 call assert_match("\n verbose=2\n", out)
347 call assert_match("\n verbosefile=Xverbosefile", out)
348 endif
349
350 call delete('Xverbosefile')
351endfunc
352
353" Test the -m, -M and -R arguments:
354" -m resets 'write'
355" -M resets 'modifiable' and 'write'
356" -R sets 'readonly'
357func Test_m_M_R()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200358 let after =<< trim [CODE]
359 call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout")
360 qall
361 [CODE]
362
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200363 if RunVim([], after, '')
364 let lines = readfile('Xtestout')
365 call assert_equal(['1', '1', '0', '200'], lines)
366 endif
367 if RunVim([], after, '-m')
368 let lines = readfile('Xtestout')
369 call assert_equal(['0', '1', '0', '200'], lines)
370 endif
371 if RunVim([], after, '-M')
372 let lines = readfile('Xtestout')
373 call assert_equal(['0', '0', '0', '200'], lines)
374 endif
375 if RunVim([], after, '-R')
376 let lines = readfile('Xtestout')
377 call assert_equal(['1', '1', '1', '10000'], lines)
378 endif
379
380 call delete('Xtestout')
381endfunc
382
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200383" Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes).
384func Test_A_F_H_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200385 let after =<< trim [CODE]
386 call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout")
387 qall
388 [CODE]
389
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200390 " Use silent Ex mode to avoid the hit-Enter prompt for the warning that
391 " 'encoding' is not utf-8.
392 if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A')
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200393 let lines = readfile('Xtestout')
394 call assert_equal(['1', '1', '0', '0'], lines)
395 endif
396
397 if has('farsi') && RunVim([], after, '-F')
398 let lines = readfile('Xtestout')
399 call assert_equal(['1', '0', '1', '0'], lines)
400 endif
401
402 if has('rightleft') && RunVim([], after, '-H')
403 let lines = readfile('Xtestout')
404 call assert_equal(['1', '0', '0', '1'], lines)
405 endif
406
407 call delete('Xtestout')
408endfunc
409
Bram Moolenaar240309c2021-03-14 16:20:37 +0100410" Test the --echo-wid argument (for GTK GUI only).
411func Test_echo_wid()
412 CheckCanRunGui
413 CheckFeature gui_gtk
414
415 if RunVim([], [], '-g --echo-wid -cq >Xtest_echo_wid')
416 let lines = readfile('Xtest_echo_wid')
417 call assert_equal(1, len(lines))
418 call assert_match('^WID: \d\+$', lines[0])
419 endif
420
421 call delete('Xtest_echo_wid')
422endfunction
423
424" Test the -reverse and +reverse arguments (for GUI only).
425func Test_reverse()
426 CheckCanRunGui
427 CheckNotMSWindows
428
429 let after =<< trim [CODE]
430 call writefile([&background], "Xtest_reverse")
431 qall
432 [CODE]
433 if RunVim([], after, '-f -g -reverse')
434 let lines = readfile('Xtest_reverse')
435 call assert_equal(['dark'], lines)
436 endif
437 if RunVim([], after, '-f -g +reverse')
438 let lines = readfile('Xtest_reverse')
439 call assert_equal(['light'], lines)
440 endif
441
442 call delete('Xtest_reverse')
443endfunc
444
445" Test the -background and -foreground arguments (for GUI only).
446func Test_background_foreground()
447 CheckCanRunGui
448 CheckNotMSWindows
449
450 " Is there a better way to check the effect of -background & -foreground
451 " other than merely looking at &background (dark or light)?
452 let after =<< trim [CODE]
453 call writefile([&background], "Xtest_fg_bg")
454 qall
455 [CODE]
456 if RunVim([], after, '-f -g -background darkred -foreground yellow')
457 let lines = readfile('Xtest_fg_bg')
458 call assert_equal(['dark'], lines)
459 endif
460 if RunVim([], after, '-f -g -background ivory -foreground darkgreen')
461 let lines = readfile('Xtest_fg_bg')
462 call assert_equal(['light'], lines)
463 endif
464
465 call delete('Xtest_fg_bg')
466endfunc
467
468" Test the -font argument (for GUI only).
469func Test_font()
470 CheckCanRunGui
471 CheckNotMSWindows
472
473 if has('gui_gtk')
474 let font = 'Courier 14'
475 elseif has('gui_motif') || has('gui_athena')
476 let font = '-misc-fixed-bold-*'
477 else
478 throw 'Skipped: test does not set a valid font for this GUI'
479 endif
480
481 let after =<< trim [CODE]
482 call writefile([&guifont], "Xtest_font")
483 qall
484 [CODE]
485
486 if RunVim([], after, '--nofork -g -font "' .. font .. '"')
487 let lines = readfile('Xtest_font')
488 call assert_equal([font], lines)
489 endif
490
491 call delete('Xtest_font')
492endfunc
493
494" Test the -geometry argument (for GUI only).
495func Test_geometry()
496 CheckCanRunGui
497 CheckNotMSWindows
498
499 if has('gui_motif') || has('gui_athena')
500 " FIXME: With GUI Athena or Motif, the value of getwinposx(),
501 " getwinposy() and getwinpos() do not match exactly the
502 " value given in -geometry. Why?
503 " So only check &columns and &lines for those GUIs.
504 let after =<< trim [CODE]
505 call writefile([&columns, &lines], "Xtest_geometry")
506 qall
507 [CODE]
508 if RunVim([], after, '-f -g -geometry 31x13+41+43')
509 let lines = readfile('Xtest_geometry')
510 call assert_equal(['31', '13'], lines)
511 endif
512 else
513 let after =<< trim [CODE]
514 call writefile([&columns, &lines, getwinposx(), getwinposy(), string(getwinpos())], "Xtest_geometry")
515 qall
516 [CODE]
517 if RunVim([], after, '-f -g -geometry 31x13+41+43')
518 let lines = readfile('Xtest_geometry')
519 call assert_equal(['31', '13', '41', '43', '[41, 43]'], lines)
520 endif
521 endif
522
523 call delete('Xtest_geometry')
524endfunc
525
526" Test the -iconic argument (for GUI only).
527func Test_iconic()
528 CheckCanRunGui
529 CheckNotMSWindows
530
531 call RunVim([], [], '-f -g -iconic -cq')
532
533 " TODO: currently only start vim iconified, but does not
534 " check that vim is iconified. How could this be checked?
535endfunc
536
537
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200538func Test_invalid_args()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200539 " must be able to get the output of Vim.
540 CheckUnix
541 CheckNotGui
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200542
543 for opt in ['-Y', '--does-not-exist']
544 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
545 call assert_equal(1, v:shell_error)
546 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
547 call assert_equal('Unknown option argument: "' .. opt .. '"', out[1])
548 call assert_equal('More info with: "vim -h"', out[2])
549 endfor
550
551 for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime']
552 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
553 call assert_equal(1, v:shell_error)
554 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
555 call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
556 call assert_equal('More info with: "vim -h"', out[2])
557 endfor
558
559 if has('clientserver')
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200560 for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr',
561 \ '--remote-tab', '--remote-tab-wait',
562 \ '--remote-tab-wait-silent', '--remote-tab-silent',
563 \ '--remote-wait', '--remote-wait-silent',
Bram Moolenaar27821262019-05-08 16:41:09 +0200564 \ '--servername',
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200565 \ ]
566 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
567 call assert_equal(1, v:shell_error)
568 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
569 call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
570 call assert_equal('More info with: "vim -h"', out[2])
571 endfor
572 endif
573
Bram Moolenaar240f7ab2019-05-08 17:58:15 +0200574 if has('gui_gtk')
Bram Moolenaar27821262019-05-08 16:41:09 +0200575 let out = split(system(GetVimCommand() .. ' --display'), "\n")
576 call assert_equal(1, v:shell_error)
577 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
578 call assert_equal('Argument missing after: "--display"', out[1])
579 call assert_equal('More info with: "vim -h"', out[2])
580 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200581
Bram Moolenaar5416b752019-05-08 18:36:43 +0200582 if has('xterm_clipboard')
Bram Moolenaar240f7ab2019-05-08 17:58:15 +0200583 let out = split(system(GetVimCommand() .. ' -display'), "\n")
584 call assert_equal(1, v:shell_error)
585 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
586 call assert_equal('Argument missing after: "-display"', out[1])
587 call assert_equal('More info with: "vim -h"', out[2])
588 endif
589
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200590 let out = split(system(GetVimCommand() .. ' -ix'), "\n")
591 call assert_equal(1, v:shell_error)
592 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
593 call assert_equal('Garbage after option argument: "-ix"', out[1])
594 call assert_equal('More info with: "vim -h"', out[2])
595
596 let out = split(system(GetVimCommand() .. ' - xxx'), "\n")
597 call assert_equal(1, v:shell_error)
598 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
599 call assert_equal('Too many edit arguments: "xxx"', out[1])
600 call assert_equal('More info with: "vim -h"', out[2])
601
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100602 if has('quickfix')
603 " Detect invalid repeated arguments '-t foo -t foo", '-q foo -q foo'.
604 for opt in ['-t', '-q']
605 let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n")
606 call assert_equal(1, v:shell_error)
607 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
608 call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1])
609 call assert_equal('More info with: "vim -h"', out[2])
610 endfor
611 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200612
613 for opt in [' -cq', ' --cmd q', ' +', ' -S foo']
614 let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n")
615 call assert_equal(1, v:shell_error)
616 " FIXME: The error message given by Vim is not ideal in case of repeated
617 " -S foo since it does not mention -S.
618 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
619 call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1])
620 call assert_equal('More info with: "vim -h"', out[2])
621 endfor
622
Bram Moolenaar27821262019-05-08 16:41:09 +0200623 if has('gui_gtk')
624 for opt in ['--socketid x', '--socketid 0xg']
625 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
626 call assert_equal(1, v:shell_error)
627 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
628 call assert_equal('Invalid argument for: "--socketid"', out[1])
629 call assert_equal('More info with: "vim -h"', out[2])
630 endfor
631 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200632endfunc
633
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200634func Test_file_args()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200635 let after =<< trim [CODE]
636 call writefile(argv(), "Xtestout")
637 qall
638 [CODE]
639
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200640 if RunVim([], after, '')
641 let lines = readfile('Xtestout')
642 call assert_equal(0, len(lines))
643 endif
644
645 if RunVim([], after, 'one')
646 let lines = readfile('Xtestout')
647 call assert_equal(1, len(lines))
648 call assert_equal('one', lines[0])
649 endif
650
651 if RunVim([], after, 'one two three')
652 let lines = readfile('Xtestout')
653 call assert_equal(3, len(lines))
654 call assert_equal('one', lines[0])
655 call assert_equal('two', lines[1])
656 call assert_equal('three', lines[2])
657 endif
658
659 if RunVim([], after, 'one -c echo two')
660 let lines = readfile('Xtestout')
661 call assert_equal(2, len(lines))
662 call assert_equal('one', lines[0])
663 call assert_equal('two', lines[1])
664 endif
665
666 if RunVim([], after, 'one -- -c echo two')
667 let lines = readfile('Xtestout')
668 call assert_equal(4, len(lines))
669 call assert_equal('one', lines[0])
670 call assert_equal('-c', lines[1])
671 call assert_equal('echo', lines[2])
672 call assert_equal('two', lines[3])
673 endif
674
675 call delete('Xtestout')
676endfunc
677
678func Test_startuptime()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200679 CheckFeature startuptime
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200680 let after = ['qall']
681 if RunVim([], after, '--startuptime Xtestout one')
682 let lines = readfile('Xtestout')
683 let expected = ['--- VIM STARTING ---', 'parsing arguments',
684 \ 'shell init', 'inits 3', 'start termcap', 'opening buffers']
685 let found = []
686 for line in lines
687 for exp in expected
688 if line =~ exp
689 call add(found, exp)
690 endif
691 endfor
692 endfor
693 call assert_equal(expected, found)
694 endif
695 call delete('Xtestout')
696endfunc
Bram Moolenaar3a938382016-08-07 16:36:40 +0200697
698func Test_read_stdin()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200699 let after =<< trim [CODE]
700 write Xtestout
701 quit!
702 [CODE]
703
Bram Moolenaar3a938382016-08-07 16:36:40 +0200704 if RunVimPiped([], after, '-', 'echo something | ')
705 let lines = readfile('Xtestout')
Bram Moolenaare4a76ad2016-08-07 16:50:10 +0200706 " MS-Windows adds a space after the word
707 call assert_equal(['something'], split(lines[0]))
Bram Moolenaar3a938382016-08-07 16:36:40 +0200708 endif
709 call delete('Xtestout')
710endfunc
Bram Moolenaar08cab962017-03-04 14:37:18 +0100711
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +0100712func Test_set_shell()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200713 let after =<< trim [CODE]
714 call writefile([&shell], "Xtestout")
715 quit!
716 [CODE]
717
Bram Moolenaar2efc44b2019-10-05 12:09:32 +0200718 if has('win32')
719 let $SHELL = 'C:\with space\cmd.exe'
720 let expected = '"C:\with space\cmd.exe"'
721 else
722 let $SHELL = '/bin/with space/sh'
723 let expected = '/bin/with\ space/sh'
724 endif
725
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +0100726 if RunVimPiped([], after, '', '')
727 let lines = readfile('Xtestout')
Bram Moolenaar2efc44b2019-10-05 12:09:32 +0200728 call assert_equal(expected, lines[0])
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +0100729 endif
730 call delete('Xtestout')
731endfunc
732
Bram Moolenaar08cab962017-03-04 14:37:18 +0100733func Test_progpath()
734 " Tests normally run with "./vim" or "../vim", these must have been expanded
735 " to a full path.
736 if has('unix')
737 call assert_equal('/', v:progpath[0])
738 elseif has('win32')
739 call assert_equal(':', v:progpath[1])
740 call assert_match('[/\\]', v:progpath[2])
741 endif
742
743 " Only expect "vim" to appear in v:progname.
744 call assert_match('vim\c', v:progname)
745endfunc
Bram Moolenaard5d37532017-03-27 23:02:07 +0200746
747func Test_silent_ex_mode()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200748 " must be able to get the output of Vim.
749 CheckUnix
750 CheckNotGui
Bram Moolenaard5d37532017-03-27 23:02:07 +0200751
752 " This caused an ml_get error.
753 let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq')
754 call assert_notmatch('E315:', out)
755endfunc
Bram Moolenaar85045a72017-04-02 16:54:09 +0200756
757func Test_default_term()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200758 " must be able to get the output of Vim.
759 CheckUnix
760 CheckNotGui
Bram Moolenaar85045a72017-04-02 16:54:09 +0200761
762 let save_term = $TERM
Bram Moolenaar08f88b12017-04-02 17:21:16 +0200763 let $TERM = 'unknownxxx'
Bram Moolenaar85045a72017-04-02 16:54:09 +0200764 let out = system(GetVimCommand() . ' -c''set term'' -c cq')
765 call assert_match("defaulting to 'ansi'", out)
766 let $TERM = save_term
767endfunc
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200768
769func Test_zzz_startinsert()
770 " Test :startinsert
771 call writefile(['123456'], 'Xtestout')
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200772 let after =<< trim [CODE]
773 :startinsert
774 call feedkeys("foobar\<c-o>:wq\<cr>","t")
775 [CODE]
776
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200777 if RunVim([], after, 'Xtestout')
778 let lines = readfile('Xtestout')
779 call assert_equal(['foobar123456'], lines)
780 endif
781 " Test :startinsert!
782 call writefile(['123456'], 'Xtestout')
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200783 let after =<< trim [CODE]
784 :startinsert!
785 call feedkeys("foobar\<c-o>:wq\<cr>","t")
786 [CODE]
787
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200788 if RunVim([], after, 'Xtestout')
789 let lines = readfile('Xtestout')
790 call assert_equal(['123456foobar'], lines)
791 endif
792 call delete('Xtestout')
793endfunc
Bram Moolenaar97c2c052019-02-22 13:42:07 +0100794
795func Test_issue_3969()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200796 " Can't catch the output of gvim.
797 CheckNotGui
798
Bram Moolenaar97c2c052019-02-22 13:42:07 +0100799 " Check that message is not truncated.
800 let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq')
801 call assert_equal('hello', out)
802endfunc
Bram Moolenaarc75e8122019-04-21 15:55:10 +0200803
804func Test_start_with_tabs()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200805 CheckRunVimInTerminal
Bram Moolenaarc75e8122019-04-21 15:55:10 +0200806
807 let buf = RunVimInTerminal('-p a b c', {})
808 call VerifyScreenDump(buf, 'Test_start_with_tabs', {})
809
810 " clean up
811 call StopVimInTerminal(buf)
812endfunc
Bram Moolenaar69bf6342019-10-29 04:16:57 +0100813
814func Test_v_argv()
815 " Can't catch the output of gvim.
816 CheckNotGui
817
818 let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q')
819 let list = out->split("', '")
820 call assert_match('vim', list[0])
821 let idx = index(list, 'arg1')
822 call assert_true(idx > 2)
823 call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:])
824endfunc
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200825
826" Test for the "-r" recovery mode option
827func Test_r_arg()
828 " Can't catch the output of gvim.
829 CheckNotGui
830 CheckUnix
831 CheckEnglish
832 let cmd = GetVimCommand()
833 " There can be swap files anywhere, only check for the headers.
834 let expected =<< trim END
835 Swap files found:.*
836 In current directory:.*
837 In directory \~/tmp:.*
838 In directory /var/tmp:.*
839 In directory /tmp:.*
840 END
841 call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', ''))
842endfunc
843
844" Test for the '-t' option to jump to a tag
845func Test_t_arg()
846 let before =<< trim [CODE]
847 set tags=Xtags
848 [CODE]
849 let after =<< trim [CODE]
850 let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.')
851 call writefile([s], "Xtestout")
852 qall
853 [CODE]
854
855 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
856 \ "first\tXfile1\t/^ \\zsfirst$/",
857 \ "second\tXfile1\t/^ \\zssecond$/",
858 \ "third\tXfile1\t/^ \\zsthird$/"],
859 \ 'Xtags')
860 call writefile([' first', ' second', ' third'], 'Xfile1')
861
862 if RunVim(before, after, '-t second')
863 call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'))
864 call delete('Xtestout')
865 endif
866
867 call delete('Xtags')
868 call delete('Xfile1')
869endfunc
870
Bram Moolenaar1f33e0a2020-12-19 13:32:07 +0100871" Test the '-T' argument which sets the 'term' option.
872func Test_T_arg()
873 CheckNotGui
874 let after =<< trim [CODE]
875 call writefile([&term], "Xtest_T_arg")
876 qall
877 [CODE]
878
879 for t in ['builtin_dumb', 'builtin_ansi']
880 if RunVim([], after, '-T ' .. t)
881 let lines = readfile('Xtest_T_arg')
882 call assert_equal([t], lines)
883 endif
884 endfor
885
886 call delete('Xtest_T_arg')
887endfunc
888
889" Test the '-x' argument to read/write encrypted files.
890func Test_x_arg()
891 CheckRunVimInTerminal
892 CheckFeature cryptv
893
894 " Create an encrypted file Xtest_x_arg.
895 let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
896 call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
897 call term_sendkeys(buf, "foo\n")
898 call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
899 call term_sendkeys(buf, "foo\n")
900 call WaitForAssert({-> assert_match(' All$', term_getline(buf, 10))})
901 call term_sendkeys(buf, "itest\<Esc>:w\<Enter>")
902 call WaitForAssert({-> assert_match('"Xtest_x_arg" \[New\]\[blowfish2\] 1L, 5B written',
903 \ term_getline(buf, 10))})
904 call StopVimInTerminal(buf)
905
906 " Read the encrypted file and check that it contains the expected content "test"
907 let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
908 call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
909 call term_sendkeys(buf, "foo\n")
910 call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
911 call term_sendkeys(buf, "foo\n")
912 call WaitForAssert({-> assert_match('^test', term_getline(buf, 1))})
913 call StopVimInTerminal(buf)
914
915 call delete('Xtest_x_arg')
916endfunc
917
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200918" Test for entering the insert mode on startup
919func Test_start_insertmode()
920 let before =<< trim [CODE]
921 set insertmode
922 [CODE]
923 let after =<< trim [CODE]
924 call writefile(['insertmode=' .. &insertmode], 'Xtestout')
925 qall
926 [CODE]
927 if RunVim(before, after, '')
928 call assert_equal(['insertmode=1'], readfile('Xtestout'))
929 call delete('Xtestout')
930 endif
931endfunc
932
933" Test for enabling the binary mode on startup
934func Test_b_arg()
935 let after =<< trim [CODE]
936 call writefile(['binary=' .. &binary], 'Xtestout')
937 qall
938 [CODE]
939 if RunVim([], after, '-b')
940 call assert_equal(['binary=1'], readfile('Xtestout'))
941 call delete('Xtestout')
942 endif
943endfunc
944
945" Test for enabling the lisp mode on startup
946func Test_l_arg()
947 let after =<< trim [CODE]
948 let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch
949 call writefile([s], 'Xtestout')
950 qall
951 [CODE]
952 if RunVim([], after, '-l')
953 call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout'))
954 call delete('Xtestout')
955 endif
956endfunc
957
958" Test for specifying a non-existing vimrc file using "-u"
959func Test_missing_vimrc()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200960 CheckRunVimInTerminal
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200961 let after =<< trim [CODE]
962 call assert_match('^E282:', v:errmsg)
963 call writefile(v:errors, 'Xtestout')
964 [CODE]
965 call writefile(after, 'Xafter')
966
967 let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter'
968 let buf = term_start(cmd, {'term_rows' : 10})
969 call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200970 call TermWait(buf)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200971 call term_sendkeys(buf, "\n:")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200972 call TermWait(buf)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200973 call WaitForAssert({-> assert_match(':', term_getline(buf, 10))})
974 call StopVimInTerminal(buf)
975 call assert_equal([], readfile('Xtestout'))
976 call delete('Xafter')
977 call delete('Xtestout')
978endfunc
979
980" Test for using the $VIMINIT environment variable
981func Test_VIMINIT()
982 let after =<< trim [CODE]
983 call assert_equal(1, exists('viminit_found'))
984 call assert_equal('yes', viminit_found)
985 call writefile(v:errors, 'Xtestout')
986 qall
987 [CODE]
988 call writefile(after, 'Xafter')
989 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
990 call setenv('VIMINIT', 'let viminit_found="yes"')
991 exe "silent !" . cmd
992 call assert_equal([], readfile('Xtestout'))
993 call delete('Xtestout')
994 call delete('Xafter')
995endfunc
996
997" Test for using the $EXINIT environment variable
998func Test_EXINIT()
999 let after =<< trim [CODE]
1000 call assert_equal(1, exists('exinit_found'))
1001 call assert_equal('yes', exinit_found)
1002 call writefile(v:errors, 'Xtestout')
1003 qall
1004 [CODE]
1005 call writefile(after, 'Xafter')
1006 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1007 call setenv('EXINIT', 'let exinit_found="yes"')
1008 exe "silent !" . cmd
1009 call assert_equal([], readfile('Xtestout'))
1010 call delete('Xtestout')
1011 call delete('Xafter')
1012endfunc
1013
1014" Test for using the 'exrc' option
1015func Test_exrc()
1016 let after =<< trim [CODE]
1017 call assert_equal(1, &exrc)
1018 call assert_equal(1, &secure)
1019 call assert_equal(37, exrc_found)
1020 call writefile(v:errors, 'Xtestout')
1021 qall
1022 [CODE]
1023 call mkdir('Xdir')
1024 call writefile(['let exrc_found=37'], 'Xdir/.exrc')
1025 call writefile(after, 'Xdir/Xafter')
1026 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xdir" --cmd "set enc=utf8 exrc secure"'
1027 exe "silent !" . cmd
1028 call assert_equal([], readfile('Xdir/Xtestout'))
1029 call delete('Xdir', 'rf')
1030endfunc
1031
1032" Test for starting Vim with a non-terminal as input/output
1033func Test_io_not_a_terminal()
1034 " Can't catch the output of gvim.
1035 CheckNotGui
1036 CheckUnix
1037 CheckEnglish
1038 let l = systemlist(GetVimProg() .. ' --ttyfail')
1039 call assert_equal(['Vim: Warning: Output is not to a terminal',
1040 \ 'Vim: Warning: Input is not from a terminal'], l)
1041endfunc
1042
1043" Test for the "-w scriptout" argument
1044func Test_w_arg()
1045 " Can't catch the output of gvim.
1046 CheckNotGui
1047 call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'b')
1048 if RunVim([], [], '-s Xscriptin -w Xscriptout')
1049 call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout'))
1050 call delete('Xscriptout')
1051 endif
1052 call delete('Xscriptin')
1053
1054 " Test for failing to open the script output file. This test works only when
1055 " the language is English.
1056 if v:lang == "C" || v:lang =~ '^[Ee]n'
1057 call mkdir("Xdir")
1058 let m = system(GetVimCommand() .. " -w Xdir")
1059 call assert_equal("Cannot open for script output: \"Xdir\"\n", m)
1060 call delete("Xdir", 'rf')
1061 endif
1062endfunc
1063
1064" Test for the "-s scriptin" argument
1065func Test_s_arg()
1066 " Can't catch the output of gvim.
1067 CheckNotGui
1068 CheckEnglish
1069 " Test for failing to open the script input file.
1070 let m = system(GetVimCommand() .. " -s abcxyz")
1071 call assert_equal("Cannot open for reading: \"abcxyz\"\n", m)
1072
1073 call writefile([], 'Xinput')
1074 let m = system(GetVimCommand() .. " -s Xinput -s Xinput")
1075 call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m)
1076 call delete('Xinput')
1077endfunc
1078
1079" Test for the "-n" (no swap file) argument
1080func Test_n_arg()
1081 let after =<< trim [CODE]
1082 call assert_equal(0, &updatecount)
1083 call writefile(v:errors, 'Xtestout')
1084 qall
1085 [CODE]
1086 if RunVim([], after, '-n')
1087 call assert_equal([], readfile('Xtestout'))
1088 call delete('Xtestout')
1089 endif
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001090endfunc
1091
1092" Test for the "-h" (help) argument
1093func Test_h_arg()
1094 " Can't catch the output of gvim.
1095 CheckNotGui
1096 let l = systemlist(GetVimProg() .. ' -h')
1097 call assert_match('^VIM - Vi IMproved', l[0])
1098 let l = systemlist(GetVimProg() .. ' -?')
1099 call assert_match('^VIM - Vi IMproved', l[0])
1100endfunc
1101
1102" Test for the "-F" (farsi) argument
1103func Test_F_arg()
1104 " Can't catch the output of gvim.
1105 CheckNotGui
1106 let l = systemlist(GetVimProg() .. ' -F')
1107 call assert_match('^E27:', l[0])
1108endfunc
1109
1110" Test for the "-E" (improved Ex mode) argument
1111func Test_E_arg()
1112 let after =<< trim [CODE]
1113 call assert_equal('cv', mode(1))
1114 call writefile(v:errors, 'Xtestout')
1115 qall
1116 [CODE]
1117 if RunVim([], after, '-E')
1118 call assert_equal([], readfile('Xtestout'))
1119 call delete('Xtestout')
1120 endif
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001121endfunc
1122
1123" Test for too many edit argument errors
1124func Test_too_many_edit_args()
1125 " Can't catch the output of gvim.
1126 CheckNotGui
1127 CheckEnglish
1128 let l = systemlist(GetVimProg() .. ' - -')
1129 call assert_match('^Too many edit arguments: "-"', l[1])
1130endfunc
1131
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001132" Test starting vim with various names: vim, ex, view, evim, etc.
1133func Test_progname()
1134 CheckUnix
1135
1136 call mkdir('Xprogname', 'p')
1137 call writefile(['silent !date',
1138 \ 'call writefile([mode(1), '
1139 \ .. '&insertmode, &diff, &readonly, &updatecount, '
1140 \ .. 'join(split(execute("message"), "\n")[1:])], "Xprogname_out")',
1141 \ 'qall'], 'Xprogname_after')
1142
1143 " +---------------------------------------------- progname
1144 " | +--------------------------------- mode(1)
1145 " | | +--------------------------- &insertmode
1146 " | | | +---------------------- &diff
1147 " | | | | +----------------- &readonly
1148 " | | | | | +-------- &updatecount
1149 " | | | | | | +--- :messages
1150 " | | | | | | |
1151 let expectations = {
1152 \ 'vim': ['n', '0', '0', '0', '200', ''],
1153 \ 'gvim': ['n', '0', '0', '0', '200', ''],
1154 \ 'ex': ['ce', '0', '0', '0', '200', ''],
1155 \ 'exim': ['cv', '0', '0', '0', '200', ''],
1156 \ 'view': ['n', '0', '0', '1', '10000', ''],
1157 \ 'gview': ['n', '0', '0', '1', '10000', ''],
1158 \ 'evim': ['n', '1', '0', '0', '200', ''],
1159 \ 'eview': ['n', '1', '0', '1', '10000', ''],
1160 \ 'rvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1161 \ 'rgvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1162 \ 'rview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1163 \ 'rgview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1164 \ 'vimdiff': ['n', '0', '1', '0', '200', ''],
1165 \ 'gvimdiff': ['n', '0', '1', '0', '200', '']}
1166
1167 let prognames = ['vim', 'gvim', 'ex', 'exim', 'view', 'gview',
1168 \ 'evim', 'eview', 'rvim', 'rgvim', 'rview', 'rgview',
1169 \ 'vimdiff', 'gvimdiff']
1170
1171 for progname in prognames
Bram Moolenaar240309c2021-03-14 16:20:37 +01001172 let run_with_gui = (progname =~# 'g') || (has('gui') && (progname ==# 'evim' || progname ==# 'eview'))
1173
1174 if empty($DISPLAY) && run_with_gui
1175 " Can't run gvim, gview (etc.) if $DISPLAY is not setup.
1176 continue
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001177 endif
1178
1179 exe 'silent !ln -s -f ' ..exepath(GetVimProg()) .. ' Xprogname/' .. progname
1180
1181 let stdout_stderr = ''
1182 if progname =~# 'g'
1183 let stdout_stderr = system('Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after')
1184 else
1185 exe 'sil !Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after'
1186 endif
1187
1188 if progname =~# 'g' && !has('gui')
1189 call assert_equal("E25: GUI cannot be used: Not enabled at compile time\n", stdout_stderr, progname)
1190 else
Bram Moolenaar240309c2021-03-14 16:20:37 +01001191 " GUI motif can output some warnings like this:
1192 " Warning:
1193 " Name: subMenu
1194 " Class: XmCascadeButton
1195 " Illegal mnemonic character; Could not convert X KEYSYM to a keycode
1196 " So don't check that stderr is empty with GUI Motif.
1197 if run_with_gui && !has('gui_motif')
1198 call assert_equal('', stdout_stderr, progname)
1199 endif
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001200 call assert_equal(expectations[progname], readfile('Xprogname_out'), progname)
1201 endif
1202
1203 call delete('Xprogname/' .. progname)
1204 call delete('Xprogname_out')
1205 endfor
1206
1207 call delete('Xprogname_after')
1208 call delete('Xprogname', 'd')
1209endfunc
1210
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001211" vim: shiftwidth=2 sts=2 expandtab