blob: 76060bf7bdef09364ae9068186646d3d937146bd [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 Moolenaarf8c52e82021-03-17 12:27:23 +0100112 " This does not work with a GUI-only binary, such as on MS-Windows.
113 CheckAnyOf Unix NotGui
Bram Moolenaar240309c2021-03-14 16:20:37 +0100114
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200115 if RunVim([], [], '--help >Xtestout')
116 let lines = readfile('Xtestout')
117 call assert_true(len(lines) > 20)
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200118 call assert_match('Vi IMproved', lines[0])
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200119
120 " check if couple of lines are there
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200121 let found = []
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200122 for line in lines
123 if line =~ '-R.*Readonly mode'
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200124 call add(found, 'Readonly mode')
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200125 endif
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200126 " Watch out for a second --version line in the Gnome version.
127 if line =~ '--version.*Print version information and exit'
128 call add(found, "--version")
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200129 endif
130 endfor
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200131 call assert_equal(['Readonly mode', '--version'], found)
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200132 endif
133 call delete('Xtestout')
134endfunc
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200135
136func Test_compatible_args()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200137 let after =<< trim [CODE]
138 call writefile([string(&compatible)], "Xtestout")
139 set viminfo+=nviminfo
140 quit
141 [CODE]
142
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200143 if RunVim([], after, '-C')
144 let lines = readfile('Xtestout')
145 call assert_equal('1', lines[0])
146 endif
147
148 if RunVim([], after, '-N')
149 let lines = readfile('Xtestout')
150 call assert_equal('0', lines[0])
151 endif
152
153 call delete('Xtestout')
154endfunc
155
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200156" Test the -o[N] and -O[N] arguments to open N windows split
157" horizontally or vertically.
158func Test_o_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200159 let after =<< trim [CODE]
Bram Moolenaare96a2492019-06-25 04:12:16 +0200160 set cpo&vim
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200161 call writefile([winnr("$"),
162 \ winheight(1), winheight(2), &lines,
163 \ winwidth(1), winwidth(2), &columns,
164 \ bufname(winbufnr(1)), bufname(winbufnr(2))],
165 \ "Xtestout")
166 qall
167 [CODE]
168
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200169 if RunVim([], after, '-o2')
170 " Open 2 windows split horizontally. Expect:
171 " - 2 windows
172 " - both windows should have the same or almost the same height
173 " - sum of both windows height (+ 3 for both statusline and Ex command)
174 " should be equal to the number of lines
175 " - both windows should have the same width which should be equal to the
176 " number of columns
177 " - buffer of both windows should have no name
178 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
179 call assert_equal('2', wn)
180 call assert_inrange(0, 1, wh1 - wh2)
181 call assert_equal(string(wh1 + wh2 + 3), ln)
182 call assert_equal(ww1, ww2)
183 call assert_equal(ww1, cn)
184 call assert_equal('', bn1)
185 call assert_equal('', bn2)
186 endif
187
188 if RunVim([], after, '-o foo bar')
189 " Same expectations as for -o2 but buffer names should be foo and bar
190 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
191 call assert_equal('2', wn)
192 call assert_inrange(0, 1, wh1 - wh2)
193 call assert_equal(string(wh1 + wh2 + 3), ln)
194 call assert_equal(ww1, ww2)
195 call assert_equal(ww1, cn)
196 call assert_equal('foo', bn1)
197 call assert_equal('bar', bn2)
198 endif
199
200 if RunVim([], after, '-O2')
201 " Open 2 windows split vertically. Expect:
202 " - 2 windows
203 " - both windows should have the same or almost the same width
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200204 " - sum of both windows width (+ 1 for the separator) should be equal to
205 " the number of columns
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200206 " - both windows should have the same height
207 " - window height (+ 2 for the statusline and Ex command) should be equal
208 " to the number of lines
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200209 " - buffer of both windows should have no name
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200210 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
211 call assert_equal('2', wn)
212 call assert_inrange(0, 1, ww1 - ww2)
213 call assert_equal(string(ww1 + ww2 + 1), cn)
214 call assert_equal(wh1, wh2)
215 call assert_equal(string(wh1 + 2), ln)
216 call assert_equal('', bn1)
217 call assert_equal('', bn2)
218 endif
219
220 if RunVim([], after, '-O foo bar')
221 " Same expectations as for -O2 but buffer names should be foo and bar
222 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
223 call assert_equal('2', wn)
224 call assert_inrange(0, 1, ww1 - ww2)
225 call assert_equal(string(ww1 + ww2 + 1), cn)
226 call assert_equal(wh1, wh2)
227 call assert_equal(string(wh1 + 2), ln)
228 call assert_equal('foo', bn1)
229 call assert_equal('bar', bn2)
230 endif
231
232 call delete('Xtestout')
233endfunc
234
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200235" Test the -p[N] argument to open N tabpages.
236func Test_p_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200237 let after =<< trim [CODE]
238 call writefile(split(execute("tabs"), "\n"), "Xtestout")
239 qall
240 [CODE]
241
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200242 if RunVim([], after, '-p2')
243 let lines = readfile('Xtestout')
244 call assert_equal(4, len(lines))
245 call assert_equal('Tab page 1', lines[0])
246 call assert_equal('> [No Name]', lines[1])
247 call assert_equal('Tab page 2', lines[2])
248 call assert_equal(' [No Name]', lines[3])
249 endif
250
251 if RunVim([], after, '-p foo bar')
252 let lines = readfile('Xtestout')
253 call assert_equal(4, len(lines))
254 call assert_equal('Tab page 1', lines[0])
255 call assert_equal('> foo', lines[1])
256 call assert_equal('Tab page 2', lines[2])
257 call assert_equal(' bar', lines[3])
258 endif
259
260 call delete('Xtestout')
261endfunc
262
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200263" Test the -V[N] argument to set the 'verbose' option to [N]
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200264func Test_V_arg()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200265 " Can't catch the output of gvim.
266 CheckNotGui
267
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200268 let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq')
269 call assert_equal(" verbose=0\n", out)
270
271 let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq')
Bram Moolenaar4515bcd2020-05-03 18:21:04 +0200272 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline \\d\\+: sourcing \"[^\"]*runtime[\\/]filetype\.vim\".*\n", out)
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200273 call assert_match(" verbose=2\n", out)
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200274
275 let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq')
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200276 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 +0200277endfunc
278
Christian Brabandt1d3a14e2021-05-29 19:53:50 +0200279" Test that an error is shown when the defaults.vim file could not be read
280func Test_defaults_error()
281 " Can't catch the output of gvim.
282 CheckNotGui
283 CheckNotMSWindows
284
285 let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' --clean -cq')
286 call assert_match("E1187: Failed to source defaults.vim", out)
287
288 let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' -u DEFAULTS -cq')
289 call assert_match("E1187: Failed to source defaults.vim", out)
290endfunc
291
Bram Moolenaar54948182018-12-28 18:32:56 +0100292" Test the '-q [errorfile]' argument.
293func Test_q_arg()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100294 CheckFeature quickfix
295
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200296 let lines =<< trim END
297 /* some file with an error */
298 main() {
299 functionCall(arg; arg, arg);
300 return 666
301 }
302 END
303 call writefile(lines, 'Xbadfile.c')
304
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200305 let after =<< trim [CODE]
306 call writefile([&errorfile, string(getpos("."))], "Xtestout")
307 copen
308 w >> Xtestout
309 qall
310 [CODE]
Bram Moolenaar54948182018-12-28 18:32:56 +0100311
312 " Test with default argument '-q'.
313 call assert_equal('errors.err', &errorfile)
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200314 call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'errors.err')
Bram Moolenaar54948182018-12-28 18:32:56 +0100315 if RunVim([], after, '-q')
316 let lines = readfile('Xtestout')
317 call assert_equal(['errors.err',
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200318 \ '[0, 4, 12, 0]',
319 \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100320 \ lines)
321 endif
322 call delete('Xtestout')
323 call delete('errors.err')
324
325 " Test with explicit argument '-q Xerrors' (with space).
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200326 call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'Xerrors')
Bram Moolenaar54948182018-12-28 18:32:56 +0100327 if RunVim([], after, '-q Xerrors')
328 let lines = readfile('Xtestout')
329 call assert_equal(['Xerrors',
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200330 \ '[0, 4, 12, 0]',
331 \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100332 \ lines)
333 endif
334 call delete('Xtestout')
335
336 " Test with explicit argument '-qXerrors' (without space).
337 if RunVim([], after, '-qXerrors')
338 let lines = readfile('Xtestout')
339 call assert_equal(['Xerrors',
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200340 \ '[0, 4, 12, 0]',
341 \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100342 \ lines)
343 endif
344
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200345 " Test with a non-existing error file (exits with value 3)
346 let out = system(GetVimCommand() .. ' -q xyz.err')
347 call assert_equal(3, v:shell_error)
348
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200349 call delete('Xbadfile.c')
Bram Moolenaar54948182018-12-28 18:32:56 +0100350 call delete('Xtestout')
351 call delete('Xerrors')
352endfunc
353
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200354" Test the -V[N]{filename} argument to set the 'verbose' option to N
355" and set 'verbosefile' to filename.
356func Test_V_file_arg()
Bram Moolenaar4841a7c2018-09-22 14:08:49 +0200357 if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq')
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200358 let out = join(readfile('Xverbosefile'), "\n")
359 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out)
360 call assert_match("\n verbose=2\n", out)
361 call assert_match("\n verbosefile=Xverbosefile", out)
362 endif
363
364 call delete('Xverbosefile')
365endfunc
366
367" Test the -m, -M and -R arguments:
368" -m resets 'write'
369" -M resets 'modifiable' and 'write'
370" -R sets 'readonly'
371func Test_m_M_R()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200372 let after =<< trim [CODE]
373 call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout")
374 qall
375 [CODE]
376
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200377 if RunVim([], after, '')
378 let lines = readfile('Xtestout')
379 call assert_equal(['1', '1', '0', '200'], lines)
380 endif
381 if RunVim([], after, '-m')
382 let lines = readfile('Xtestout')
383 call assert_equal(['0', '1', '0', '200'], lines)
384 endif
385 if RunVim([], after, '-M')
386 let lines = readfile('Xtestout')
387 call assert_equal(['0', '0', '0', '200'], lines)
388 endif
389 if RunVim([], after, '-R')
390 let lines = readfile('Xtestout')
391 call assert_equal(['1', '1', '1', '10000'], lines)
392 endif
393
394 call delete('Xtestout')
395endfunc
396
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200397" Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes).
398func Test_A_F_H_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200399 let after =<< trim [CODE]
400 call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout")
401 qall
402 [CODE]
403
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200404 " Use silent Ex mode to avoid the hit-Enter prompt for the warning that
405 " 'encoding' is not utf-8.
406 if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A')
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200407 let lines = readfile('Xtestout')
408 call assert_equal(['1', '1', '0', '0'], lines)
409 endif
410
411 if has('farsi') && RunVim([], after, '-F')
412 let lines = readfile('Xtestout')
413 call assert_equal(['1', '0', '1', '0'], lines)
414 endif
415
416 if has('rightleft') && RunVim([], after, '-H')
417 let lines = readfile('Xtestout')
418 call assert_equal(['1', '0', '0', '1'], lines)
419 endif
420
421 call delete('Xtestout')
422endfunc
423
Bram Moolenaar240309c2021-03-14 16:20:37 +0100424" Test the --echo-wid argument (for GTK GUI only).
425func Test_echo_wid()
426 CheckCanRunGui
427 CheckFeature gui_gtk
428
429 if RunVim([], [], '-g --echo-wid -cq >Xtest_echo_wid')
430 let lines = readfile('Xtest_echo_wid')
431 call assert_equal(1, len(lines))
432 call assert_match('^WID: \d\+$', lines[0])
433 endif
434
435 call delete('Xtest_echo_wid')
436endfunction
437
438" Test the -reverse and +reverse arguments (for GUI only).
439func Test_reverse()
440 CheckCanRunGui
Bram Moolenaarf8c52e82021-03-17 12:27:23 +0100441 CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
Bram Moolenaar240309c2021-03-14 16:20:37 +0100442
443 let after =<< trim [CODE]
444 call writefile([&background], "Xtest_reverse")
445 qall
446 [CODE]
447 if RunVim([], after, '-f -g -reverse')
448 let lines = readfile('Xtest_reverse')
449 call assert_equal(['dark'], lines)
450 endif
451 if RunVim([], after, '-f -g +reverse')
452 let lines = readfile('Xtest_reverse')
453 call assert_equal(['light'], lines)
454 endif
455
456 call delete('Xtest_reverse')
457endfunc
458
459" Test the -background and -foreground arguments (for GUI only).
460func Test_background_foreground()
461 CheckCanRunGui
Bram Moolenaarf8c52e82021-03-17 12:27:23 +0100462 CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
Bram Moolenaar240309c2021-03-14 16:20:37 +0100463
464 " Is there a better way to check the effect of -background & -foreground
465 " other than merely looking at &background (dark or light)?
466 let after =<< trim [CODE]
467 call writefile([&background], "Xtest_fg_bg")
468 qall
469 [CODE]
470 if RunVim([], after, '-f -g -background darkred -foreground yellow')
471 let lines = readfile('Xtest_fg_bg')
472 call assert_equal(['dark'], lines)
473 endif
474 if RunVim([], after, '-f -g -background ivory -foreground darkgreen')
475 let lines = readfile('Xtest_fg_bg')
476 call assert_equal(['light'], lines)
477 endif
478
479 call delete('Xtest_fg_bg')
480endfunc
481
482" Test the -font argument (for GUI only).
483func Test_font()
484 CheckCanRunGui
485 CheckNotMSWindows
486
487 if has('gui_gtk')
488 let font = 'Courier 14'
489 elseif has('gui_motif') || has('gui_athena')
490 let font = '-misc-fixed-bold-*'
491 else
492 throw 'Skipped: test does not set a valid font for this GUI'
493 endif
494
495 let after =<< trim [CODE]
496 call writefile([&guifont], "Xtest_font")
497 qall
498 [CODE]
499
500 if RunVim([], after, '--nofork -g -font "' .. font .. '"')
501 let lines = readfile('Xtest_font')
502 call assert_equal([font], lines)
503 endif
504
505 call delete('Xtest_font')
506endfunc
507
508" Test the -geometry argument (for GUI only).
509func Test_geometry()
510 CheckCanRunGui
Bram Moolenaarf8c52e82021-03-17 12:27:23 +0100511 CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
Bram Moolenaar240309c2021-03-14 16:20:37 +0100512
513 if has('gui_motif') || has('gui_athena')
514 " FIXME: With GUI Athena or Motif, the value of getwinposx(),
515 " getwinposy() and getwinpos() do not match exactly the
516 " value given in -geometry. Why?
517 " So only check &columns and &lines for those GUIs.
518 let after =<< trim [CODE]
519 call writefile([&columns, &lines], "Xtest_geometry")
520 qall
521 [CODE]
522 if RunVim([], after, '-f -g -geometry 31x13+41+43')
523 let lines = readfile('Xtest_geometry')
524 call assert_equal(['31', '13'], lines)
525 endif
526 else
527 let after =<< trim [CODE]
528 call writefile([&columns, &lines, getwinposx(), getwinposy(), string(getwinpos())], "Xtest_geometry")
529 qall
530 [CODE]
531 if RunVim([], after, '-f -g -geometry 31x13+41+43')
532 let lines = readfile('Xtest_geometry')
533 call assert_equal(['31', '13', '41', '43', '[41, 43]'], lines)
534 endif
535 endif
536
537 call delete('Xtest_geometry')
538endfunc
539
540" Test the -iconic argument (for GUI only).
541func Test_iconic()
542 CheckCanRunGui
Bram Moolenaarf8c52e82021-03-17 12:27:23 +0100543 CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena
Bram Moolenaar240309c2021-03-14 16:20:37 +0100544
545 call RunVim([], [], '-f -g -iconic -cq')
546
547 " TODO: currently only start vim iconified, but does not
548 " check that vim is iconified. How could this be checked?
549endfunc
550
551
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200552func Test_invalid_args()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200553 " must be able to get the output of Vim.
554 CheckUnix
555 CheckNotGui
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200556
557 for opt in ['-Y', '--does-not-exist']
558 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
559 call assert_equal(1, v:shell_error)
560 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
561 call assert_equal('Unknown option argument: "' .. opt .. '"', out[1])
562 call assert_equal('More info with: "vim -h"', out[2])
563 endfor
564
565 for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime']
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
573 if has('clientserver')
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200574 for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr',
575 \ '--remote-tab', '--remote-tab-wait',
576 \ '--remote-tab-wait-silent', '--remote-tab-silent',
577 \ '--remote-wait', '--remote-wait-silent',
Bram Moolenaar27821262019-05-08 16:41:09 +0200578 \ '--servername',
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200579 \ ]
580 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
581 call assert_equal(1, v:shell_error)
582 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
583 call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
584 call assert_equal('More info with: "vim -h"', out[2])
585 endfor
586 endif
587
Bram Moolenaar240f7ab2019-05-08 17:58:15 +0200588 if has('gui_gtk')
Bram Moolenaar27821262019-05-08 16:41:09 +0200589 let out = split(system(GetVimCommand() .. ' --display'), "\n")
590 call assert_equal(1, v:shell_error)
591 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
592 call assert_equal('Argument missing after: "--display"', out[1])
593 call assert_equal('More info with: "vim -h"', out[2])
594 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200595
Bram Moolenaar5416b752019-05-08 18:36:43 +0200596 if has('xterm_clipboard')
Bram Moolenaar240f7ab2019-05-08 17:58:15 +0200597 let out = split(system(GetVimCommand() .. ' -display'), "\n")
598 call assert_equal(1, v:shell_error)
599 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
600 call assert_equal('Argument missing after: "-display"', out[1])
601 call assert_equal('More info with: "vim -h"', out[2])
602 endif
603
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200604 let out = split(system(GetVimCommand() .. ' -ix'), "\n")
605 call assert_equal(1, v:shell_error)
606 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
607 call assert_equal('Garbage after option argument: "-ix"', out[1])
608 call assert_equal('More info with: "vim -h"', out[2])
609
610 let out = split(system(GetVimCommand() .. ' - xxx'), "\n")
611 call assert_equal(1, v:shell_error)
612 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
613 call assert_equal('Too many edit arguments: "xxx"', out[1])
614 call assert_equal('More info with: "vim -h"', out[2])
615
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100616 if has('quickfix')
617 " Detect invalid repeated arguments '-t foo -t foo", '-q foo -q foo'.
618 for opt in ['-t', '-q']
619 let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n")
620 call assert_equal(1, v:shell_error)
621 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
622 call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1])
623 call assert_equal('More info with: "vim -h"', out[2])
624 endfor
625 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200626
627 for opt in [' -cq', ' --cmd q', ' +', ' -S foo']
628 let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n")
629 call assert_equal(1, v:shell_error)
630 " FIXME: The error message given by Vim is not ideal in case of repeated
631 " -S foo since it does not mention -S.
632 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
633 call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1])
634 call assert_equal('More info with: "vim -h"', out[2])
635 endfor
636
Bram Moolenaar27821262019-05-08 16:41:09 +0200637 if has('gui_gtk')
Dominique Pelle6d37e8e2021-05-06 17:36:55 +0200638 let out = split(system(GetVimCommand() .. ' --socketid'), "\n")
639 call assert_equal(1, v:shell_error)
640 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
641 call assert_equal('Argument missing after: "--socketid"', out[1])
642 call assert_equal('More info with: "vim -h"', out[2])
643
Bram Moolenaar27821262019-05-08 16:41:09 +0200644 for opt in ['--socketid x', '--socketid 0xg']
645 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
646 call assert_equal(1, v:shell_error)
647 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
648 call assert_equal('Invalid argument for: "--socketid"', out[1])
649 call assert_equal('More info with: "vim -h"', out[2])
650 endfor
Dominique Pelle6d37e8e2021-05-06 17:36:55 +0200651
Bram Moolenaar27821262019-05-08 16:41:09 +0200652 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200653endfunc
654
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200655func Test_file_args()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200656 let after =<< trim [CODE]
657 call writefile(argv(), "Xtestout")
658 qall
659 [CODE]
660
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200661 if RunVim([], after, '')
662 let lines = readfile('Xtestout')
663 call assert_equal(0, len(lines))
664 endif
665
666 if RunVim([], after, 'one')
667 let lines = readfile('Xtestout')
668 call assert_equal(1, len(lines))
669 call assert_equal('one', lines[0])
670 endif
671
672 if RunVim([], after, 'one two three')
673 let lines = readfile('Xtestout')
674 call assert_equal(3, len(lines))
675 call assert_equal('one', lines[0])
676 call assert_equal('two', lines[1])
677 call assert_equal('three', lines[2])
678 endif
679
680 if RunVim([], after, 'one -c echo two')
681 let lines = readfile('Xtestout')
682 call assert_equal(2, len(lines))
683 call assert_equal('one', lines[0])
684 call assert_equal('two', lines[1])
685 endif
686
687 if RunVim([], after, 'one -- -c echo two')
688 let lines = readfile('Xtestout')
689 call assert_equal(4, len(lines))
690 call assert_equal('one', lines[0])
691 call assert_equal('-c', lines[1])
692 call assert_equal('echo', lines[2])
693 call assert_equal('two', lines[3])
694 endif
695
696 call delete('Xtestout')
697endfunc
698
699func Test_startuptime()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200700 CheckFeature startuptime
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200701 let after = ['qall']
702 if RunVim([], after, '--startuptime Xtestout one')
703 let lines = readfile('Xtestout')
704 let expected = ['--- VIM STARTING ---', 'parsing arguments',
705 \ 'shell init', 'inits 3', 'start termcap', 'opening buffers']
706 let found = []
707 for line in lines
708 for exp in expected
709 if line =~ exp
710 call add(found, exp)
711 endif
712 endfor
713 endfor
714 call assert_equal(expected, found)
715 endif
716 call delete('Xtestout')
717endfunc
Bram Moolenaar3a938382016-08-07 16:36:40 +0200718
719func Test_read_stdin()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200720 let after =<< trim [CODE]
721 write Xtestout
722 quit!
723 [CODE]
724
Bram Moolenaar3a938382016-08-07 16:36:40 +0200725 if RunVimPiped([], after, '-', 'echo something | ')
726 let lines = readfile('Xtestout')
Bram Moolenaare4a76ad2016-08-07 16:50:10 +0200727 " MS-Windows adds a space after the word
728 call assert_equal(['something'], split(lines[0]))
Bram Moolenaar3a938382016-08-07 16:36:40 +0200729 endif
730 call delete('Xtestout')
731endfunc
Bram Moolenaar08cab962017-03-04 14:37:18 +0100732
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +0100733func Test_set_shell()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200734 let after =<< trim [CODE]
735 call writefile([&shell], "Xtestout")
736 quit!
737 [CODE]
738
Bram Moolenaar2efc44b2019-10-05 12:09:32 +0200739 if has('win32')
740 let $SHELL = 'C:\with space\cmd.exe'
741 let expected = '"C:\with space\cmd.exe"'
742 else
743 let $SHELL = '/bin/with space/sh'
744 let expected = '/bin/with\ space/sh'
745 endif
746
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +0100747 if RunVimPiped([], after, '', '')
748 let lines = readfile('Xtestout')
Bram Moolenaar2efc44b2019-10-05 12:09:32 +0200749 call assert_equal(expected, lines[0])
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +0100750 endif
751 call delete('Xtestout')
752endfunc
753
Bram Moolenaar08cab962017-03-04 14:37:18 +0100754func Test_progpath()
755 " Tests normally run with "./vim" or "../vim", these must have been expanded
756 " to a full path.
757 if has('unix')
758 call assert_equal('/', v:progpath[0])
759 elseif has('win32')
760 call assert_equal(':', v:progpath[1])
761 call assert_match('[/\\]', v:progpath[2])
762 endif
763
764 " Only expect "vim" to appear in v:progname.
765 call assert_match('vim\c', v:progname)
766endfunc
Bram Moolenaard5d37532017-03-27 23:02:07 +0200767
768func Test_silent_ex_mode()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200769 " must be able to get the output of Vim.
770 CheckUnix
771 CheckNotGui
Bram Moolenaard5d37532017-03-27 23:02:07 +0200772
773 " This caused an ml_get error.
774 let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq')
775 call assert_notmatch('E315:', out)
776endfunc
Bram Moolenaar85045a72017-04-02 16:54:09 +0200777
778func Test_default_term()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200779 " must be able to get the output of Vim.
780 CheckUnix
781 CheckNotGui
Bram Moolenaar85045a72017-04-02 16:54:09 +0200782
783 let save_term = $TERM
Bram Moolenaar08f88b12017-04-02 17:21:16 +0200784 let $TERM = 'unknownxxx'
Bram Moolenaar85045a72017-04-02 16:54:09 +0200785 let out = system(GetVimCommand() . ' -c''set term'' -c cq')
786 call assert_match("defaulting to 'ansi'", out)
787 let $TERM = save_term
788endfunc
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200789
790func Test_zzz_startinsert()
791 " Test :startinsert
792 call writefile(['123456'], 'Xtestout')
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200793 let after =<< trim [CODE]
794 :startinsert
795 call feedkeys("foobar\<c-o>:wq\<cr>","t")
796 [CODE]
797
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200798 if RunVim([], after, 'Xtestout')
799 let lines = readfile('Xtestout')
800 call assert_equal(['foobar123456'], lines)
801 endif
802 " Test :startinsert!
803 call writefile(['123456'], 'Xtestout')
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200804 let after =<< trim [CODE]
805 :startinsert!
806 call feedkeys("foobar\<c-o>:wq\<cr>","t")
807 [CODE]
808
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200809 if RunVim([], after, 'Xtestout')
810 let lines = readfile('Xtestout')
811 call assert_equal(['123456foobar'], lines)
812 endif
813 call delete('Xtestout')
814endfunc
Bram Moolenaar97c2c052019-02-22 13:42:07 +0100815
816func Test_issue_3969()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200817 " Can't catch the output of gvim.
818 CheckNotGui
819
Bram Moolenaar97c2c052019-02-22 13:42:07 +0100820 " Check that message is not truncated.
821 let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq')
822 call assert_equal('hello', out)
823endfunc
Bram Moolenaarc75e8122019-04-21 15:55:10 +0200824
825func Test_start_with_tabs()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200826 CheckRunVimInTerminal
Bram Moolenaarc75e8122019-04-21 15:55:10 +0200827
828 let buf = RunVimInTerminal('-p a b c', {})
829 call VerifyScreenDump(buf, 'Test_start_with_tabs', {})
830
831 " clean up
832 call StopVimInTerminal(buf)
833endfunc
Bram Moolenaar69bf6342019-10-29 04:16:57 +0100834
835func Test_v_argv()
836 " Can't catch the output of gvim.
837 CheckNotGui
838
839 let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q')
840 let list = out->split("', '")
841 call assert_match('vim', list[0])
842 let idx = index(list, 'arg1')
843 call assert_true(idx > 2)
844 call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:])
845endfunc
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200846
847" Test for the "-r" recovery mode option
848func Test_r_arg()
849 " Can't catch the output of gvim.
850 CheckNotGui
851 CheckUnix
852 CheckEnglish
853 let cmd = GetVimCommand()
854 " There can be swap files anywhere, only check for the headers.
855 let expected =<< trim END
856 Swap files found:.*
857 In current directory:.*
858 In directory \~/tmp:.*
859 In directory /var/tmp:.*
860 In directory /tmp:.*
861 END
862 call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', ''))
863endfunc
864
865" Test for the '-t' option to jump to a tag
866func Test_t_arg()
867 let before =<< trim [CODE]
868 set tags=Xtags
869 [CODE]
870 let after =<< trim [CODE]
871 let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.')
872 call writefile([s], "Xtestout")
873 qall
874 [CODE]
875
876 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
877 \ "first\tXfile1\t/^ \\zsfirst$/",
878 \ "second\tXfile1\t/^ \\zssecond$/",
879 \ "third\tXfile1\t/^ \\zsthird$/"],
880 \ 'Xtags')
881 call writefile([' first', ' second', ' third'], 'Xfile1')
882
Bram Moolenaara2b3e7d2021-03-26 17:24:34 +0100883 for t_arg in ['-t second', '-tsecond']
884 if RunVim(before, after, '-t second')
885 call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'), t_arg)
886 call delete('Xtestout')
887 endif
888 endfor
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200889
890 call delete('Xtags')
891 call delete('Xfile1')
892endfunc
893
Bram Moolenaar1f33e0a2020-12-19 13:32:07 +0100894" Test the '-T' argument which sets the 'term' option.
895func Test_T_arg()
896 CheckNotGui
897 let after =<< trim [CODE]
898 call writefile([&term], "Xtest_T_arg")
899 qall
900 [CODE]
901
902 for t in ['builtin_dumb', 'builtin_ansi']
903 if RunVim([], after, '-T ' .. t)
904 let lines = readfile('Xtest_T_arg')
905 call assert_equal([t], lines)
906 endif
907 endfor
908
909 call delete('Xtest_T_arg')
910endfunc
911
912" Test the '-x' argument to read/write encrypted files.
913func Test_x_arg()
914 CheckRunVimInTerminal
915 CheckFeature cryptv
916
917 " Create an encrypted file Xtest_x_arg.
918 let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
919 call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
920 call term_sendkeys(buf, "foo\n")
921 call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
922 call term_sendkeys(buf, "foo\n")
923 call WaitForAssert({-> assert_match(' All$', term_getline(buf, 10))})
924 call term_sendkeys(buf, "itest\<Esc>:w\<Enter>")
925 call WaitForAssert({-> assert_match('"Xtest_x_arg" \[New\]\[blowfish2\] 1L, 5B written',
926 \ term_getline(buf, 10))})
927 call StopVimInTerminal(buf)
928
929 " Read the encrypted file and check that it contains the expected content "test"
930 let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
931 call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
932 call term_sendkeys(buf, "foo\n")
933 call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
934 call term_sendkeys(buf, "foo\n")
935 call WaitForAssert({-> assert_match('^test', term_getline(buf, 1))})
936 call StopVimInTerminal(buf)
937
938 call delete('Xtest_x_arg')
939endfunc
940
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200941" Test for entering the insert mode on startup
942func Test_start_insertmode()
943 let before =<< trim [CODE]
944 set insertmode
945 [CODE]
946 let after =<< trim [CODE]
947 call writefile(['insertmode=' .. &insertmode], 'Xtestout')
948 qall
949 [CODE]
950 if RunVim(before, after, '')
951 call assert_equal(['insertmode=1'], readfile('Xtestout'))
952 call delete('Xtestout')
953 endif
954endfunc
955
956" Test for enabling the binary mode on startup
957func Test_b_arg()
958 let after =<< trim [CODE]
959 call writefile(['binary=' .. &binary], 'Xtestout')
960 qall
961 [CODE]
962 if RunVim([], after, '-b')
963 call assert_equal(['binary=1'], readfile('Xtestout'))
964 call delete('Xtestout')
965 endif
966endfunc
967
968" Test for enabling the lisp mode on startup
969func Test_l_arg()
970 let after =<< trim [CODE]
971 let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch
972 call writefile([s], 'Xtestout')
973 qall
974 [CODE]
975 if RunVim([], after, '-l')
976 call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout'))
977 call delete('Xtestout')
978 endif
979endfunc
980
981" Test for specifying a non-existing vimrc file using "-u"
982func Test_missing_vimrc()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200983 CheckRunVimInTerminal
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200984 let after =<< trim [CODE]
985 call assert_match('^E282:', v:errmsg)
986 call writefile(v:errors, 'Xtestout')
987 [CODE]
988 call writefile(after, 'Xafter')
989
990 let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter'
991 let buf = term_start(cmd, {'term_rows' : 10})
992 call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200993 call TermWait(buf)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200994 call term_sendkeys(buf, "\n:")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200995 call TermWait(buf)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200996 call WaitForAssert({-> assert_match(':', term_getline(buf, 10))})
997 call StopVimInTerminal(buf)
998 call assert_equal([], readfile('Xtestout'))
999 call delete('Xafter')
1000 call delete('Xtestout')
1001endfunc
1002
1003" Test for using the $VIMINIT environment variable
1004func Test_VIMINIT()
1005 let after =<< trim [CODE]
1006 call assert_equal(1, exists('viminit_found'))
1007 call assert_equal('yes', viminit_found)
1008 call writefile(v:errors, 'Xtestout')
1009 qall
1010 [CODE]
1011 call writefile(after, 'Xafter')
1012 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1013 call setenv('VIMINIT', 'let viminit_found="yes"')
1014 exe "silent !" . cmd
1015 call assert_equal([], readfile('Xtestout'))
1016 call delete('Xtestout')
1017 call delete('Xafter')
1018endfunc
1019
1020" Test for using the $EXINIT environment variable
1021func Test_EXINIT()
1022 let after =<< trim [CODE]
1023 call assert_equal(1, exists('exinit_found'))
1024 call assert_equal('yes', exinit_found)
1025 call writefile(v:errors, 'Xtestout')
1026 qall
1027 [CODE]
1028 call writefile(after, 'Xafter')
1029 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1030 call setenv('EXINIT', 'let exinit_found="yes"')
1031 exe "silent !" . cmd
1032 call assert_equal([], readfile('Xtestout'))
1033 call delete('Xtestout')
1034 call delete('Xafter')
1035endfunc
1036
1037" Test for using the 'exrc' option
1038func Test_exrc()
1039 let after =<< trim [CODE]
1040 call assert_equal(1, &exrc)
1041 call assert_equal(1, &secure)
1042 call assert_equal(37, exrc_found)
1043 call writefile(v:errors, 'Xtestout')
1044 qall
1045 [CODE]
1046 call mkdir('Xdir')
1047 call writefile(['let exrc_found=37'], 'Xdir/.exrc')
1048 call writefile(after, 'Xdir/Xafter')
1049 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xdir" --cmd "set enc=utf8 exrc secure"'
1050 exe "silent !" . cmd
1051 call assert_equal([], readfile('Xdir/Xtestout'))
1052 call delete('Xdir', 'rf')
1053endfunc
1054
1055" Test for starting Vim with a non-terminal as input/output
1056func Test_io_not_a_terminal()
1057 " Can't catch the output of gvim.
1058 CheckNotGui
1059 CheckUnix
1060 CheckEnglish
1061 let l = systemlist(GetVimProg() .. ' --ttyfail')
1062 call assert_equal(['Vim: Warning: Output is not to a terminal',
1063 \ 'Vim: Warning: Input is not from a terminal'], l)
1064endfunc
1065
Bram Moolenaar7007e312021-03-27 12:11:33 +01001066" Test for --not-a-term avoiding escape codes.
1067func Test_not_a_term()
1068 CheckUnix
1069 CheckNotGui
1070
1071 if &shellredir =~ '%s'
1072 let redir = printf(&shellredir, 'Xvimout')
1073 else
1074 let redir = &shellredir .. ' Xvimout'
1075 endif
1076
1077 " Without --not-a-term there are a few escape sequences.
1078 " This will take 2 seconds because of the missing --not-a-term
1079 let cmd = GetVimProg() .. ' --cmd quit ' .. redir
1080 exe "silent !" . cmd
1081 call assert_match("\<Esc>", readfile('Xvimout')->join())
1082 call delete('Xvimout')
1083
1084 " With --not-a-term there are no escape sequences.
1085 let cmd = GetVimProg() .. ' --not-a-term --cmd quit ' .. redir
1086 exe "silent !" . cmd
1087 call assert_notmatch("\<Esc>", readfile('Xvimout')->join())
1088 call delete('Xvimout')
1089endfunc
1090
1091
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001092" Test for the "-w scriptout" argument
1093func Test_w_arg()
1094 " Can't catch the output of gvim.
1095 CheckNotGui
Bram Moolenaar0a1a6a12021-03-26 14:14:18 +01001096
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001097 call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'b')
1098 if RunVim([], [], '-s Xscriptin -w Xscriptout')
1099 call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout'))
1100 call delete('Xscriptout')
1101 endif
1102 call delete('Xscriptin')
1103
1104 " Test for failing to open the script output file. This test works only when
1105 " the language is English.
1106 if v:lang == "C" || v:lang =~ '^[Ee]n'
1107 call mkdir("Xdir")
1108 let m = system(GetVimCommand() .. " -w Xdir")
1109 call assert_equal("Cannot open for script output: \"Xdir\"\n", m)
1110 call delete("Xdir", 'rf')
1111 endif
Bram Moolenaar0a1a6a12021-03-26 14:14:18 +01001112
1113 " A number argument sets the 'window' option
1114 call writefile(["iwindow \<C-R>=&window\<CR>\<Esc>:wq! Xresult\<CR>"], 'Xscriptin', 'b')
Bram Moolenaara2b3e7d2021-03-26 17:24:34 +01001115 for w_arg in ['-w 17', '-w17']
1116 if RunVim([], [], '-s Xscriptin ' .. w_arg)
1117 call assert_equal(["window 17"], readfile('Xresult'), w_arg)
1118 call delete('Xresult')
1119 endif
1120 endfor
Bram Moolenaar0a1a6a12021-03-26 14:14:18 +01001121 call delete('Xscriptin')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001122endfunc
1123
1124" Test for the "-s scriptin" argument
1125func Test_s_arg()
1126 " Can't catch the output of gvim.
1127 CheckNotGui
1128 CheckEnglish
1129 " Test for failing to open the script input file.
1130 let m = system(GetVimCommand() .. " -s abcxyz")
1131 call assert_equal("Cannot open for reading: \"abcxyz\"\n", m)
1132
1133 call writefile([], 'Xinput')
1134 let m = system(GetVimCommand() .. " -s Xinput -s Xinput")
1135 call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m)
1136 call delete('Xinput')
1137endfunc
1138
1139" Test for the "-n" (no swap file) argument
1140func Test_n_arg()
1141 let after =<< trim [CODE]
1142 call assert_equal(0, &updatecount)
1143 call writefile(v:errors, 'Xtestout')
1144 qall
1145 [CODE]
1146 if RunVim([], after, '-n')
1147 call assert_equal([], readfile('Xtestout'))
1148 call delete('Xtestout')
1149 endif
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001150endfunc
1151
1152" Test for the "-h" (help) argument
1153func Test_h_arg()
1154 " Can't catch the output of gvim.
1155 CheckNotGui
1156 let l = systemlist(GetVimProg() .. ' -h')
1157 call assert_match('^VIM - Vi IMproved', l[0])
1158 let l = systemlist(GetVimProg() .. ' -?')
1159 call assert_match('^VIM - Vi IMproved', l[0])
1160endfunc
1161
1162" Test for the "-F" (farsi) argument
1163func Test_F_arg()
1164 " Can't catch the output of gvim.
1165 CheckNotGui
1166 let l = systemlist(GetVimProg() .. ' -F')
1167 call assert_match('^E27:', l[0])
1168endfunc
1169
1170" Test for the "-E" (improved Ex mode) argument
1171func Test_E_arg()
1172 let after =<< trim [CODE]
1173 call assert_equal('cv', mode(1))
1174 call writefile(v:errors, 'Xtestout')
1175 qall
1176 [CODE]
1177 if RunVim([], after, '-E')
1178 call assert_equal([], readfile('Xtestout'))
1179 call delete('Xtestout')
1180 endif
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001181endfunc
1182
Bram Moolenaarc5cf3692021-03-20 22:16:56 +01001183" Test for the "-D" (debugger) argument
1184func Test_D_arg()
1185 CheckRunVimInTerminal
1186
1187 let cmd = GetVimCommandCleanTerm() .. ' -D'
1188 let buf = term_start(cmd, {'term_rows' : 10})
1189 call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
1190
1191 call WaitForAssert({-> assert_equal('Entering Debug mode. Type "cont" to continue.',
1192 \ term_getline(buf, 7))})
1193 call WaitForAssert({-> assert_equal('>', term_getline(buf, 10))})
1194
1195 call StopVimInTerminal(buf)
1196endfunc
1197
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001198" Test for too many edit argument errors
1199func Test_too_many_edit_args()
1200 " Can't catch the output of gvim.
1201 CheckNotGui
1202 CheckEnglish
1203 let l = systemlist(GetVimProg() .. ' - -')
1204 call assert_match('^Too many edit arguments: "-"', l[1])
1205endfunc
1206
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001207" Test starting vim with various names: vim, ex, view, evim, etc.
1208func Test_progname()
1209 CheckUnix
1210
1211 call mkdir('Xprogname', 'p')
1212 call writefile(['silent !date',
1213 \ 'call writefile([mode(1), '
1214 \ .. '&insertmode, &diff, &readonly, &updatecount, '
1215 \ .. 'join(split(execute("message"), "\n")[1:])], "Xprogname_out")',
1216 \ 'qall'], 'Xprogname_after')
1217
1218 " +---------------------------------------------- progname
1219 " | +--------------------------------- mode(1)
1220 " | | +--------------------------- &insertmode
1221 " | | | +---------------------- &diff
1222 " | | | | +----------------- &readonly
1223 " | | | | | +-------- &updatecount
1224 " | | | | | | +--- :messages
1225 " | | | | | | |
1226 let expectations = {
1227 \ 'vim': ['n', '0', '0', '0', '200', ''],
1228 \ 'gvim': ['n', '0', '0', '0', '200', ''],
1229 \ 'ex': ['ce', '0', '0', '0', '200', ''],
1230 \ 'exim': ['cv', '0', '0', '0', '200', ''],
1231 \ 'view': ['n', '0', '0', '1', '10000', ''],
1232 \ 'gview': ['n', '0', '0', '1', '10000', ''],
1233 \ 'evim': ['n', '1', '0', '0', '200', ''],
1234 \ 'eview': ['n', '1', '0', '1', '10000', ''],
1235 \ 'rvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1236 \ 'rgvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1237 \ 'rview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1238 \ 'rgview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1239 \ 'vimdiff': ['n', '0', '1', '0', '200', ''],
1240 \ 'gvimdiff': ['n', '0', '1', '0', '200', '']}
1241
1242 let prognames = ['vim', 'gvim', 'ex', 'exim', 'view', 'gview',
1243 \ 'evim', 'eview', 'rvim', 'rgvim', 'rview', 'rgview',
1244 \ 'vimdiff', 'gvimdiff']
1245
1246 for progname in prognames
Bram Moolenaar240309c2021-03-14 16:20:37 +01001247 let run_with_gui = (progname =~# 'g') || (has('gui') && (progname ==# 'evim' || progname ==# 'eview'))
1248
1249 if empty($DISPLAY) && run_with_gui
1250 " Can't run gvim, gview (etc.) if $DISPLAY is not setup.
1251 continue
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001252 endif
1253
1254 exe 'silent !ln -s -f ' ..exepath(GetVimProg()) .. ' Xprogname/' .. progname
1255
1256 let stdout_stderr = ''
1257 if progname =~# 'g'
1258 let stdout_stderr = system('Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after')
1259 else
1260 exe 'sil !Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after'
1261 endif
1262
1263 if progname =~# 'g' && !has('gui')
1264 call assert_equal("E25: GUI cannot be used: Not enabled at compile time\n", stdout_stderr, progname)
1265 else
Bram Moolenaar240309c2021-03-14 16:20:37 +01001266 " GUI motif can output some warnings like this:
1267 " Warning:
1268 " Name: subMenu
1269 " Class: XmCascadeButton
1270 " Illegal mnemonic character; Could not convert X KEYSYM to a keycode
1271 " So don't check that stderr is empty with GUI Motif.
1272 if run_with_gui && !has('gui_motif')
1273 call assert_equal('', stdout_stderr, progname)
1274 endif
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001275 call assert_equal(expectations[progname], readfile('Xprogname_out'), progname)
1276 endif
1277
1278 call delete('Xprogname/' .. progname)
1279 call delete('Xprogname_out')
1280 endfor
1281
1282 call delete('Xprogname_after')
1283 call delete('Xprogname', 'd')
1284endfunc
1285
Yegappan Lakshmanan36f96a52021-05-13 18:33:16 +02001286" Test for doing a write from .vimrc
1287func Test_write_in_vimrc()
1288 call writefile(['silent! write'], 'Xvimrc')
1289 let after =<< trim [CODE]
1290 call assert_match('E32: ', v:errmsg)
1291 call writefile(v:errors, 'Xtestout')
1292 qall
1293 [CODE]
1294 if RunVim([], after, '-u Xvimrc')
1295 call assert_equal([], readfile('Xtestout'))
1296 call delete('Xtestout')
1297 endif
1298 call delete('Xvimrc')
1299endfunc
1300
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001301" vim: shiftwidth=2 sts=2 expandtab