blob: 08a107e8157fee4f14c7fa5cf63642754393c3ac [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
4
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)
11endfunc
Bram Moolenaar66459b72016-08-06 19:01:55 +020012
13" Verify the order in which plugins are loaded:
14" 1. plugins in non-after directories
15" 2. packages
16" 3. plugins in after directories
17func Test_after_comes_later()
Bram Moolenaar32860432016-08-06 19:24:23 +020018 if !has('packages')
19 return
20 endif
Bram Moolenaar66459b72016-08-06 19:01:55 +020021 let before = [
Bram Moolenaar446cce62016-08-06 21:37:27 +020022 \ 'set nocp viminfo+=nviminfo',
23 \ 'set guioptions+=M',
Bram Moolenaar66459b72016-08-06 19:01:55 +020024 \ 'let $HOME = "/does/not/exist"',
25 \ 'set loadplugins',
26 \ 'set rtp=Xhere,Xafter',
27 \ 'set packpath=Xhere,Xafter',
28 \ 'set nomore',
29 \ ]
30 let after = [
31 \ 'redir! > Xtestout',
32 \ 'scriptnames',
33 \ 'redir END',
34 \ 'quit',
35 \ ]
36 call mkdir('Xhere/plugin', 'p')
37 call writefile(['let done = 1'], 'Xhere/plugin/here.vim')
38 call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p')
39 call writefile(['let done = 1'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim')
40
41 call mkdir('Xafter/plugin', 'p')
42 call writefile(['let done = 1'], 'Xafter/plugin/later.vim')
43
Bram Moolenaar472a0a82016-08-06 22:31:42 +020044 if RunVim(before, after, '')
Bram Moolenaar66459b72016-08-06 19:01:55 +020045
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020046 let lines = readfile('Xtestout')
47 let expected = ['Xbefore.vim', 'here.vim', 'foo.vim', 'later.vim', 'Xafter.vim']
48 let found = []
49 for line in lines
50 for one in expected
51 if line =~ one
52 call add(found, one)
53 endif
54 endfor
Bram Moolenaar66459b72016-08-06 19:01:55 +020055 endfor
Bram Moolenaar83b3c3d2016-08-06 19:16:43 +020056 call assert_equal(expected, found)
57 endif
Bram Moolenaar66459b72016-08-06 19:01:55 +020058
59 call delete('Xtestout')
60 call delete('Xhere', 'rf')
61 call delete('Xafter', 'rf')
62endfunc
Bram Moolenaar472a0a82016-08-06 22:31:42 +020063
Bram Moolenaarce876aa2017-06-04 17:47:42 +020064func Test_pack_in_rtp_when_plugins_run()
65 if !has('packages')
66 return
67 endif
68 let before = [
69 \ 'set nocp viminfo+=nviminfo',
70 \ 'set guioptions+=M',
71 \ 'let $HOME = "/does/not/exist"',
72 \ 'set loadplugins',
73 \ 'set rtp=Xhere',
74 \ 'set packpath=Xhere',
75 \ 'set nomore',
76 \ ]
77 let after = [
78 \ 'quit',
79 \ ]
80 call mkdir('Xhere/plugin', 'p')
81 call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim')
82 call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p')
83 call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim')
84
85 if RunVim(before, after, '')
86
87 let lines = filter(readfile('Xtestout'), '!empty(v:val)')
88 call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0))
89 call assert_match('autoloaded foo', get(lines, 1))
90 endif
91
92 call delete('Xtestout')
93 call delete('Xhere', 'rf')
94endfunc
95
Bram Moolenaar472a0a82016-08-06 22:31:42 +020096func Test_help_arg()
Bram Moolenaar3321e9d2016-08-06 23:03:59 +020097 if !has('unix') && has('gui')
98 " this doesn't work with gvim on MS-Windows
99 return
100 endif
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200101 if RunVim([], [], '--help >Xtestout')
102 let lines = readfile('Xtestout')
103 call assert_true(len(lines) > 20)
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200104 call assert_match('Vi IMproved', lines[0])
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200105
106 " check if couple of lines are there
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200107 let found = []
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200108 for line in lines
109 if line =~ '-R.*Readonly mode'
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200110 call add(found, 'Readonly mode')
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200111 endif
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200112 " Watch out for a second --version line in the Gnome version.
113 if line =~ '--version.*Print version information and exit'
114 call add(found, "--version")
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200115 endif
116 endfor
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +0200117 call assert_equal(['Readonly mode', '--version'], found)
Bram Moolenaar472a0a82016-08-06 22:31:42 +0200118 endif
119 call delete('Xtestout')
120endfunc
Bram Moolenaarba98bef2016-08-07 15:51:39 +0200121
122func Test_compatible_args()
123 let after = [
124 \ 'call writefile([string(&compatible)], "Xtestout")',
125 \ 'set viminfo+=nviminfo',
126 \ 'quit',
127 \ ]
128 if RunVim([], after, '-C')
129 let lines = readfile('Xtestout')
130 call assert_equal('1', lines[0])
131 endif
132
133 if RunVim([], after, '-N')
134 let lines = readfile('Xtestout')
135 call assert_equal('0', lines[0])
136 endif
137
138 call delete('Xtestout')
139endfunc
140
141func Test_file_args()
142 let after = [
143 \ 'call writefile(argv(), "Xtestout")',
144 \ 'qall',
145 \ ]
146 if RunVim([], after, '')
147 let lines = readfile('Xtestout')
148 call assert_equal(0, len(lines))
149 endif
150
151 if RunVim([], after, 'one')
152 let lines = readfile('Xtestout')
153 call assert_equal(1, len(lines))
154 call assert_equal('one', lines[0])
155 endif
156
157 if RunVim([], after, 'one two three')
158 let lines = readfile('Xtestout')
159 call assert_equal(3, len(lines))
160 call assert_equal('one', lines[0])
161 call assert_equal('two', lines[1])
162 call assert_equal('three', lines[2])
163 endif
164
165 if RunVim([], after, 'one -c echo two')
166 let lines = readfile('Xtestout')
167 call assert_equal(2, len(lines))
168 call assert_equal('one', lines[0])
169 call assert_equal('two', lines[1])
170 endif
171
172 if RunVim([], after, 'one -- -c echo two')
173 let lines = readfile('Xtestout')
174 call assert_equal(4, len(lines))
175 call assert_equal('one', lines[0])
176 call assert_equal('-c', lines[1])
177 call assert_equal('echo', lines[2])
178 call assert_equal('two', lines[3])
179 endif
180
181 call delete('Xtestout')
182endfunc
183
184func Test_startuptime()
185 if !has('startuptime')
186 return
187 endif
188 let after = ['qall']
189 if RunVim([], after, '--startuptime Xtestout one')
190 let lines = readfile('Xtestout')
191 let expected = ['--- VIM STARTING ---', 'parsing arguments',
192 \ 'shell init', 'inits 3', 'start termcap', 'opening buffers']
193 let found = []
194 for line in lines
195 for exp in expected
196 if line =~ exp
197 call add(found, exp)
198 endif
199 endfor
200 endfor
201 call assert_equal(expected, found)
202 endif
203 call delete('Xtestout')
204endfunc
Bram Moolenaar3a938382016-08-07 16:36:40 +0200205
206func Test_read_stdin()
207 let after = [
208 \ 'write Xtestout',
209 \ 'quit!',
210 \ ]
211 if RunVimPiped([], after, '-', 'echo something | ')
212 let lines = readfile('Xtestout')
Bram Moolenaare4a76ad2016-08-07 16:50:10 +0200213 " MS-Windows adds a space after the word
214 call assert_equal(['something'], split(lines[0]))
Bram Moolenaar3a938382016-08-07 16:36:40 +0200215 endif
216 call delete('Xtestout')
217endfunc
Bram Moolenaar08cab962017-03-04 14:37:18 +0100218
219func Test_progpath()
220 " Tests normally run with "./vim" or "../vim", these must have been expanded
221 " to a full path.
222 if has('unix')
223 call assert_equal('/', v:progpath[0])
224 elseif has('win32')
225 call assert_equal(':', v:progpath[1])
226 call assert_match('[/\\]', v:progpath[2])
227 endif
228
229 " Only expect "vim" to appear in v:progname.
230 call assert_match('vim\c', v:progname)
231endfunc
Bram Moolenaard5d37532017-03-27 23:02:07 +0200232
233func Test_silent_ex_mode()
234 if !has('unix') || has('gui_running')
235 " can't get output of Vim.
236 return
237 endif
238
239 " This caused an ml_get error.
240 let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq')
241 call assert_notmatch('E315:', out)
242endfunc
Bram Moolenaar85045a72017-04-02 16:54:09 +0200243
244func Test_default_term()
245 if !has('unix') || has('gui_running')
246 " can't get output of Vim.
247 return
248 endif
249
250 let save_term = $TERM
Bram Moolenaar08f88b12017-04-02 17:21:16 +0200251 let $TERM = 'unknownxxx'
Bram Moolenaar85045a72017-04-02 16:54:09 +0200252 let out = system(GetVimCommand() . ' -c''set term'' -c cq')
253 call assert_match("defaulting to 'ansi'", out)
254 let $TERM = save_term
255endfunc