1" Tests for startup. 2 3source shared.vim 4 5" Check that loading startup.vim works. 6func Test_startup_script() 7 set compatible 8 source $VIMRUNTIME/defaults.vim 9 10 call assert_equal(0, &compatible) 11endfunc 12 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() 18 if !has('packages') 19 return 20 endif 21 let before = [ 22 \ 'set nocp viminfo+=nviminfo', 23 \ 'set guioptions+=M', 24 \ '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 44 if RunVim(before, after, '') 45 46 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 55 endfor 56 call assert_equal(expected, found) 57 endif 58 59 call delete('Xtestout') 60 call delete('Xhere', 'rf') 61 call delete('Xafter', 'rf') 62endfunc 63 64func Test_help_arg() 65 if !has('unix') && has('gui') 66 " this doesn't work with gvim on MS-Windows 67 return 68 endif 69 if RunVim([], [], '--help >Xtestout') 70 let lines = readfile('Xtestout') 71 call assert_true(len(lines) > 20) 72 call assert_match('Vi IMproved', lines[0]) 73 74 " check if couple of lines are there 75 let found = [] 76 for line in lines 77 if line =~ '-R.*Readonly mode' 78 call add(found, 'Readonly mode') 79 endif 80 " 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") 83 endif 84 endfor 85 call assert_equal(['Readonly mode', '--version'], found) 86 endif 87 call delete('Xtestout') 88endfunc 89 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 173 174func Test_read_stdin() 175 let after = [ 176 \ 'write Xtestout', 177 \ 'quit!', 178 \ ] 179 if RunVimPiped([], after, '-', 'echo something | ') 180 let lines = readfile('Xtestout') 181 " MS-Windows adds a space after the word 182 call assert_equal(['something'], split(lines[0])) 183 endif 184 call delete('Xtestout') 185endfunc 186