blob: 02d1adf140bb28c8befd69ef5fcd5976b970ff4f [file] [log] [blame]
Bram Moolenaar66459b72016-08-06 19:01:55 +02001" Tests for startup.
Bram Moolenaarb9a46fe2016-07-29 18:13:42 +02002
Christian Brabandteb380b92025-07-07 20:53:55 +02003source util/screendump.vim
Bram Moolenaar66459b72016-08-06 19:01:55 +02004
5" Check that loading startup.vim works.
Bram Moolenaarb9a46fe2016-07-29 18:13:42 +02006func Test_startup_script()
7 set compatible
8 source $VIMRUNTIME/defaults.vim
9
10 call assert_equal(0, &compatible)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +020011 " Restore some options, so that the following tests doesn't break
12 set nomore
13 set noshowmode
Bram Moolenaarb9a46fe2016-07-29 18:13:42 +020014endfunc
Bram Moolenaar66459b72016-08-06 19:01:55 +020015
16" Verify the order in which plugins are loaded:
17" 1. plugins in non-after directories
18" 2. packages
19" 3. plugins in after directories
20func Test_after_comes_later()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020021 CheckFeature packages
Bram Moolenaarc79745a2019-05-20 22:12:34 +020022 let before =<< trim [CODE]
23 set nocp viminfo+=nviminfo
24 set guioptions+=M
25 let $HOME = "/does/not/exist"
26 set loadplugins
27 set rtp=Xhere,Xafter,Xanother
28 set packpath=Xhere,Xafter
29 set nomore
30 let g:sequence = ""
31 [CODE]
32
33 let after =<< trim [CODE]
34 redir! > Xtestout
35 scriptnames
36 redir END
37 redir! > Xsequence
38 echo g:sequence
39 redir END
40 quit
41 [CODE]
42
Bram Moolenaar56564962022-10-10 22:39:42 +010043 call mkdir('Xhere/plugin', 'pR')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020044 call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim')
Bram Moolenaar56564962022-10-10 22:39:42 +010045 call mkdir('Xanother/plugin', 'pR')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020046 call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020047 call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020048 call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020049
Bram Moolenaar56564962022-10-10 22:39:42 +010050 call mkdir('Xafter/plugin', 'pR')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020051 call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim')
Bram Moolenaar66459b72016-08-06 19:01:55 +020052
Bram Moolenaar472a0a82016-08-06 22:31:42 +020053 if RunVim(before, after, '')
Bram Moolenaar66459b72016-08-06 19:01:55 +020054
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020055 let lines = readfile('Xtestout')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020056 let expected = ['Xbefore.vim', 'here.vim', 'another.vim', 'foo.vim', 'later.vim', 'Xafter.vim']
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020057 let found = []
58 for line in lines
59 for one in expected
60 if line =~ one
61 call add(found, one)
62 endif
63 endfor
Bram Moolenaar66459b72016-08-06 19:01:55 +020064 endfor
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020065 call assert_equal(expected, found)
66 endif
Bram Moolenaar66459b72016-08-06 19:01:55 +020067
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020068 call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', ''))
69
Bram Moolenaar66459b72016-08-06 19:01:55 +020070 call delete('Xtestout')
Bram Moolenaar07ecfa62017-06-27 14:43:55 +020071 call delete('Xsequence')
Bram Moolenaar66459b72016-08-06 19:01:55 +020072endfunc
Bram Moolenaar472a0a82016-08-06 22:31:42 +020073
Bram Moolenaarce876aa2017-06-04 17:47:42 +020074func Test_pack_in_rtp_when_plugins_run()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020075 CheckFeature packages
Bram Moolenaarc79745a2019-05-20 22:12:34 +020076 let before =<< trim [CODE]
77 set nocp viminfo+=nviminfo
78 set guioptions+=M
79 let $HOME = "/does/not/exist"
80 set loadplugins
81 set rtp=Xhere
82 set packpath=Xhere
83 set nomore
84 [CODE]
85
Bram Moolenaarce876aa2017-06-04 17:47:42 +020086 let after = [
87 \ 'quit',
88 \ ]
Bram Moolenaar56564962022-10-10 22:39:42 +010089 call mkdir('Xhere/plugin', 'pR')
Bram Moolenaarce876aa2017-06-04 17:47:42 +020090 call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim')
91 call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p')
92 call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim')
93
94 if RunVim(before, after, '')
95
96 let lines = filter(readfile('Xtestout'), '!empty(v:val)')
97 call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0))
98 call assert_match('autoloaded foo', get(lines, 1))
99 endif
100
101 call delete('Xtestout')
Bram Moolenaarce876aa2017-06-04 17:47:42 +0200102endfunc
103
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200104func Test_help_arg()
Bram Moolenaarf8c52e82021-03-17 12:27:23 +0100105 " This does not work with a GUI-only binary, such as on MS-Windows.
106 CheckAnyOf Unix NotGui
Bram Moolenaar240309c2021-03-14 16:20:37 +0100107
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200108 if RunVim([], [], '--help >Xtestout')
109 let lines = readfile('Xtestout')
110 call assert_true(len(lines) > 20)
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200111 call assert_match('Vi IMproved', lines[0])
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200112
113 " check if couple of lines are there
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200114 let found = []
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200115 for line in lines
116 if line =~ '-R.*Readonly mode'
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200117 call add(found, 'Readonly mode')
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200118 endif
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200119 " Watch out for a second --version line in the Gnome version.
120 if line =~ '--version.*Print version information and exit'
121 call add(found, "--version")
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200122 endif
123 endfor
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200124 call assert_equal(['Readonly mode', '--version'], found)
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200125 endif
126 call delete('Xtestout')
127endfunc
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200128
129func Test_compatible_args()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200130 let after =<< trim [CODE]
131 call writefile([string(&compatible)], "Xtestout")
132 set viminfo+=nviminfo
133 quit
134 [CODE]
135
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200136 if RunVim([], after, '-C')
137 let lines = readfile('Xtestout')
138 call assert_equal('1', lines[0])
139 endif
140
141 if RunVim([], after, '-N')
142 let lines = readfile('Xtestout')
143 call assert_equal('0', lines[0])
144 endif
145
146 call delete('Xtestout')
147endfunc
148
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200149" Test the -o[N] and -O[N] arguments to open N windows split
150" horizontally or vertically.
151func Test_o_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200152 let after =<< trim [CODE]
Bram Moolenaare96a2492019-06-25 04:12:16 +0200153 set cpo&vim
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200154 call writefile([winnr("$"),
155 \ winheight(1), winheight(2), &lines,
156 \ winwidth(1), winwidth(2), &columns,
157 \ bufname(winbufnr(1)), bufname(winbufnr(2))],
158 \ "Xtestout")
159 qall
160 [CODE]
161
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200162 if RunVim([], after, '-o2')
163 " Open 2 windows split horizontally. Expect:
164 " - 2 windows
165 " - both windows should have the same or almost the same height
166 " - sum of both windows height (+ 3 for both statusline and Ex command)
167 " should be equal to the number of lines
168 " - both windows should have the same width which should be equal to the
169 " number of columns
170 " - buffer of both windows should have no name
171 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
172 call assert_equal('2', wn)
173 call assert_inrange(0, 1, wh1 - wh2)
174 call assert_equal(string(wh1 + wh2 + 3), ln)
175 call assert_equal(ww1, ww2)
176 call assert_equal(ww1, cn)
177 call assert_equal('', bn1)
178 call assert_equal('', bn2)
179 endif
180
181 if RunVim([], after, '-o foo bar')
182 " Same expectations as for -o2 but buffer names should be foo and bar
183 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
184 call assert_equal('2', wn)
185 call assert_inrange(0, 1, wh1 - wh2)
186 call assert_equal(string(wh1 + wh2 + 3), ln)
187 call assert_equal(ww1, ww2)
188 call assert_equal(ww1, cn)
189 call assert_equal('foo', bn1)
190 call assert_equal('bar', bn2)
191 endif
192
193 if RunVim([], after, '-O2')
194 " Open 2 windows split vertically. Expect:
195 " - 2 windows
196 " - both windows should have the same or almost the same width
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200197 " - sum of both windows width (+ 1 for the separator) should be equal to
198 " the number of columns
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200199 " - both windows should have the same height
200 " - window height (+ 2 for the statusline and Ex command) should be equal
201 " to the number of lines
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200202 " - buffer of both windows should have no name
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200203 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
204 call assert_equal('2', wn)
205 call assert_inrange(0, 1, ww1 - ww2)
206 call assert_equal(string(ww1 + ww2 + 1), cn)
207 call assert_equal(wh1, wh2)
208 call assert_equal(string(wh1 + 2), ln)
209 call assert_equal('', bn1)
210 call assert_equal('', bn2)
211 endif
212
213 if RunVim([], after, '-O foo bar')
214 " Same expectations as for -O2 but buffer names should be foo and bar
215 let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
216 call assert_equal('2', wn)
217 call assert_inrange(0, 1, ww1 - ww2)
218 call assert_equal(string(ww1 + ww2 + 1), cn)
219 call assert_equal(wh1, wh2)
220 call assert_equal(string(wh1 + 2), ln)
221 call assert_equal('foo', bn1)
222 call assert_equal('bar', bn2)
223 endif
Bram Moolenaar8f4499b2018-09-16 16:28:11 +0200224 call delete('Xtestout')
225endfunc
226
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200227" Test the -p[N] argument to open N tabpages.
228func Test_p_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200229 let after =<< trim [CODE]
230 call writefile(split(execute("tabs"), "\n"), "Xtestout")
231 qall
232 [CODE]
233
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200234 if RunVim([], after, '-p2')
235 let lines = readfile('Xtestout')
236 call assert_equal(4, len(lines))
237 call assert_equal('Tab page 1', lines[0])
238 call assert_equal('> [No Name]', lines[1])
239 call assert_equal('Tab page 2', lines[2])
240 call assert_equal(' [No Name]', lines[3])
241 endif
242
243 if RunVim([], after, '-p foo bar')
244 let lines = readfile('Xtestout')
245 call assert_equal(4, len(lines))
246 call assert_equal('Tab page 1', lines[0])
247 call assert_equal('> foo', lines[1])
248 call assert_equal('Tab page 2', lines[2])
249 call assert_equal(' bar', lines[3])
250 endif
251
252 call delete('Xtestout')
253endfunc
254
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200255" Test the -V[N] argument to set the 'verbose' option to [N]
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200256func Test_V_arg()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200257 " Can't catch the output of gvim.
258 CheckNotGui
259
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200260 let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq')
261 call assert_equal(" verbose=0\n", out)
262
263 let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq')
Bram Moolenaar4515bcd2020-05-03 18:21:04 +0200264 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline \\d\\+: sourcing \"[^\"]*runtime[\\/]filetype\.vim\".*\n", out)
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200265 call assert_match(" verbose=2\n", out)
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200266
267 let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq')
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200268 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 +0200269endfunc
270
Christian Brabandt1d3a14e2021-05-29 19:53:50 +0200271" Test that an error is shown when the defaults.vim file could not be read
Bram Moolenaara83d0602021-06-02 16:49:32 +0200272func Test_defaults_error()
273 " Can't catch the output of gvim.
274 CheckNotGui
275 CheckNotMSWindows
276 " For unknown reasons freeing all memory does not work here, even though
277 " EXITFREE is defined.
278 CheckNotAsan
279
280 let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' --clean -cq')
281 call assert_match("E1187: Failed to source defaults.vim", out)
282
283 let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' -u DEFAULTS -cq')
284 call assert_match("E1187: Failed to source defaults.vim", out)
285endfunc
Christian Brabandt1d3a14e2021-05-29 19:53:50 +0200286
Bram Moolenaar54948182018-12-28 18:32:56 +0100287" Test the '-q [errorfile]' argument.
288func Test_q_arg()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100289 CheckFeature quickfix
290
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200291 let lines =<< trim END
292 /* some file with an error */
293 main() {
294 functionCall(arg; arg, arg);
295 return 666
296 }
297 END
Bram Moolenaar56564962022-10-10 22:39:42 +0100298 call writefile(lines, 'Xbadfile.c', 'D')
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200299
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200300 let after =<< trim [CODE]
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100301 call writefile([&errorfile, string(getpos("."))], "XtestoutQarg")
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200302 copen
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100303 w >> XtestoutQarg
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200304 qall
305 [CODE]
Bram Moolenaar54948182018-12-28 18:32:56 +0100306
307 " Test with default argument '-q'.
308 call assert_equal('errors.err', &errorfile)
Bram Moolenaar56564962022-10-10 22:39:42 +0100309 call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'errors.err', 'D')
Bram Moolenaar54948182018-12-28 18:32:56 +0100310 if RunVim([], after, '-q')
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100311 let lines = readfile('XtestoutQarg')
Bram Moolenaar54948182018-12-28 18:32:56 +0100312 call assert_equal(['errors.err',
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200313 \ '[0, 4, 12, 0]',
314 \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100315 \ lines)
316 endif
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100317 call delete('XtestoutQarg')
Bram Moolenaar54948182018-12-28 18:32:56 +0100318
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100319 " Test with explicit argument '-q XerrorsQarg' (with space).
Bram Moolenaar56564962022-10-10 22:39:42 +0100320 call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'XerrorsQarg', 'D')
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100321 if RunVim([], after, '-q XerrorsQarg')
322 let lines = readfile('XtestoutQarg')
323 call assert_equal(['XerrorsQarg',
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200324 \ '[0, 4, 12, 0]',
325 \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100326 \ lines)
327 endif
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100328 call delete('XtestoutQarg')
Bram Moolenaar54948182018-12-28 18:32:56 +0100329
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100330 " Test with explicit argument '-qXerrorsQarg' (without space).
331 if RunVim([], after, '-qXerrorsQarg')
332 let lines = readfile('XtestoutQarg')
333 call assert_equal(['XerrorsQarg',
Bram Moolenaar1e1f6122020-07-15 11:19:11 +0200334 \ '[0, 4, 12, 0]',
335 \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
Bram Moolenaar54948182018-12-28 18:32:56 +0100336 \ lines)
337 endif
338
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200339 " Test with a non-existing error file (exits with value 3)
340 let out = system(GetVimCommand() .. ' -q xyz.err')
341 call assert_equal(3, v:shell_error)
342
Bram Moolenaarbe9fc5b2022-09-09 17:09:35 +0100343 call delete('XtestoutQarg')
Bram Moolenaar54948182018-12-28 18:32:56 +0100344endfunc
345
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200346" Test the -V[N]{filename} argument to set the 'verbose' option to N
347" and set 'verbosefile' to filename.
348func Test_V_file_arg()
Bram Moolenaar4841a7c2018-09-22 14:08:49 +0200349 if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq')
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200350 let out = join(readfile('Xverbosefile'), "\n")
351 call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out)
352 call assert_match("\n verbose=2\n", out)
353 call assert_match("\n verbosefile=Xverbosefile", out)
354 endif
355
356 call delete('Xverbosefile')
357endfunc
358
359" Test the -m, -M and -R arguments:
360" -m resets 'write'
361" -M resets 'modifiable' and 'write'
362" -R sets 'readonly'
363func Test_m_M_R()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200364 let after =<< trim [CODE]
365 call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout")
366 qall
367 [CODE]
368
Bram Moolenaar036b09c2018-09-21 12:54:06 +0200369 if RunVim([], after, '')
370 let lines = readfile('Xtestout')
371 call assert_equal(['1', '1', '0', '200'], lines)
372 endif
373 if RunVim([], after, '-m')
374 let lines = readfile('Xtestout')
375 call assert_equal(['0', '1', '0', '200'], lines)
376 endif
377 if RunVim([], after, '-M')
378 let lines = readfile('Xtestout')
379 call assert_equal(['0', '0', '0', '200'], lines)
380 endif
381 if RunVim([], after, '-R')
382 let lines = readfile('Xtestout')
383 call assert_equal(['1', '1', '1', '10000'], lines)
384 endif
385
386 call delete('Xtestout')
387endfunc
388
zeertzjqf0300fc2023-02-28 16:02:35 +0000389" Test the -A and -H arguments (Arabic and Hebrew modes).
390func Test_A_H_arg()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200391 let after =<< trim [CODE]
Bram Moolenaar9ce79152022-10-12 11:54:34 +0100392 call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout")
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200393 qall
394 [CODE]
395
Bram Moolenaar4b1c9a92018-09-19 21:06:31 +0200396 " Use silent Ex mode to avoid the hit-Enter prompt for the warning that
397 " 'encoding' is not utf-8.
398 if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A')
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200399 let lines = readfile('Xtestout')
400 call assert_equal(['1', '1', '0', '0'], lines)
401 endif
402
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200403 if has('rightleft') && RunVim([], after, '-H')
404 let lines = readfile('Xtestout')
405 call assert_equal(['1', '0', '0', '1'], lines)
406 endif
Bram Moolenaar9ce79152022-10-12 11:54:34 +0100407
408 call delete('Xtestout')
Bram Moolenaar9e81db92018-09-18 22:37:31 +0200409endfunc
410
Bram Moolenaar240309c2021-03-14 16:20:37 +0100411" Test the --echo-wid argument (for GTK GUI only).
412func Test_echo_wid()
413 CheckCanRunGui
414 CheckFeature gui_gtk
415
416 if RunVim([], [], '-g --echo-wid -cq >Xtest_echo_wid')
417 let lines = readfile('Xtest_echo_wid')
418 call assert_equal(1, len(lines))
419 call assert_match('^WID: \d\+$', lines[0])
420 endif
421
422 call delete('Xtest_echo_wid')
423endfunction
424
425" Test the -reverse and +reverse arguments (for GUI only).
426func Test_reverse()
427 CheckCanRunGui
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100428 CheckAnyOf Feature:gui_gtk Feature:gui_motif
Bram Moolenaar240309c2021-03-14 16:20:37 +0100429
430 let after =<< trim [CODE]
431 call writefile([&background], "Xtest_reverse")
432 qall
433 [CODE]
434 if RunVim([], after, '-f -g -reverse')
435 let lines = readfile('Xtest_reverse')
436 call assert_equal(['dark'], lines)
437 endif
438 if RunVim([], after, '-f -g +reverse')
439 let lines = readfile('Xtest_reverse')
440 call assert_equal(['light'], lines)
441 endif
442
443 call delete('Xtest_reverse')
444endfunc
445
446" Test the -background and -foreground arguments (for GUI only).
447func Test_background_foreground()
448 CheckCanRunGui
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100449 CheckAnyOf Feature:gui_gtk Feature:gui_motif
Bram Moolenaar240309c2021-03-14 16:20:37 +0100450
451 " Is there a better way to check the effect of -background & -foreground
452 " other than merely looking at &background (dark or light)?
453 let after =<< trim [CODE]
454 call writefile([&background], "Xtest_fg_bg")
455 qall
456 [CODE]
457 if RunVim([], after, '-f -g -background darkred -foreground yellow')
458 let lines = readfile('Xtest_fg_bg')
459 call assert_equal(['dark'], lines)
460 endif
461 if RunVim([], after, '-f -g -background ivory -foreground darkgreen')
462 let lines = readfile('Xtest_fg_bg')
463 call assert_equal(['light'], lines)
464 endif
465
466 call delete('Xtest_fg_bg')
467endfunc
468
469" Test the -font argument (for GUI only).
470func Test_font()
471 CheckCanRunGui
472 CheckNotMSWindows
473
474 if has('gui_gtk')
475 let font = 'Courier 14'
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100476 elseif has('gui_motif')
Bram Moolenaar240309c2021-03-14 16:20:37 +0100477 let font = '-misc-fixed-bold-*'
478 else
479 throw 'Skipped: test does not set a valid font for this GUI'
480 endif
481
482 let after =<< trim [CODE]
483 call writefile([&guifont], "Xtest_font")
484 qall
485 [CODE]
486
487 if RunVim([], after, '--nofork -g -font "' .. font .. '"')
488 let lines = readfile('Xtest_font')
489 call assert_equal([font], lines)
490 endif
491
492 call delete('Xtest_font')
493endfunc
494
495" Test the -geometry argument (for GUI only).
496func Test_geometry()
497 CheckCanRunGui
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100498 CheckAnyOf Feature:gui_gtk Feature:gui_motif
Bram Moolenaar240309c2021-03-14 16:20:37 +0100499
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100500 if has('gui_motif')
501 " FIXME: With GUI Motif the value of getwinposx(),
Bram Moolenaar240309c2021-03-14 16:20:37 +0100502 " getwinposy() and getwinpos() do not match exactly the
503 " value given in -geometry. Why?
504 " So only check &columns and &lines for those GUIs.
505 let after =<< trim [CODE]
506 call writefile([&columns, &lines], "Xtest_geometry")
507 qall
508 [CODE]
509 if RunVim([], after, '-f -g -geometry 31x13+41+43')
510 let lines = readfile('Xtest_geometry')
511 call assert_equal(['31', '13'], lines)
512 endif
513 else
514 let after =<< trim [CODE]
515 call writefile([&columns, &lines, getwinposx(), getwinposy(), string(getwinpos())], "Xtest_geometry")
516 qall
517 [CODE]
lilydjwg6e0a18f2024-01-29 20:54:28 +0100518 " Hide menu because gtk insists to make the window wide enough to show it completely
Bram Moolenaarfa04eae2022-06-21 14:38:40 +0100519 " Some window managers have a bar at the top that pushes windows down,
520 " need to use at least 130, let's do 150
lilydjwg6e0a18f2024-01-29 20:54:28 +0100521 if RunVim(['set guioptions-=m'], after, '-f -g -geometry 31x13+41+150')
Bram Moolenaar240309c2021-03-14 16:20:37 +0100522 let lines = readfile('Xtest_geometry')
Bram Moolenaarb376aa22021-10-11 16:08:32 +0100523 " Depending on the GUI library and the windowing system the final size
524 " might be a bit different, allow for some tolerance. Tuned based on
525 " actual failures.
Christian Brabandte965b7a2025-06-10 21:29:43 +0200526 call assert_inrange(30, 35, str2nr(lines[0]))
lilydjwg94ff09a2024-01-29 20:14:01 +0100527 " for some reason, the window may contain fewer lines than requested
528 " for GTK, so allow some tolerance
529 call assert_inrange(8, 13, str2nr(lines[1]))
lilydjwg6e0a18f2024-01-29 20:54:28 +0100530 " on Wayland there is no way to set or retrieve window positions
531 if empty($WAYLAND_DISPLAY)
532 call assert_equal('41', lines[2])
533 call assert_equal('150', lines[3])
534 call assert_equal('[41, 150]', lines[4])
535 endif
Bram Moolenaar240309c2021-03-14 16:20:37 +0100536 endif
537 endif
538
539 call delete('Xtest_geometry')
540endfunc
541
542" Test the -iconic argument (for GUI only).
543func Test_iconic()
544 CheckCanRunGui
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100545 CheckAnyOf Feature:gui_gtk Feature:gui_motif
Bram Moolenaar240309c2021-03-14 16:20:37 +0100546
547 call RunVim([], [], '-f -g -iconic -cq')
548
549 " TODO: currently only start vim iconified, but does not
550 " check that vim is iconified. How could this be checked?
551endfunc
552
553
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200554func Test_invalid_args()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200555 " must be able to get the output of Vim.
556 CheckUnix
557 CheckNotGui
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200558
Foxe Chenb90c2392025-06-27 21:10:35 +0200559 for opt in ['-K', '--does-not-exist']
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200560 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
561 call assert_equal(1, v:shell_error)
562 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
563 call assert_equal('Unknown option argument: "' .. opt .. '"', out[1])
564 call assert_equal('More info with: "vim -h"', out[2])
565 endfor
566
567 for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime']
568 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
569 call assert_equal(1, v:shell_error)
570 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
571 call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
572 call assert_equal('More info with: "vim -h"', out[2])
573 endfor
574
575 if has('clientserver')
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200576 for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr',
577 \ '--remote-tab', '--remote-tab-wait',
578 \ '--remote-tab-wait-silent', '--remote-tab-silent',
579 \ '--remote-wait', '--remote-wait-silent',
Bram Moolenaar27821262019-05-08 16:41:09 +0200580 \ '--servername',
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200581 \ ]
582 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
583 call assert_equal(1, v:shell_error)
584 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
585 call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
586 call assert_equal('More info with: "vim -h"', out[2])
587 endfor
588 endif
589
Bram Moolenaar240f7ab2019-05-08 17:58:15 +0200590 if has('gui_gtk')
Bram Moolenaar27821262019-05-08 16:41:09 +0200591 let out = split(system(GetVimCommand() .. ' --display'), "\n")
592 call assert_equal(1, v:shell_error)
593 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
594 call assert_equal('Argument missing after: "--display"', out[1])
595 call assert_equal('More info with: "vim -h"', out[2])
596 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200597
Bram Moolenaar5416b752019-05-08 18:36:43 +0200598 if has('xterm_clipboard')
Bram Moolenaar240f7ab2019-05-08 17:58:15 +0200599 let out = split(system(GetVimCommand() .. ' -display'), "\n")
600 call assert_equal(1, v:shell_error)
601 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
602 call assert_equal('Argument missing after: "-display"', out[1])
603 call assert_equal('More info with: "vim -h"', out[2])
604 endif
605
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200606 let out = split(system(GetVimCommand() .. ' -ix'), "\n")
607 call assert_equal(1, v:shell_error)
608 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
609 call assert_equal('Garbage after option argument: "-ix"', out[1])
610 call assert_equal('More info with: "vim -h"', out[2])
611
612 let out = split(system(GetVimCommand() .. ' - xxx'), "\n")
613 call assert_equal(1, v:shell_error)
614 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
615 call assert_equal('Too many edit arguments: "xxx"', out[1])
616 call assert_equal('More info with: "vim -h"', out[2])
617
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100618 if has('quickfix')
Dominique Pelled176ca32021-09-09 20:45:34 +0200619 " Detect invalid repeated arguments '-t foo -t foo', '-q foo -q foo'.
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100620 for opt in ['-t', '-q']
621 let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n")
622 call assert_equal(1, v:shell_error)
623 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
624 call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1])
625 call assert_equal('More info with: "vim -h"', out[2])
626 endfor
627 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200628
629 for opt in [' -cq', ' --cmd q', ' +', ' -S foo']
630 let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n")
631 call assert_equal(1, v:shell_error)
632 " FIXME: The error message given by Vim is not ideal in case of repeated
633 " -S foo since it does not mention -S.
634 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
635 call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1])
636 call assert_equal('More info with: "vim -h"', out[2])
637 endfor
638
Bram Moolenaar27821262019-05-08 16:41:09 +0200639 if has('gui_gtk')
Dominique Pelle6d37e8e2021-05-06 17:36:55 +0200640 let out = split(system(GetVimCommand() .. ' --socketid'), "\n")
641 call assert_equal(1, v:shell_error)
642 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
643 call assert_equal('Argument missing after: "--socketid"', out[1])
644 call assert_equal('More info with: "vim -h"', out[2])
645
Bram Moolenaar27821262019-05-08 16:41:09 +0200646 for opt in ['--socketid x', '--socketid 0xg']
647 let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
648 call assert_equal(1, v:shell_error)
649 call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
650 call assert_equal('Invalid argument for: "--socketid"', out[1])
651 call assert_equal('More info with: "vim -h"', out[2])
652 endfor
Dominique Pelle6d37e8e2021-05-06 17:36:55 +0200653
Bram Moolenaar27821262019-05-08 16:41:09 +0200654 endif
Bram Moolenaarba9ea912019-05-07 22:10:50 +0200655endfunc
656
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200657func Test_file_args()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200658 let after =<< trim [CODE]
659 call writefile(argv(), "Xtestout")
660 qall
661 [CODE]
662
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200663 if RunVim([], after, '')
664 let lines = readfile('Xtestout')
665 call assert_equal(0, len(lines))
666 endif
667
668 if RunVim([], after, 'one')
669 let lines = readfile('Xtestout')
670 call assert_equal(1, len(lines))
671 call assert_equal('one', lines[0])
672 endif
673
674 if RunVim([], after, 'one two three')
675 let lines = readfile('Xtestout')
676 call assert_equal(3, len(lines))
677 call assert_equal('one', lines[0])
678 call assert_equal('two', lines[1])
679 call assert_equal('three', lines[2])
680 endif
681
682 if RunVim([], after, 'one -c echo two')
683 let lines = readfile('Xtestout')
684 call assert_equal(2, len(lines))
685 call assert_equal('one', lines[0])
686 call assert_equal('two', lines[1])
687 endif
688
689 if RunVim([], after, 'one -- -c echo two')
690 let lines = readfile('Xtestout')
691 call assert_equal(4, len(lines))
692 call assert_equal('one', lines[0])
693 call assert_equal('-c', lines[1])
694 call assert_equal('echo', lines[2])
695 call assert_equal('two', lines[3])
696 endif
697
698 call delete('Xtestout')
699endfunc
700
701func Test_startuptime()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200702 CheckFeature startuptime
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200703 let after = ['qall']
704 if RunVim([], after, '--startuptime Xtestout one')
705 let lines = readfile('Xtestout')
706 let expected = ['--- VIM STARTING ---', 'parsing arguments',
707 \ 'shell init', 'inits 3', 'start termcap', 'opening buffers']
708 let found = []
709 for line in lines
710 for exp in expected
711 if line =~ exp
712 call add(found, exp)
713 endif
714 endfor
715 endfor
716 call assert_equal(expected, found)
717 endif
718 call delete('Xtestout')
719endfunc
Bram Moolenaar3a938382016-08-07 16:36:40 +0200720
Bram Moolenaarc9a9a0a2022-04-12 15:09:23 +0100721func Test_log()
722 CheckFeature channel
723
724 call assert_false(filereadable('Xlogfile'))
725 let after = ['qall']
726 if RunVim([], after, '--log Xlogfile')
727 call assert_equal(1, readfile('Xlogfile')
728 \ ->filter({i, l -> l =~ '==== start log session'})
729 \ ->len())
730 " second time appends to the log
731 if RunVim([], after, '--log Xlogfile')
732 call assert_equal(2, readfile('Xlogfile')
733 \ ->filter({i, l -> l =~ '==== start log session'})
734 \ ->len())
735 endif
736 endif
737 call delete('Xlogfile')
738endfunc
739
Hirohito Higashic5654b82025-02-10 20:55:17 +0100740func Test_log_nonexistent()
741 " this used to crash Vim
Christian Brabandt88ce0c52025-02-11 22:58:20 +0100742 CheckRunVimInTerminal
Christian Brabandt35e02af2025-02-10 22:13:43 +0100743 CheckUnix
Christian Brabandt88ce0c52025-02-11 22:58:20 +0100744 let args = ' -u NONE -i NONE -U NONE --log /X/Xlogfile -X -c qa!'
745 let options = {'term_finish': 'open', 'cmd':
746 \ 'sh -c "' .. GetVimCommand() .. args .. '"'}
747 let buf = RunVimInTerminal('', options)
748 call WaitForAssert({-> assert_match('E484: Can''t open file.*Xlogfile', term_getline(buf, 1))})
749 " terminal job has already finished, so just close the buffer
750 exe buf .. "bw!"
Hirohito Higashic5654b82025-02-10 20:55:17 +0100751endfunc
752
Bram Moolenaar3a938382016-08-07 16:36:40 +0200753func Test_read_stdin()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200754 let after =<< trim [CODE]
755 write Xtestout
756 quit!
757 [CODE]
758
Bram Moolenaar3a938382016-08-07 16:36:40 +0200759 if RunVimPiped([], after, '-', 'echo something | ')
760 let lines = readfile('Xtestout')
Bram Moolenaare4a76ad2016-08-07 16:50:10 +0200761 " MS-Windows adds a space after the word
762 call assert_equal(['something'], split(lines[0]))
Bram Moolenaar3a938382016-08-07 16:36:40 +0200763 endif
764 call delete('Xtestout')
765endfunc
Bram Moolenaar08cab962017-03-04 14:37:18 +0100766
767func Test_progpath()
768 " Tests normally run with "./vim" or "../vim", these must have been expanded
769 " to a full path.
770 if has('unix')
771 call assert_equal('/', v:progpath[0])
772 elseif has('win32')
773 call assert_equal(':', v:progpath[1])
774 call assert_match('[/\\]', v:progpath[2])
775 endif
776
777 " Only expect "vim" to appear in v:progname.
778 call assert_match('vim\c', v:progname)
779endfunc
Bram Moolenaard5d37532017-03-27 23:02:07 +0200780
Abhijit Barik221927b2025-04-06 16:12:06 +0200781func Test_stdin_no_newline()
782 CheckScreendump
783 CheckUnix
784 CheckExecutable bash
785
786 let $PS1 = 'TEST_PROMPT> '
787 let buf = RunVimInTerminal('', #{rows: 20, cmd: 'bash --noprofile --norc'})
788 call TermWait(buf, 100)
789
790 " Write input to temp file
791 call term_sendkeys(buf, "echo hello > temp.txt\<CR>")
792 call TermWait(buf, 200)
793
794 call term_sendkeys(buf, "bash -c '../vim --not-a-term -u NONE -c \":q!\" -' < temp.txt\<CR>")
795 call TermWait(buf, 200)
796
797 " Capture terminal output
798 let lines = []
799 for i in range(1, term_getsize(buf)[0])
800 call add(lines, term_getline(buf, i))
801 endfor
802
803 " Find the command line in output
804 let cmd_line = -1
805 for i in range(len(lines))
806 if lines[i] =~ '.*vim.*--not-a-term.*'
807 let cmd_line = i
808 break
809 endif
810 endfor
811
812 if cmd_line == -1
813 call assert_report('Command line not found in terminal output')
814 else
815 let next_line = -1
816 for i in range(cmd_line + 1, len(lines))
817 if lines[i] =~ '\S'
818 let next_line = i
819 break
820 endif
821 endfor
822
823 if next_line == -1
824 call assert_report('No prompt found after command execution')
825 else
826 call assert_equal(cmd_line + 1, next_line, 'Prompt should be on the immediate next line')
827 call assert_match('.*TEST_PROMPT>.*', lines[next_line], 'Line should contain the prompt PS1')
828 endif
829 endif
830
831 " Clean up temp file and exit shell
832 call term_sendkeys(buf, "rm -f temp.txt\<CR>")
833 call term_sendkeys(buf, "exit\<CR>")
834 call TermWait(buf, 200)
835
836 if job_status(term_getjob(buf)) ==# 'run'
837 call StopVimInTerminal(buf)
838 endif
839
840 unlet $PS1
841endfunc
842
Bram Moolenaard5d37532017-03-27 23:02:07 +0200843func Test_silent_ex_mode()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200844 " must be able to get the output of Vim.
845 CheckUnix
846 CheckNotGui
Bram Moolenaard5d37532017-03-27 23:02:07 +0200847
848 " This caused an ml_get error.
849 let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq')
850 call assert_notmatch('E315:', out)
851endfunc
Bram Moolenaar85045a72017-04-02 16:54:09 +0200852
853func Test_default_term()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200854 " must be able to get the output of Vim.
855 CheckUnix
856 CheckNotGui
Bram Moolenaar85045a72017-04-02 16:54:09 +0200857
858 let save_term = $TERM
Bram Moolenaar08f88b12017-04-02 17:21:16 +0200859 let $TERM = 'unknownxxx'
Bram Moolenaar85045a72017-04-02 16:54:09 +0200860 let out = system(GetVimCommand() . ' -c''set term'' -c cq')
861 call assert_match("defaulting to 'ansi'", out)
862 let $TERM = save_term
863endfunc
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200864
865func Test_zzz_startinsert()
866 " Test :startinsert
Bram Moolenaar56564962022-10-10 22:39:42 +0100867 call writefile(['123456'], 'Xtestout', 'D')
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200868 let after =<< trim [CODE]
869 :startinsert
870 call feedkeys("foobar\<c-o>:wq\<cr>","t")
871 [CODE]
872
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200873 if RunVim([], after, 'Xtestout')
874 let lines = readfile('Xtestout')
875 call assert_equal(['foobar123456'], lines)
876 endif
877 " Test :startinsert!
878 call writefile(['123456'], 'Xtestout')
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200879 let after =<< trim [CODE]
880 :startinsert!
881 call feedkeys("foobar\<c-o>:wq\<cr>","t")
882 [CODE]
883
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200884 if RunVim([], after, 'Xtestout')
885 let lines = readfile('Xtestout')
886 call assert_equal(['123456foobar'], lines)
887 endif
Bram Moolenaar09ca9322017-09-26 17:40:45 +0200888endfunc
Bram Moolenaar97c2c052019-02-22 13:42:07 +0100889
890func Test_issue_3969()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200891 " Can't catch the output of gvim.
892 CheckNotGui
893
Bram Moolenaar97c2c052019-02-22 13:42:07 +0100894 " Check that message is not truncated.
895 let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq')
896 call assert_equal('hello', out)
897endfunc
Bram Moolenaarc75e8122019-04-21 15:55:10 +0200898
899func Test_start_with_tabs()
Drew Vogelea67ba72025-05-07 22:05:17 +0200900 CheckScreendump
Bram Moolenaar494e9062020-05-31 21:28:02 +0200901 CheckRunVimInTerminal
Bram Moolenaarc75e8122019-04-21 15:55:10 +0200902
903 let buf = RunVimInTerminal('-p a b c', {})
904 call VerifyScreenDump(buf, 'Test_start_with_tabs', {})
905
906 " clean up
907 call StopVimInTerminal(buf)
908endfunc
Bram Moolenaar69bf6342019-10-29 04:16:57 +0100909
Bram Moolenaard1f34e62022-01-07 19:24:20 +0000910func Test_start_in_minimal_window()
911 CheckRunVimInTerminal
912
913 let buf = RunVimInTerminal('-c "set nomore"', {'cols': 12, 'rows': 2, 'keep_t_u7': 1})
914 call term_sendkeys(buf, "ahello\<Esc>")
915 call WaitForAssert({-> assert_match('^hello', term_getline(buf, 1))})
916
917 " clean up
918 call StopVimInTerminal(buf)
919endfunc
920
Bram Moolenaar69bf6342019-10-29 04:16:57 +0100921func Test_v_argv()
922 " Can't catch the output of gvim.
923 CheckNotGui
924
925 let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q')
926 let list = out->split("', '")
927 call assert_match('vim', list[0])
928 let idx = index(list, 'arg1')
929 call assert_true(idx > 2)
930 call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:])
931endfunc
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200932
933" Test for the "-r" recovery mode option
934func Test_r_arg()
935 " Can't catch the output of gvim.
936 CheckNotGui
937 CheckUnix
938 CheckEnglish
939 let cmd = GetVimCommand()
940 " There can be swap files anywhere, only check for the headers.
941 let expected =<< trim END
942 Swap files found:.*
943 In current directory:.*
944 In directory \~/tmp:.*
945 In directory /var/tmp:.*
946 In directory /tmp:.*
947 END
948 call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', ''))
949endfunc
950
951" Test for the '-t' option to jump to a tag
952func Test_t_arg()
953 let before =<< trim [CODE]
954 set tags=Xtags
955 [CODE]
956 let after =<< trim [CODE]
957 let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.')
958 call writefile([s], "Xtestout")
959 qall
960 [CODE]
961
962 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
963 \ "first\tXfile1\t/^ \\zsfirst$/",
964 \ "second\tXfile1\t/^ \\zssecond$/",
965 \ "third\tXfile1\t/^ \\zsthird$/"],
Bram Moolenaar56564962022-10-10 22:39:42 +0100966 \ 'Xtags', 'D')
967 call writefile([' first', ' second', ' third'], 'Xfile1', 'D')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200968
Bram Moolenaara2b3e7d2021-03-26 17:24:34 +0100969 for t_arg in ['-t second', '-tsecond']
Dominique Pelled176ca32021-09-09 20:45:34 +0200970 if RunVim(before, after, t_arg)
Bram Moolenaara2b3e7d2021-03-26 17:24:34 +0100971 call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'), t_arg)
972 call delete('Xtestout')
973 endif
974 endfor
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200975endfunc
976
Bram Moolenaar1f33e0a2020-12-19 13:32:07 +0100977" Test the '-T' argument which sets the 'term' option.
978func Test_T_arg()
979 CheckNotGui
980 let after =<< trim [CODE]
981 call writefile([&term], "Xtest_T_arg")
982 qall
983 [CODE]
984
985 for t in ['builtin_dumb', 'builtin_ansi']
986 if RunVim([], after, '-T ' .. t)
987 let lines = readfile('Xtest_T_arg')
988 call assert_equal([t], lines)
989 endif
990 endfor
991
992 call delete('Xtest_T_arg')
993endfunc
994
995" Test the '-x' argument to read/write encrypted files.
996func Test_x_arg()
997 CheckRunVimInTerminal
998 CheckFeature cryptv
999
1000 " Create an encrypted file Xtest_x_arg.
1001 let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
1002 call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
1003 call term_sendkeys(buf, "foo\n")
1004 call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
1005 call term_sendkeys(buf, "foo\n")
1006 call WaitForAssert({-> assert_match(' All$', term_getline(buf, 10))})
1007 call term_sendkeys(buf, "itest\<Esc>:w\<Enter>")
1008 call WaitForAssert({-> assert_match('"Xtest_x_arg" \[New\]\[blowfish2\] 1L, 5B written',
1009 \ term_getline(buf, 10))})
1010 call StopVimInTerminal(buf)
1011
1012 " Read the encrypted file and check that it contains the expected content "test"
1013 let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
1014 call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
1015 call term_sendkeys(buf, "foo\n")
1016 call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
1017 call term_sendkeys(buf, "foo\n")
1018 call WaitForAssert({-> assert_match('^test', term_getline(buf, 1))})
1019 call StopVimInTerminal(buf)
1020
1021 call delete('Xtest_x_arg')
1022endfunc
1023
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001024" Test for entering the insert mode on startup
1025func Test_start_insertmode()
1026 let before =<< trim [CODE]
1027 set insertmode
1028 [CODE]
1029 let after =<< trim [CODE]
1030 call writefile(['insertmode=' .. &insertmode], 'Xtestout')
1031 qall
1032 [CODE]
1033 if RunVim(before, after, '')
1034 call assert_equal(['insertmode=1'], readfile('Xtestout'))
1035 call delete('Xtestout')
1036 endif
1037endfunc
1038
1039" Test for enabling the binary mode on startup
1040func Test_b_arg()
1041 let after =<< trim [CODE]
1042 call writefile(['binary=' .. &binary], 'Xtestout')
1043 qall
1044 [CODE]
1045 if RunVim([], after, '-b')
1046 call assert_equal(['binary=1'], readfile('Xtestout'))
1047 call delete('Xtestout')
1048 endif
1049endfunc
1050
1051" Test for enabling the lisp mode on startup
1052func Test_l_arg()
1053 let after =<< trim [CODE]
1054 let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch
1055 call writefile([s], 'Xtestout')
1056 qall
1057 [CODE]
1058 if RunVim([], after, '-l')
1059 call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout'))
1060 call delete('Xtestout')
1061 endif
1062endfunc
1063
1064" Test for specifying a non-existing vimrc file using "-u"
1065func Test_missing_vimrc()
Bram Moolenaar494e9062020-05-31 21:28:02 +02001066 CheckRunVimInTerminal
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001067 let after =<< trim [CODE]
1068 call assert_match('^E282:', v:errmsg)
1069 call writefile(v:errors, 'Xtestout')
1070 [CODE]
Bram Moolenaar56564962022-10-10 22:39:42 +01001071 call writefile(after, 'Xafter', 'D')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001072
1073 let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter'
1074 let buf = term_start(cmd, {'term_rows' : 10})
1075 call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001076 call TermWait(buf)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001077 call term_sendkeys(buf, "\n:")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001078 call TermWait(buf)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001079 call WaitForAssert({-> assert_match(':', term_getline(buf, 10))})
1080 call StopVimInTerminal(buf)
1081 call assert_equal([], readfile('Xtestout'))
Bram Moolenaar56564962022-10-10 22:39:42 +01001082
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001083 call delete('Xtestout')
1084endfunc
1085
1086" Test for using the $VIMINIT environment variable
1087func Test_VIMINIT()
1088 let after =<< trim [CODE]
1089 call assert_equal(1, exists('viminit_found'))
1090 call assert_equal('yes', viminit_found)
1091 call writefile(v:errors, 'Xtestout')
1092 qall
1093 [CODE]
Bram Moolenaar56564962022-10-10 22:39:42 +01001094 call writefile(after, 'Xafter', 'D')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001095 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1096 call setenv('VIMINIT', 'let viminit_found="yes"')
1097 exe "silent !" . cmd
1098 call assert_equal([], readfile('Xtestout'))
Bram Moolenaar56564962022-10-10 22:39:42 +01001099
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001100 call delete('Xtestout')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001101endfunc
1102
1103" Test for using the $EXINIT environment variable
1104func Test_EXINIT()
1105 let after =<< trim [CODE]
1106 call assert_equal(1, exists('exinit_found'))
1107 call assert_equal('yes', exinit_found)
1108 call writefile(v:errors, 'Xtestout')
1109 qall
1110 [CODE]
Bram Moolenaar56564962022-10-10 22:39:42 +01001111 call writefile(after, 'Xafter', 'D')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001112 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
Christian Brabandt28155d02025-02-23 19:55:09 +01001113 call setenv('HOME', '/non-existing')
1114 call setenv('XDG_CONFIG_HOME', '/non-existing')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001115 call setenv('EXINIT', 'let exinit_found="yes"')
1116 exe "silent !" . cmd
1117 call assert_equal([], readfile('Xtestout'))
Bram Moolenaar56564962022-10-10 22:39:42 +01001118
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001119 call delete('Xtestout')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001120endfunc
1121
1122" Test for using the 'exrc' option
1123func Test_exrc()
1124 let after =<< trim [CODE]
1125 call assert_equal(1, &exrc)
1126 call assert_equal(1, &secure)
1127 call assert_equal(37, exrc_found)
1128 call writefile(v:errors, 'Xtestout')
1129 qall
1130 [CODE]
Bram Moolenaar56564962022-10-10 22:39:42 +01001131 call mkdir('Xrcdir', 'R')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001132 call writefile(['let exrc_found=37'], 'Xrcdir/.exrc')
1133 call writefile(after, 'Xrcdir/Xafter')
1134 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xrcdir" --cmd "set enc=utf8 exrc secure"'
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001135 exe "silent !" . cmd
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001136 call assert_equal([], readfile('Xrcdir/Xtestout'))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001137endfunc
1138
1139" Test for starting Vim with a non-terminal as input/output
1140func Test_io_not_a_terminal()
1141 " Can't catch the output of gvim.
1142 CheckNotGui
1143 CheckUnix
1144 CheckEnglish
1145 let l = systemlist(GetVimProg() .. ' --ttyfail')
1146 call assert_equal(['Vim: Warning: Output is not to a terminal',
1147 \ 'Vim: Warning: Input is not from a terminal'], l)
1148endfunc
1149
Bram Moolenaar7007e312021-03-27 12:11:33 +01001150" Test for --not-a-term avoiding escape codes.
1151func Test_not_a_term()
1152 CheckUnix
1153 CheckNotGui
1154
1155 if &shellredir =~ '%s'
1156 let redir = printf(&shellredir, 'Xvimout')
1157 else
1158 let redir = &shellredir .. ' Xvimout'
1159 endif
1160
1161 " Without --not-a-term there are a few escape sequences.
1162 " This will take 2 seconds because of the missing --not-a-term
1163 let cmd = GetVimProg() .. ' --cmd quit ' .. redir
1164 exe "silent !" . cmd
1165 call assert_match("\<Esc>", readfile('Xvimout')->join())
1166 call delete('Xvimout')
1167
1168 " With --not-a-term there are no escape sequences.
1169 let cmd = GetVimProg() .. ' --not-a-term --cmd quit ' .. redir
1170 exe "silent !" . cmd
1171 call assert_notmatch("\<Esc>", readfile('Xvimout')->join())
1172 call delete('Xvimout')
1173endfunc
1174
Bram Moolenaar5939c352022-09-24 12:50:45 +01001175" Test quitting with CTRL-C when output is redirected.
1176func Test_redirect_Ctrl_C()
1177 CheckUnix
1178 CheckNotGui
1179 CheckRunVimInTerminal
1180
1181 let buf = Run_shell_in_terminal({})
1182 " Wait for the shell to display a prompt
1183 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
1184
1185 call term_sendkeys(buf, GetVimProg() .. " | grep word\<CR>")
1186 call WaitForAssert({-> assert_match("Output is not to a terminal", getline(1, 4)->join())})
1187 " wait for the hard coded delay, otherwise the CTRL-C interrupts startup
1188 sleep 2
1189 call term_sendkeys(buf, "\<C-C>")
1190 sleep 100m
1191 call term_sendkeys(buf, "exit\<CR>")
1192 call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
1193
1194 exe buf . 'bwipe!'
1195 unlet g:job
1196endfunc
1197
Bram Moolenaar7007e312021-03-27 12:11:33 +01001198
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001199" Test for the "-w scriptout" argument
1200func Test_w_arg()
1201 " Can't catch the output of gvim.
1202 CheckNotGui
Bram Moolenaar0a1a6a12021-03-26 14:14:18 +01001203
Bram Moolenaar56564962022-10-10 22:39:42 +01001204 call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'bD')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001205 if RunVim([], [], '-s Xscriptin -w Xscriptout')
1206 call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout'))
1207 call delete('Xscriptout')
1208 endif
1209 call delete('Xscriptin')
1210
1211 " Test for failing to open the script output file. This test works only when
1212 " the language is English.
1213 if v:lang == "C" || v:lang =~ '^[Ee]n'
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001214 call mkdir("Xargdir")
1215 let m = system(GetVimCommand() .. " -w Xargdir")
1216 call assert_equal("Cannot open for script output: \"Xargdir\"\n", m)
1217 call delete("Xargdir", 'rf')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001218 endif
Bram Moolenaar0a1a6a12021-03-26 14:14:18 +01001219
1220 " A number argument sets the 'window' option
1221 call writefile(["iwindow \<C-R>=&window\<CR>\<Esc>:wq! Xresult\<CR>"], 'Xscriptin', 'b')
Bram Moolenaara2b3e7d2021-03-26 17:24:34 +01001222 for w_arg in ['-w 17', '-w17']
1223 if RunVim([], [], '-s Xscriptin ' .. w_arg)
1224 call assert_equal(["window 17"], readfile('Xresult'), w_arg)
1225 call delete('Xresult')
1226 endif
1227 endfor
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001228endfunc
1229
1230" Test for the "-s scriptin" argument
1231func Test_s_arg()
1232 " Can't catch the output of gvim.
1233 CheckNotGui
1234 CheckEnglish
1235 " Test for failing to open the script input file.
1236 let m = system(GetVimCommand() .. " -s abcxyz")
1237 call assert_equal("Cannot open for reading: \"abcxyz\"\n", m)
1238
Bram Moolenaar56564962022-10-10 22:39:42 +01001239 call writefile([], 'Xinput', 'D')
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001240 let m = system(GetVimCommand() .. " -s Xinput -s Xinput")
1241 call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m)
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001242endfunc
1243
1244" Test for the "-n" (no swap file) argument
1245func Test_n_arg()
1246 let after =<< trim [CODE]
1247 call assert_equal(0, &updatecount)
1248 call writefile(v:errors, 'Xtestout')
1249 qall
1250 [CODE]
1251 if RunVim([], after, '-n')
1252 call assert_equal([], readfile('Xtestout'))
1253 call delete('Xtestout')
1254 endif
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001255endfunc
1256
1257" Test for the "-h" (help) argument
1258func Test_h_arg()
1259 " Can't catch the output of gvim.
1260 CheckNotGui
1261 let l = systemlist(GetVimProg() .. ' -h')
1262 call assert_match('^VIM - Vi IMproved', l[0])
1263 let l = systemlist(GetVimProg() .. ' -?')
1264 call assert_match('^VIM - Vi IMproved', l[0])
1265endfunc
1266
1267" Test for the "-F" (farsi) argument
1268func Test_F_arg()
1269 " Can't catch the output of gvim.
1270 CheckNotGui
1271 let l = systemlist(GetVimProg() .. ' -F')
1272 call assert_match('^E27:', l[0])
1273endfunc
1274
1275" Test for the "-E" (improved Ex mode) argument
1276func Test_E_arg()
1277 let after =<< trim [CODE]
1278 call assert_equal('cv', mode(1))
1279 call writefile(v:errors, 'Xtestout')
1280 qall
1281 [CODE]
1282 if RunVim([], after, '-E')
1283 call assert_equal([], readfile('Xtestout'))
1284 call delete('Xtestout')
1285 endif
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001286endfunc
1287
Bram Moolenaarc5cf3692021-03-20 22:16:56 +01001288" Test for the "-D" (debugger) argument
1289func Test_D_arg()
1290 CheckRunVimInTerminal
1291
1292 let cmd = GetVimCommandCleanTerm() .. ' -D'
1293 let buf = term_start(cmd, {'term_rows' : 10})
1294 call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
1295
1296 call WaitForAssert({-> assert_equal('Entering Debug mode. Type "cont" to continue.',
1297 \ term_getline(buf, 7))})
1298 call WaitForAssert({-> assert_equal('>', term_getline(buf, 10))})
1299
1300 call StopVimInTerminal(buf)
1301endfunc
1302
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001303" Test for too many edit argument errors
1304func Test_too_many_edit_args()
1305 " Can't catch the output of gvim.
1306 CheckNotGui
1307 CheckEnglish
1308 let l = systemlist(GetVimProg() .. ' - -')
1309 call assert_match('^Too many edit arguments: "-"', l[1])
1310endfunc
1311
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001312" Test starting vim with various names: vim, ex, view, evim, etc.
1313func Test_progname()
1314 CheckUnix
1315
Bram Moolenaar56564962022-10-10 22:39:42 +01001316 call mkdir('Xprogname', 'pD')
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001317 call writefile(['silent !date',
1318 \ 'call writefile([mode(1), '
1319 \ .. '&insertmode, &diff, &readonly, &updatecount, '
1320 \ .. 'join(split(execute("message"), "\n")[1:])], "Xprogname_out")',
1321 \ 'qall'], 'Xprogname_after')
1322
1323 " +---------------------------------------------- progname
1324 " | +--------------------------------- mode(1)
1325 " | | +--------------------------- &insertmode
1326 " | | | +---------------------- &diff
1327 " | | | | +----------------- &readonly
1328 " | | | | | +-------- &updatecount
1329 " | | | | | | +--- :messages
1330 " | | | | | | |
1331 let expectations = {
1332 \ 'vim': ['n', '0', '0', '0', '200', ''],
1333 \ 'gvim': ['n', '0', '0', '0', '200', ''],
1334 \ 'ex': ['ce', '0', '0', '0', '200', ''],
1335 \ 'exim': ['cv', '0', '0', '0', '200', ''],
1336 \ 'view': ['n', '0', '0', '1', '10000', ''],
1337 \ 'gview': ['n', '0', '0', '1', '10000', ''],
1338 \ 'evim': ['n', '1', '0', '0', '200', ''],
1339 \ 'eview': ['n', '1', '0', '1', '10000', ''],
1340 \ 'rvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1341 \ 'rgvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1342 \ 'rview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1343 \ 'rgview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
1344 \ 'vimdiff': ['n', '0', '1', '0', '200', ''],
1345 \ 'gvimdiff': ['n', '0', '1', '0', '200', '']}
1346
1347 let prognames = ['vim', 'gvim', 'ex', 'exim', 'view', 'gview',
1348 \ 'evim', 'eview', 'rvim', 'rgvim', 'rview', 'rgview',
1349 \ 'vimdiff', 'gvimdiff']
1350
1351 for progname in prognames
Bram Moolenaar240309c2021-03-14 16:20:37 +01001352 let run_with_gui = (progname =~# 'g') || (has('gui') && (progname ==# 'evim' || progname ==# 'eview'))
1353
1354 if empty($DISPLAY) && run_with_gui
1355 " Can't run gvim, gview (etc.) if $DISPLAY is not setup.
1356 continue
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001357 endif
1358
1359 exe 'silent !ln -s -f ' ..exepath(GetVimProg()) .. ' Xprogname/' .. progname
1360
1361 let stdout_stderr = ''
1362 if progname =~# 'g'
1363 let stdout_stderr = system('Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after')
1364 else
1365 exe 'sil !Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after'
1366 endif
1367
1368 if progname =~# 'g' && !has('gui')
1369 call assert_equal("E25: GUI cannot be used: Not enabled at compile time\n", stdout_stderr, progname)
1370 else
Bram Moolenaar240309c2021-03-14 16:20:37 +01001371 " GUI motif can output some warnings like this:
1372 " Warning:
1373 " Name: subMenu
1374 " Class: XmCascadeButton
1375 " Illegal mnemonic character; Could not convert X KEYSYM to a keycode
1376 " So don't check that stderr is empty with GUI Motif.
1377 if run_with_gui && !has('gui_motif')
1378 call assert_equal('', stdout_stderr, progname)
1379 endif
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001380 call assert_equal(expectations[progname], readfile('Xprogname_out'), progname)
1381 endif
1382
1383 call delete('Xprogname/' .. progname)
1384 call delete('Xprogname_out')
1385 endfor
1386
1387 call delete('Xprogname_after')
Bram Moolenaardf4c9af2021-01-11 19:54:42 +01001388endfunc
1389
Yegappan Lakshmanan36f96a52021-05-13 18:33:16 +02001390" Test for doing a write from .vimrc
1391func Test_write_in_vimrc()
Bram Moolenaar56564962022-10-10 22:39:42 +01001392 call writefile(['silent! write'], 'Xvimrc', 'D')
Yegappan Lakshmanan36f96a52021-05-13 18:33:16 +02001393 let after =<< trim [CODE]
1394 call assert_match('E32: ', v:errmsg)
1395 call writefile(v:errors, 'Xtestout')
1396 qall
1397 [CODE]
1398 if RunVim([], after, '-u Xvimrc')
1399 call assert_equal([], readfile('Xtestout'))
1400 call delete('Xtestout')
1401 endif
Yegappan Lakshmanan36f96a52021-05-13 18:33:16 +02001402endfunc
1403
Bram Moolenaara97c3632021-06-15 22:39:11 +02001404func Test_echo_true_in_cmd()
Bram Moolenaarb90ac5e2021-06-16 10:59:36 +02001405 CheckNotGui
1406
Bram Moolenaara97c3632021-06-15 22:39:11 +02001407 let lines =<< trim END
1408 echo v:true
1409 call writefile(['done'], 'Xresult')
Bram Moolenaar55b6b602021-06-15 23:05:59 +02001410 quit
Bram Moolenaara97c3632021-06-15 22:39:11 +02001411 END
Bram Moolenaar56564962022-10-10 22:39:42 +01001412 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar55b6b602021-06-15 23:05:59 +02001413 if RunVim([], [], '--cmd "source Xscript"')
Bram Moolenaara97c3632021-06-15 22:39:11 +02001414 call assert_equal(['done'], readfile('Xresult'))
1415 endif
Bram Moolenaar56564962022-10-10 22:39:42 +01001416
Bram Moolenaara97c3632021-06-15 22:39:11 +02001417 call delete('Xresult')
Bram Moolenaara97c3632021-06-15 22:39:11 +02001418endfunc
1419
Bram Moolenaard3710cf2021-10-04 23:13:13 +01001420func Test_rename_buffer_on_startup()
Bram Moolenaar6d197982021-10-05 01:19:53 +01001421 CheckUnix
1422
Bram Moolenaard3710cf2021-10-04 23:13:13 +01001423 let lines =<< trim END
1424 call writefile(['done'], 'Xresult')
1425 qa!
1426 END
Bram Moolenaar56564962022-10-10 22:39:42 +01001427 call writefile(lines, 'Xscript', 'D')
Bram Moolenaard3710cf2021-10-04 23:13:13 +01001428 if RunVim([], [], "--clean -e -s --cmd 'file x|new|file x' --cmd 'so Xscript'")
1429 call assert_equal(['done'], readfile('Xresult'))
1430 endif
Bram Moolenaar56564962022-10-10 22:39:42 +01001431
Bram Moolenaard3710cf2021-10-04 23:13:13 +01001432 call delete('Xresult')
1433endfunc
1434
Christian Brabandtba9aed42023-10-14 11:38:12 +02001435" Test that -cq works as expected
1436func Test_cq_zero_exmode()
Christian Brabandtc2900092023-10-17 18:10:13 +02001437 CheckFeature channel
1438
Christian Brabandtba9aed42023-10-14 11:38:12 +02001439 let logfile = 'Xcq_log.txt'
1440 let out = system(GetVimCommand() .. ' --clean --log ' .. logfile .. ' -es -X -c "argdelete foobar" -c"7cq"')
1441 call assert_equal(8, v:shell_error)
zeertzjq67fe77d2025-04-20 10:21:18 +02001442 let log = filter(readfile(logfile), {idx, val -> val =~ "E480:"})
Christian Brabandtba9aed42023-10-14 11:38:12 +02001443 call assert_match('E480: No match: foobar', log[0])
1444 call delete(logfile)
1445
1446 " wrap-around on Unix
1447 let out = system(GetVimCommand() .. ' --clean --log ' .. logfile .. ' -es -X -c "argdelete foobar" -c"255cq"')
1448 if !has('win32')
1449 call assert_equal(0, v:shell_error)
1450 else
1451 call assert_equal(256, v:shell_error)
1452 endif
zeertzjq67fe77d2025-04-20 10:21:18 +02001453 let log = filter(readfile(logfile), {idx, val -> val =~ "E480:"})
Christian Brabandtba9aed42023-10-14 11:38:12 +02001454 call assert_match('E480: No match: foobar', log[0])
1455 call delete('Xcq_log.txt')
1456endfunc
Bram Moolenaard3710cf2021-10-04 23:13:13 +01001457
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001458" vim: shiftwidth=2 sts=2 expandtab