blob: bce431f7ddc21f2bb4bc7a3302d6a129e2fbf37b [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
64func Test_help_arg()
Bram Moolenaar3321e9d2016-08-06 23:03:59 +020065 if !has('unix') && has('gui')
66 " this doesn't work with gvim on MS-Windows
67 return
68 endif
Bram Moolenaar472a0a82016-08-06 22:31:42 +020069 if RunVim([], [], '--help >Xtestout')
70 let lines = readfile('Xtestout')
71 call assert_true(len(lines) > 20)
Bram Moolenaarba98bef2016-08-07 15:51:39 +020072 call assert_match('Vi IMproved', lines[0])
Bram Moolenaar472a0a82016-08-06 22:31:42 +020073
74 " check if couple of lines are there
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +020075 let found = []
Bram Moolenaar472a0a82016-08-06 22:31:42 +020076 for line in lines
77 if line =~ '-R.*Readonly mode'
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +020078 call add(found, 'Readonly mode')
Bram Moolenaar472a0a82016-08-06 22:31:42 +020079 endif
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +020080 " Watch out for a second --version line in the Gnome version.
81 if line =~ '--version.*Print version information and exit'
82 call add(found, "--version")
Bram Moolenaar472a0a82016-08-06 22:31:42 +020083 endif
84 endfor
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +020085 call assert_equal(['Readonly mode', '--version'], found)
Bram Moolenaar472a0a82016-08-06 22:31:42 +020086 endif
87 call delete('Xtestout')
88endfunc
Bram Moolenaarba98bef2016-08-07 15:51:39 +020089
90func Test_compatible_args()
91 let after = [
92 \ 'call writefile([string(&compatible)], "Xtestout")',
93 \ 'set viminfo+=nviminfo',
94 \ 'quit',
95 \ ]
96 if RunVim([], after, '-C')
97 let lines = readfile('Xtestout')
98 call assert_equal('1', lines[0])
99 endif
100
101 if RunVim([], after, '-N')
102 let lines = readfile('Xtestout')
103 call assert_equal('0', lines[0])
104 endif
105
106 call delete('Xtestout')
107endfunc
108
109func Test_file_args()
110 let after = [
111 \ 'call writefile(argv(), "Xtestout")',
112 \ 'qall',
113 \ ]
114 if RunVim([], after, '')
115 let lines = readfile('Xtestout')
116 call assert_equal(0, len(lines))
117 endif
118
119 if RunVim([], after, 'one')
120 let lines = readfile('Xtestout')
121 call assert_equal(1, len(lines))
122 call assert_equal('one', lines[0])
123 endif
124
125 if RunVim([], after, 'one two three')
126 let lines = readfile('Xtestout')
127 call assert_equal(3, len(lines))
128 call assert_equal('one', lines[0])
129 call assert_equal('two', lines[1])
130 call assert_equal('three', lines[2])
131 endif
132
133 if RunVim([], after, 'one -c echo two')
134 let lines = readfile('Xtestout')
135 call assert_equal(2, len(lines))
136 call assert_equal('one', lines[0])
137 call assert_equal('two', lines[1])
138 endif
139
140 if RunVim([], after, 'one -- -c echo two')
141 let lines = readfile('Xtestout')
142 call assert_equal(4, len(lines))
143 call assert_equal('one', lines[0])
144 call assert_equal('-c', lines[1])
145 call assert_equal('echo', lines[2])
146 call assert_equal('two', lines[3])
147 endif
148
149 call delete('Xtestout')
150endfunc
151
152func Test_startuptime()
153 if !has('startuptime')
154 return
155 endif
156 let after = ['qall']
157 if RunVim([], after, '--startuptime Xtestout one')
158 let lines = readfile('Xtestout')
159 let expected = ['--- VIM STARTING ---', 'parsing arguments',
160 \ 'shell init', 'inits 3', 'start termcap', 'opening buffers']
161 let found = []
162 for line in lines
163 for exp in expected
164 if line =~ exp
165 call add(found, exp)
166 endif
167 endfor
168 endfor
169 call assert_equal(expected, found)
170 endif
171 call delete('Xtestout')
172endfunc
Bram Moolenaar3a938382016-08-07 16:36:40 +0200173
174func Test_read_stdin()
175 let after = [
176 \ 'write Xtestout',
177 \ 'quit!',
178 \ ]
179 if RunVimPiped([], after, '-', 'echo something | ')
180 let lines = readfile('Xtestout')
Bram Moolenaare4a76ad2016-08-07 16:50:10 +0200181 " MS-Windows adds a space after the word
182 call assert_equal(['something'], split(lines[0]))
Bram Moolenaar3a938382016-08-07 16:36:40 +0200183 endif
184 call delete('Xtestout')
185endfunc
Bram Moolenaar08cab962017-03-04 14:37:18 +0100186
187func Test_progpath()
188 " Tests normally run with "./vim" or "../vim", these must have been expanded
189 " to a full path.
190 if has('unix')
191 call assert_equal('/', v:progpath[0])
192 elseif has('win32')
193 call assert_equal(':', v:progpath[1])
194 call assert_match('[/\\]', v:progpath[2])
195 endif
196
197 " Only expect "vim" to appear in v:progname.
198 call assert_match('vim\c', v:progname)
199endfunc
Bram Moolenaard5d37532017-03-27 23:02:07 +0200200
201func Test_silent_ex_mode()
202 if !has('unix') || has('gui_running')
203 " can't get output of Vim.
204 return
205 endif
206
207 " This caused an ml_get error.
208 let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq')
209 call assert_notmatch('E315:', out)
210endfunc
Bram Moolenaar85045a72017-04-02 16:54:09 +0200211
212func Test_default_term()
213 if !has('unix') || has('gui_running')
214 " can't get output of Vim.
215 return
216 endif
217
218 let save_term = $TERM
Bram Moolenaar08f88b12017-04-02 17:21:16 +0200219 let $TERM = 'unknownxxx'
Bram Moolenaar85045a72017-04-02 16:54:09 +0200220 let out = system(GetVimCommand() . ' -c''set term'' -c cq')
221 call assert_match("defaulting to 'ansi'", out)
222 let $TERM = save_term
223endfunc