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 | |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 151 | " Test the -o[N] and -O[N] arguments to open N windows split |
| 152 | " horizontally or vertically. |
| 153 | func Test_o_arg() |
| 154 | let after = [ |
| 155 | \ 'call writefile([winnr("$"), |
| 156 | \ winheight(1), winheight(2), &lines, |
| 157 | \ winwidth(1), winwidth(2), &columns, |
| 158 | \ bufname(winbufnr(1)), bufname(winbufnr(2))], |
| 159 | \ "Xtestout")', |
| 160 | \ 'qall', |
| 161 | \ ] |
| 162 | if RunVim([], after, '-o2') |
| 163 | " Open 2 windows split horizontally. Expect: |
| 164 | " - 2 windows |
| 165 | " - both windows should have the same or almost the same height |
| 166 | " - sum of both windows height (+ 3 for both statusline and Ex command) |
| 167 | " should be equal to the number of lines |
| 168 | " - both windows should have the same width which should be equal to the |
| 169 | " number of columns |
| 170 | " - buffer of both windows should have no name |
| 171 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 172 | call assert_equal('2', wn) |
| 173 | call assert_inrange(0, 1, wh1 - wh2) |
| 174 | call assert_equal(string(wh1 + wh2 + 3), ln) |
| 175 | call assert_equal(ww1, ww2) |
| 176 | call assert_equal(ww1, cn) |
| 177 | call assert_equal('', bn1) |
| 178 | call assert_equal('', bn2) |
| 179 | endif |
| 180 | |
| 181 | if RunVim([], after, '-o foo bar') |
| 182 | " Same expectations as for -o2 but buffer names should be foo and bar |
| 183 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 184 | call assert_equal('2', wn) |
| 185 | call assert_inrange(0, 1, wh1 - wh2) |
| 186 | call assert_equal(string(wh1 + wh2 + 3), ln) |
| 187 | call assert_equal(ww1, ww2) |
| 188 | call assert_equal(ww1, cn) |
| 189 | call assert_equal('foo', bn1) |
| 190 | call assert_equal('bar', bn2) |
| 191 | endif |
| 192 | |
| 193 | if RunVim([], after, '-O2') |
| 194 | " Open 2 windows split vertically. Expect: |
| 195 | " - 2 windows |
| 196 | " - both windows should have the same or almost the same width |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 197 | " - sum of both windows width (+ 1 for the separator) should be equal to |
| 198 | " the number of columns |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 199 | " - both windows should have the same height |
| 200 | " - window height (+ 2 for the statusline and Ex command) should be equal |
| 201 | " to the number of lines |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 202 | " - buffer of both windows should have no name |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 203 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 204 | call assert_equal('2', wn) |
| 205 | call assert_inrange(0, 1, ww1 - ww2) |
| 206 | call assert_equal(string(ww1 + ww2 + 1), cn) |
| 207 | call assert_equal(wh1, wh2) |
| 208 | call assert_equal(string(wh1 + 2), ln) |
| 209 | call assert_equal('', bn1) |
| 210 | call assert_equal('', bn2) |
| 211 | endif |
| 212 | |
| 213 | if RunVim([], after, '-O foo bar') |
| 214 | " Same expectations as for -O2 but buffer names should be foo and bar |
| 215 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 216 | call assert_equal('2', wn) |
| 217 | call assert_inrange(0, 1, ww1 - ww2) |
| 218 | call assert_equal(string(ww1 + ww2 + 1), cn) |
| 219 | call assert_equal(wh1, wh2) |
| 220 | call assert_equal(string(wh1 + 2), ln) |
| 221 | call assert_equal('foo', bn1) |
| 222 | call assert_equal('bar', bn2) |
| 223 | endif |
| 224 | |
| 225 | call delete('Xtestout') |
| 226 | endfunc |
| 227 | |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 228 | " Test the -p[N] argument to open N tabpages. |
| 229 | func Test_p_arg() |
| 230 | let after = [ |
| 231 | \ 'call writefile(split(execute("tabs"), "\n"), "Xtestout")', |
| 232 | \ 'qall', |
| 233 | \ ] |
| 234 | if RunVim([], after, '-p2') |
| 235 | let lines = readfile('Xtestout') |
| 236 | call assert_equal(4, len(lines)) |
| 237 | call assert_equal('Tab page 1', lines[0]) |
| 238 | call assert_equal('> [No Name]', lines[1]) |
| 239 | call assert_equal('Tab page 2', lines[2]) |
| 240 | call assert_equal(' [No Name]', lines[3]) |
| 241 | endif |
| 242 | |
| 243 | if RunVim([], after, '-p foo bar') |
| 244 | let lines = readfile('Xtestout') |
| 245 | call assert_equal(4, len(lines)) |
| 246 | call assert_equal('Tab page 1', lines[0]) |
| 247 | call assert_equal('> foo', lines[1]) |
| 248 | call assert_equal('Tab page 2', lines[2]) |
| 249 | call assert_equal(' bar', lines[3]) |
| 250 | endif |
| 251 | |
| 252 | call delete('Xtestout') |
| 253 | endfunc |
| 254 | |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 255 | " Test the -V[N] argument to set the 'verbose' option to [N] |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 256 | func Test_V_arg() |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 257 | if has('gui_running') |
| 258 | " Can't catch the output of gvim. |
| 259 | return |
| 260 | endif |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 261 | let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq') |
| 262 | call assert_equal(" verbose=0\n", out) |
| 263 | |
| 264 | let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq') |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 265 | call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nSearching for \"filetype\.vim\".*\n", out) |
| 266 | call assert_match(" verbose=2\n", out) |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 267 | |
| 268 | let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq') |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 269 | call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline 1: \" The default vimrc file\..* verbose=15\n", out) |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 270 | endfunc |
| 271 | |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 272 | " Test the -V[N]{filename} argument to set the 'verbose' option to N |
| 273 | " and set 'verbosefile' to filename. |
| 274 | func Test_V_file_arg() |
| 275 | if RunVim([], [], ' --clean -X -V2Xverbosefile -c "set verbose? verbosefile?" -cq') |
| 276 | let out = join(readfile('Xverbosefile'), "\n") |
| 277 | call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out) |
| 278 | call assert_match("\n verbose=2\n", out) |
| 279 | call assert_match("\n verbosefile=Xverbosefile", out) |
| 280 | endif |
| 281 | |
| 282 | call delete('Xverbosefile') |
| 283 | endfunc |
| 284 | |
| 285 | " Test the -m, -M and -R arguments: |
| 286 | " -m resets 'write' |
| 287 | " -M resets 'modifiable' and 'write' |
| 288 | " -R sets 'readonly' |
| 289 | func Test_m_M_R() |
| 290 | let after = [ |
| 291 | \ 'call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout")', |
| 292 | \ 'qall', |
| 293 | \ ] |
| 294 | if RunVim([], after, '') |
| 295 | let lines = readfile('Xtestout') |
| 296 | call assert_equal(['1', '1', '0', '200'], lines) |
| 297 | endif |
| 298 | if RunVim([], after, '-m') |
| 299 | let lines = readfile('Xtestout') |
| 300 | call assert_equal(['0', '1', '0', '200'], lines) |
| 301 | endif |
| 302 | if RunVim([], after, '-M') |
| 303 | let lines = readfile('Xtestout') |
| 304 | call assert_equal(['0', '0', '0', '200'], lines) |
| 305 | endif |
| 306 | if RunVim([], after, '-R') |
| 307 | let lines = readfile('Xtestout') |
| 308 | call assert_equal(['1', '1', '1', '10000'], lines) |
| 309 | endif |
| 310 | |
| 311 | call delete('Xtestout') |
| 312 | endfunc |
| 313 | |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 314 | " Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes). |
| 315 | func Test_A_F_H_arg() |
| 316 | let after = [ |
| 317 | \ 'call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout")', |
| 318 | \ 'qall', |
| 319 | \ ] |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 320 | " Use silent Ex mode to avoid the hit-Enter prompt for the warning that |
| 321 | " 'encoding' is not utf-8. |
| 322 | if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A') |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 323 | let lines = readfile('Xtestout') |
| 324 | call assert_equal(['1', '1', '0', '0'], lines) |
| 325 | endif |
| 326 | |
| 327 | if has('farsi') && RunVim([], after, '-F') |
| 328 | let lines = readfile('Xtestout') |
| 329 | call assert_equal(['1', '0', '1', '0'], lines) |
| 330 | endif |
| 331 | |
| 332 | if has('rightleft') && RunVim([], after, '-H') |
| 333 | let lines = readfile('Xtestout') |
| 334 | call assert_equal(['1', '0', '0', '1'], lines) |
| 335 | endif |
| 336 | |
| 337 | call delete('Xtestout') |
| 338 | endfunc |
| 339 | |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 340 | func Test_file_args() |
| 341 | let after = [ |
| 342 | \ 'call writefile(argv(), "Xtestout")', |
| 343 | \ 'qall', |
| 344 | \ ] |
| 345 | if RunVim([], after, '') |
| 346 | let lines = readfile('Xtestout') |
| 347 | call assert_equal(0, len(lines)) |
| 348 | endif |
| 349 | |
| 350 | if RunVim([], after, 'one') |
| 351 | let lines = readfile('Xtestout') |
| 352 | call assert_equal(1, len(lines)) |
| 353 | call assert_equal('one', lines[0]) |
| 354 | endif |
| 355 | |
| 356 | if RunVim([], after, 'one two three') |
| 357 | let lines = readfile('Xtestout') |
| 358 | call assert_equal(3, len(lines)) |
| 359 | call assert_equal('one', lines[0]) |
| 360 | call assert_equal('two', lines[1]) |
| 361 | call assert_equal('three', lines[2]) |
| 362 | endif |
| 363 | |
| 364 | if RunVim([], after, 'one -c echo two') |
| 365 | let lines = readfile('Xtestout') |
| 366 | call assert_equal(2, len(lines)) |
| 367 | call assert_equal('one', lines[0]) |
| 368 | call assert_equal('two', lines[1]) |
| 369 | endif |
| 370 | |
| 371 | if RunVim([], after, 'one -- -c echo two') |
| 372 | let lines = readfile('Xtestout') |
| 373 | call assert_equal(4, len(lines)) |
| 374 | call assert_equal('one', lines[0]) |
| 375 | call assert_equal('-c', lines[1]) |
| 376 | call assert_equal('echo', lines[2]) |
| 377 | call assert_equal('two', lines[3]) |
| 378 | endif |
| 379 | |
| 380 | call delete('Xtestout') |
| 381 | endfunc |
| 382 | |
| 383 | func Test_startuptime() |
| 384 | if !has('startuptime') |
| 385 | return |
| 386 | endif |
| 387 | let after = ['qall'] |
| 388 | if RunVim([], after, '--startuptime Xtestout one') |
| 389 | let lines = readfile('Xtestout') |
| 390 | let expected = ['--- VIM STARTING ---', 'parsing arguments', |
| 391 | \ 'shell init', 'inits 3', 'start termcap', 'opening buffers'] |
| 392 | let found = [] |
| 393 | for line in lines |
| 394 | for exp in expected |
| 395 | if line =~ exp |
| 396 | call add(found, exp) |
| 397 | endif |
| 398 | endfor |
| 399 | endfor |
| 400 | call assert_equal(expected, found) |
| 401 | endif |
| 402 | call delete('Xtestout') |
| 403 | endfunc |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 404 | |
| 405 | func Test_read_stdin() |
| 406 | let after = [ |
| 407 | \ 'write Xtestout', |
| 408 | \ 'quit!', |
| 409 | \ ] |
| 410 | if RunVimPiped([], after, '-', 'echo something | ') |
| 411 | let lines = readfile('Xtestout') |
Bram Moolenaar | e4a76ad | 2016-08-07 16:50:10 +0200 | [diff] [blame] | 412 | " MS-Windows adds a space after the word |
| 413 | call assert_equal(['something'], split(lines[0])) |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 414 | endif |
| 415 | call delete('Xtestout') |
| 416 | endfunc |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 417 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 418 | func Test_set_shell() |
| 419 | let after = [ |
| 420 | \ 'call writefile([&shell], "Xtestout")', |
| 421 | \ 'quit!', |
| 422 | \ ] |
| 423 | let $SHELL = '/bin/with space/sh' |
| 424 | if RunVimPiped([], after, '', '') |
| 425 | let lines = readfile('Xtestout') |
| 426 | " MS-Windows adds a space after the word |
| 427 | call assert_equal('/bin/with\ space/sh', lines[0]) |
| 428 | endif |
| 429 | call delete('Xtestout') |
| 430 | endfunc |
| 431 | |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 432 | func Test_progpath() |
| 433 | " Tests normally run with "./vim" or "../vim", these must have been expanded |
| 434 | " to a full path. |
| 435 | if has('unix') |
| 436 | call assert_equal('/', v:progpath[0]) |
| 437 | elseif has('win32') |
| 438 | call assert_equal(':', v:progpath[1]) |
| 439 | call assert_match('[/\\]', v:progpath[2]) |
| 440 | endif |
| 441 | |
| 442 | " Only expect "vim" to appear in v:progname. |
| 443 | call assert_match('vim\c', v:progname) |
| 444 | endfunc |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 445 | |
| 446 | func Test_silent_ex_mode() |
| 447 | if !has('unix') || has('gui_running') |
| 448 | " can't get output of Vim. |
| 449 | return |
| 450 | endif |
| 451 | |
| 452 | " This caused an ml_get error. |
| 453 | let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq') |
| 454 | call assert_notmatch('E315:', out) |
| 455 | endfunc |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 456 | |
| 457 | func Test_default_term() |
| 458 | if !has('unix') || has('gui_running') |
| 459 | " can't get output of Vim. |
| 460 | return |
| 461 | endif |
| 462 | |
| 463 | let save_term = $TERM |
Bram Moolenaar | 08f88b1 | 2017-04-02 17:21:16 +0200 | [diff] [blame] | 464 | let $TERM = 'unknownxxx' |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 465 | let out = system(GetVimCommand() . ' -c''set term'' -c cq') |
| 466 | call assert_match("defaulting to 'ansi'", out) |
| 467 | let $TERM = save_term |
| 468 | endfunc |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 469 | |
| 470 | func Test_zzz_startinsert() |
| 471 | " Test :startinsert |
| 472 | call writefile(['123456'], 'Xtestout') |
| 473 | let after = [ |
| 474 | \ ':startinsert', |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 475 | \ 'call feedkeys("foobar\<c-o>:wq\<cr>","t")' |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 476 | \ ] |
| 477 | if RunVim([], after, 'Xtestout') |
| 478 | let lines = readfile('Xtestout') |
| 479 | call assert_equal(['foobar123456'], lines) |
| 480 | endif |
| 481 | " Test :startinsert! |
| 482 | call writefile(['123456'], 'Xtestout') |
| 483 | let after = [ |
| 484 | \ ':startinsert!', |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 485 | \ 'call feedkeys("foobar\<c-o>:wq\<cr>","t")' |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 486 | \ ] |
| 487 | if RunVim([], after, 'Xtestout') |
| 488 | let lines = readfile('Xtestout') |
| 489 | call assert_equal(['123456foobar'], lines) |
| 490 | endif |
| 491 | call delete('Xtestout') |
| 492 | endfunc |