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', |
| 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 Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 44 | if RunVim(before, after, '') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 45 | |
Bram Moolenaar | 83b3c3d | 2016-08-06 19:16:43 +0200 | [diff] [blame] | 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 |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 55 | endfor |
Bram Moolenaar | 83b3c3d | 2016-08-06 19:16:43 +0200 | [diff] [blame] | 56 | call assert_equal(expected, found) |
| 57 | endif |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 58 | |
| 59 | call delete('Xtestout') |
| 60 | call delete('Xhere', 'rf') |
| 61 | call delete('Xafter', 'rf') |
| 62 | endfunc |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 63 | |
Bram Moolenaar | ce876aa | 2017-06-04 17:47:42 +0200 | [diff] [blame] | 64 | func 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') |
| 94 | endfunc |
| 95 | |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 96 | func Test_help_arg() |
Bram Moolenaar | 3321e9d | 2016-08-06 23:03:59 +0200 | [diff] [blame] | 97 | if !has('unix') && has('gui') |
| 98 | " this doesn't work with gvim on MS-Windows |
| 99 | return |
| 100 | endif |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 101 | if RunVim([], [], '--help >Xtestout') |
| 102 | let lines = readfile('Xtestout') |
| 103 | call assert_true(len(lines) > 20) |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 104 | call assert_match('Vi IMproved', lines[0]) |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 105 | |
| 106 | " check if couple of lines are there |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 107 | let found = [] |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 108 | for line in lines |
| 109 | if line =~ '-R.*Readonly mode' |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 110 | call add(found, 'Readonly mode') |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 111 | endif |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 112 | " 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 Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 115 | endif |
| 116 | endfor |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 117 | call assert_equal(['Readonly mode', '--version'], found) |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 118 | endif |
| 119 | call delete('Xtestout') |
| 120 | endfunc |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 121 | |
| 122 | func 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') |
| 139 | endfunc |
| 140 | |
| 141 | func 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') |
| 182 | endfunc |
| 183 | |
| 184 | func 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') |
| 204 | endfunc |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 205 | |
| 206 | func Test_read_stdin() |
| 207 | let after = [ |
| 208 | \ 'write Xtestout', |
| 209 | \ 'quit!', |
| 210 | \ ] |
| 211 | if RunVimPiped([], after, '-', 'echo something | ') |
| 212 | let lines = readfile('Xtestout') |
Bram Moolenaar | e4a76ad | 2016-08-07 16:50:10 +0200 | [diff] [blame] | 213 | " MS-Windows adds a space after the word |
| 214 | call assert_equal(['something'], split(lines[0])) |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 215 | endif |
| 216 | call delete('Xtestout') |
| 217 | endfunc |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 218 | |
| 219 | func 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) |
| 231 | endfunc |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 232 | |
| 233 | func 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) |
| 242 | endfunc |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 243 | |
| 244 | func 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 Moolenaar | 08f88b1 | 2017-04-02 17:21:16 +0200 | [diff] [blame] | 251 | let $TERM = 'unknownxxx' |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 252 | let out = system(GetVimCommand() . ' -c''set term'' -c cq') |
| 253 | call assert_match("defaulting to 'ansi'", out) |
| 254 | let $TERM = save_term |
| 255 | endfunc |