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 | |
| 64 | func Test_help_arg() |
Bram Moolenaar | 3321e9d | 2016-08-06 23:03:59 +0200 | [diff] [blame] | 65 | if !has('unix') && has('gui') |
| 66 | " this doesn't work with gvim on MS-Windows |
| 67 | return |
| 68 | endif |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 69 | if RunVim([], [], '--help >Xtestout') |
| 70 | let lines = readfile('Xtestout') |
| 71 | call assert_true(len(lines) > 20) |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 72 | call assert_match('Vi IMproved', lines[0]) |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 73 | |
| 74 | " check if couple of lines are there |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 75 | let found = [] |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 76 | for line in lines |
| 77 | if line =~ '-R.*Readonly mode' |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 78 | call add(found, 'Readonly mode') |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 79 | endif |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 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") |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 83 | endif |
| 84 | endfor |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 85 | call assert_equal(['Readonly mode', '--version'], found) |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 86 | endif |
| 87 | call delete('Xtestout') |
| 88 | endfunc |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 89 | |
| 90 | func 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') |
| 107 | endfunc |
| 108 | |
| 109 | func 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') |
| 150 | endfunc |
| 151 | |
| 152 | func 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') |
| 172 | endfunc |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 173 | |
| 174 | func Test_read_stdin() |
| 175 | let after = [ |
| 176 | \ 'write Xtestout', |
| 177 | \ 'quit!', |
| 178 | \ ] |
| 179 | if RunVimPiped([], after, '-', 'echo something | ') |
| 180 | let lines = readfile('Xtestout') |
Bram Moolenaar | e4a76ad | 2016-08-07 16:50:10 +0200 | [diff] [blame] | 181 | " MS-Windows adds a space after the word |
| 182 | call assert_equal(['something'], split(lines[0])) |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 183 | endif |
| 184 | call delete('Xtestout') |
| 185 | endfunc |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 186 | |
| 187 | func 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) |
| 199 | endfunc |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 200 | |
| 201 | func 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) |
| 210 | endfunc |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 211 | |
| 212 | func 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 Moolenaar | 08f88b1 | 2017-04-02 17:21:16 +0200 | [diff] [blame] | 219 | let $TERM = 'unknownxxx' |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 220 | let out = system(GetVimCommand() . ' -c''set term'' -c cq') |
| 221 | call assert_match("defaulting to 'ansi'", out) |
| 222 | let $TERM = save_term |
| 223 | endfunc |