blob: 652318fb7cb53e9f1c79b0f48cd71885310cb0d0 [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
75 let found = 0
76 for line in lines
77 if line =~ '-R.*Readonly mode'
78 let found += 1
79 endif
80 if line =~ '--version'
81 let found += 1
82 endif
83 endfor
84 call assert_equal(2, found)
85 endif
86 call delete('Xtestout')
87endfunc
Bram Moolenaarba98bef2016-08-07 15:51:39 +020088
89func Test_compatible_args()
90 let after = [
91 \ 'call writefile([string(&compatible)], "Xtestout")',
92 \ 'set viminfo+=nviminfo',
93 \ 'quit',
94 \ ]
95 if RunVim([], after, '-C')
96 let lines = readfile('Xtestout')
97 call assert_equal('1', lines[0])
98 endif
99
100 if RunVim([], after, '-N')
101 let lines = readfile('Xtestout')
102 call assert_equal('0', lines[0])
103 endif
104
105 call delete('Xtestout')
106endfunc
107
108func Test_file_args()
109 let after = [
110 \ 'call writefile(argv(), "Xtestout")',
111 \ 'qall',
112 \ ]
113 if RunVim([], after, '')
114 let lines = readfile('Xtestout')
115 call assert_equal(0, len(lines))
116 endif
117
118 if RunVim([], after, 'one')
119 let lines = readfile('Xtestout')
120 call assert_equal(1, len(lines))
121 call assert_equal('one', lines[0])
122 endif
123
124 if RunVim([], after, 'one two three')
125 let lines = readfile('Xtestout')
126 call assert_equal(3, len(lines))
127 call assert_equal('one', lines[0])
128 call assert_equal('two', lines[1])
129 call assert_equal('three', lines[2])
130 endif
131
132 if RunVim([], after, 'one -c echo two')
133 let lines = readfile('Xtestout')
134 call assert_equal(2, len(lines))
135 call assert_equal('one', lines[0])
136 call assert_equal('two', lines[1])
137 endif
138
139 if RunVim([], after, 'one -- -c echo two')
140 let lines = readfile('Xtestout')
141 call assert_equal(4, len(lines))
142 call assert_equal('one', lines[0])
143 call assert_equal('-c', lines[1])
144 call assert_equal('echo', lines[2])
145 call assert_equal('two', lines[3])
146 endif
147
148 call delete('Xtestout')
149endfunc
150
151func Test_startuptime()
152 if !has('startuptime')
153 return
154 endif
155 let after = ['qall']
156 if RunVim([], after, '--startuptime Xtestout one')
157 let lines = readfile('Xtestout')
158 let expected = ['--- VIM STARTING ---', 'parsing arguments',
159 \ 'shell init', 'inits 3', 'start termcap', 'opening buffers']
160 let found = []
161 for line in lines
162 for exp in expected
163 if line =~ exp
164 call add(found, exp)
165 endif
166 endfor
167 endfor
168 call assert_equal(expected, found)
169 endif
170 call delete('Xtestout')
171endfunc
Bram Moolenaar3a938382016-08-07 16:36:40 +0200172
173func Test_read_stdin()
174 let after = [
175 \ 'write Xtestout',
176 \ 'quit!',
177 \ ]
178 if RunVimPiped([], after, '-', 'echo something | ')
179 let lines = readfile('Xtestout')
180 call assert_equal('something', lines[0])
181 endif
182 call delete('Xtestout')
183endfunc