Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 1 | " Tests for startup. |
Bram Moolenaar | b9a46fe | 2016-07-29 18:13:42 +0200 | [diff] [blame] | 2 | |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 3 | source shared.vim |
| 4 | |
| 5 | " Check that loading startup.vim works. |
Bram Moolenaar | b9a46fe | 2016-07-29 18:13:42 +0200 | [diff] [blame] | 6 | func Test_startup_script() |
| 7 | set compatible |
| 8 | source $VIMRUNTIME/defaults.vim |
| 9 | |
| 10 | call assert_equal(0, &compatible) |
| 11 | endfunc |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 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 |
| 17 | func Test_after_comes_later() |
Bram Moolenaar | 3286043 | 2016-08-06 19:24:23 +0200 | [diff] [blame] | 18 | if !has('packages') |
| 19 | return |
| 20 | endif |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 21 | let before = [ |
Bram Moolenaar | 446cce6 | 2016-08-06 21:37:27 +0200 | [diff] [blame] | 22 | \ 'set nocp viminfo+=nviminfo', |
| 23 | \ 'set guioptions+=M', |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 24 | \ 'let $HOME = "/does/not/exist"', |
| 25 | \ 'set loadplugins', |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 26 | \ 'set rtp=Xhere,Xafter,Xanother', |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 27 | \ 'set packpath=Xhere,Xafter', |
| 28 | \ 'set nomore', |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 29 | \ 'let g:sequence = ""', |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 30 | \ ] |
| 31 | let after = [ |
| 32 | \ 'redir! > Xtestout', |
| 33 | \ 'scriptnames', |
| 34 | \ 'redir END', |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 35 | \ 'redir! > Xsequence', |
| 36 | \ 'echo g:sequence', |
| 37 | \ 'redir END', |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 38 | \ 'quit', |
| 39 | \ ] |
| 40 | call mkdir('Xhere/plugin', 'p') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 41 | call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim') |
| 42 | call mkdir('Xanother/plugin', 'p') |
| 43 | call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 44 | call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 45 | call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 46 | |
| 47 | call mkdir('Xafter/plugin', 'p') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 48 | call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 49 | |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 50 | if RunVim(before, after, '') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 51 | |
Bram Moolenaar | 83b3c3d | 2016-08-06 19:16:43 +0200 | [diff] [blame] | 52 | let lines = readfile('Xtestout') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 53 | let expected = ['Xbefore.vim', 'here.vim', 'another.vim', 'foo.vim', 'later.vim', 'Xafter.vim'] |
Bram Moolenaar | 83b3c3d | 2016-08-06 19:16:43 +0200 | [diff] [blame] | 54 | let found = [] |
| 55 | for line in lines |
| 56 | for one in expected |
| 57 | if line =~ one |
| 58 | call add(found, one) |
| 59 | endif |
| 60 | endfor |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 61 | endfor |
Bram Moolenaar | 83b3c3d | 2016-08-06 19:16:43 +0200 | [diff] [blame] | 62 | call assert_equal(expected, found) |
| 63 | endif |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 64 | |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 65 | call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', '')) |
| 66 | |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 67 | call delete('Xtestout') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 68 | call delete('Xsequence') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 69 | call delete('Xhere', 'rf') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 70 | call delete('Xanother', 'rf') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 71 | call delete('Xafter', 'rf') |
| 72 | endfunc |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 73 | |
Bram Moolenaar | ce876aa | 2017-06-04 17:47:42 +0200 | [diff] [blame] | 74 | func Test_pack_in_rtp_when_plugins_run() |
| 75 | if !has('packages') |
| 76 | return |
| 77 | endif |
| 78 | let before = [ |
| 79 | \ 'set nocp viminfo+=nviminfo', |
| 80 | \ 'set guioptions+=M', |
| 81 | \ 'let $HOME = "/does/not/exist"', |
| 82 | \ 'set loadplugins', |
| 83 | \ 'set rtp=Xhere', |
| 84 | \ 'set packpath=Xhere', |
| 85 | \ 'set nomore', |
| 86 | \ ] |
| 87 | let after = [ |
| 88 | \ 'quit', |
| 89 | \ ] |
| 90 | call mkdir('Xhere/plugin', 'p') |
| 91 | call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim') |
| 92 | call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p') |
| 93 | call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim') |
| 94 | |
| 95 | if RunVim(before, after, '') |
| 96 | |
| 97 | let lines = filter(readfile('Xtestout'), '!empty(v:val)') |
| 98 | call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0)) |
| 99 | call assert_match('autoloaded foo', get(lines, 1)) |
| 100 | endif |
| 101 | |
| 102 | call delete('Xtestout') |
| 103 | call delete('Xhere', 'rf') |
| 104 | endfunc |
| 105 | |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 106 | func Test_help_arg() |
Bram Moolenaar | 3321e9d | 2016-08-06 23:03:59 +0200 | [diff] [blame] | 107 | if !has('unix') && has('gui') |
| 108 | " this doesn't work with gvim on MS-Windows |
| 109 | return |
| 110 | endif |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 111 | if RunVim([], [], '--help >Xtestout') |
| 112 | let lines = readfile('Xtestout') |
| 113 | call assert_true(len(lines) > 20) |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 114 | call assert_match('Vi IMproved', lines[0]) |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 115 | |
| 116 | " check if couple of lines are there |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 117 | let found = [] |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 118 | for line in lines |
| 119 | if line =~ '-R.*Readonly mode' |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 120 | call add(found, 'Readonly mode') |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 121 | endif |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 122 | " Watch out for a second --version line in the Gnome version. |
| 123 | if line =~ '--version.*Print version information and exit' |
| 124 | call add(found, "--version") |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 125 | endif |
| 126 | endfor |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 127 | call assert_equal(['Readonly mode', '--version'], found) |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 128 | endif |
| 129 | call delete('Xtestout') |
| 130 | endfunc |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 131 | |
| 132 | func Test_compatible_args() |
| 133 | let after = [ |
| 134 | \ 'call writefile([string(&compatible)], "Xtestout")', |
| 135 | \ 'set viminfo+=nviminfo', |
| 136 | \ 'quit', |
| 137 | \ ] |
| 138 | if RunVim([], after, '-C') |
| 139 | let lines = readfile('Xtestout') |
| 140 | call assert_equal('1', lines[0]) |
| 141 | endif |
| 142 | |
| 143 | if RunVim([], after, '-N') |
| 144 | let lines = readfile('Xtestout') |
| 145 | call assert_equal('0', lines[0]) |
| 146 | endif |
| 147 | |
| 148 | call delete('Xtestout') |
| 149 | endfunc |
| 150 | |
| 151 | func Test_file_args() |
| 152 | let after = [ |
| 153 | \ 'call writefile(argv(), "Xtestout")', |
| 154 | \ 'qall', |
| 155 | \ ] |
| 156 | if RunVim([], after, '') |
| 157 | let lines = readfile('Xtestout') |
| 158 | call assert_equal(0, len(lines)) |
| 159 | endif |
| 160 | |
| 161 | if RunVim([], after, 'one') |
| 162 | let lines = readfile('Xtestout') |
| 163 | call assert_equal(1, len(lines)) |
| 164 | call assert_equal('one', lines[0]) |
| 165 | endif |
| 166 | |
| 167 | if RunVim([], after, 'one two three') |
| 168 | let lines = readfile('Xtestout') |
| 169 | call assert_equal(3, len(lines)) |
| 170 | call assert_equal('one', lines[0]) |
| 171 | call assert_equal('two', lines[1]) |
| 172 | call assert_equal('three', lines[2]) |
| 173 | endif |
| 174 | |
| 175 | if RunVim([], after, 'one -c echo two') |
| 176 | let lines = readfile('Xtestout') |
| 177 | call assert_equal(2, len(lines)) |
| 178 | call assert_equal('one', lines[0]) |
| 179 | call assert_equal('two', lines[1]) |
| 180 | endif |
| 181 | |
| 182 | if RunVim([], after, 'one -- -c echo two') |
| 183 | let lines = readfile('Xtestout') |
| 184 | call assert_equal(4, len(lines)) |
| 185 | call assert_equal('one', lines[0]) |
| 186 | call assert_equal('-c', lines[1]) |
| 187 | call assert_equal('echo', lines[2]) |
| 188 | call assert_equal('two', lines[3]) |
| 189 | endif |
| 190 | |
| 191 | call delete('Xtestout') |
| 192 | endfunc |
| 193 | |
| 194 | func Test_startuptime() |
| 195 | if !has('startuptime') |
| 196 | return |
| 197 | endif |
| 198 | let after = ['qall'] |
| 199 | if RunVim([], after, '--startuptime Xtestout one') |
| 200 | let lines = readfile('Xtestout') |
| 201 | let expected = ['--- VIM STARTING ---', 'parsing arguments', |
| 202 | \ 'shell init', 'inits 3', 'start termcap', 'opening buffers'] |
| 203 | let found = [] |
| 204 | for line in lines |
| 205 | for exp in expected |
| 206 | if line =~ exp |
| 207 | call add(found, exp) |
| 208 | endif |
| 209 | endfor |
| 210 | endfor |
| 211 | call assert_equal(expected, found) |
| 212 | endif |
| 213 | call delete('Xtestout') |
| 214 | endfunc |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 215 | |
| 216 | func Test_read_stdin() |
| 217 | let after = [ |
| 218 | \ 'write Xtestout', |
| 219 | \ 'quit!', |
| 220 | \ ] |
| 221 | if RunVimPiped([], after, '-', 'echo something | ') |
| 222 | let lines = readfile('Xtestout') |
Bram Moolenaar | e4a76ad | 2016-08-07 16:50:10 +0200 | [diff] [blame] | 223 | " MS-Windows adds a space after the word |
| 224 | call assert_equal(['something'], split(lines[0])) |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 225 | endif |
| 226 | call delete('Xtestout') |
| 227 | endfunc |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 228 | |
| 229 | func Test_progpath() |
| 230 | " Tests normally run with "./vim" or "../vim", these must have been expanded |
| 231 | " to a full path. |
| 232 | if has('unix') |
| 233 | call assert_equal('/', v:progpath[0]) |
| 234 | elseif has('win32') |
| 235 | call assert_equal(':', v:progpath[1]) |
| 236 | call assert_match('[/\\]', v:progpath[2]) |
| 237 | endif |
| 238 | |
| 239 | " Only expect "vim" to appear in v:progname. |
| 240 | call assert_match('vim\c', v:progname) |
| 241 | endfunc |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 242 | |
| 243 | func Test_silent_ex_mode() |
| 244 | if !has('unix') || has('gui_running') |
| 245 | " can't get output of Vim. |
| 246 | return |
| 247 | endif |
| 248 | |
| 249 | " This caused an ml_get error. |
| 250 | let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq') |
| 251 | call assert_notmatch('E315:', out) |
| 252 | endfunc |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 253 | |
| 254 | func Test_default_term() |
| 255 | if !has('unix') || has('gui_running') |
| 256 | " can't get output of Vim. |
| 257 | return |
| 258 | endif |
| 259 | |
| 260 | let save_term = $TERM |
Bram Moolenaar | 08f88b1 | 2017-04-02 17:21:16 +0200 | [diff] [blame] | 261 | let $TERM = 'unknownxxx' |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 262 | let out = system(GetVimCommand() . ' -c''set term'' -c cq') |
| 263 | call assert_match("defaulting to 'ansi'", out) |
| 264 | let $TERM = save_term |
| 265 | endfunc |