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 |
Bram Moolenaar | c75e812 | 2019-04-21 15:55:10 +0200 | [diff] [blame] | 4 | source screendump.vim |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 5 | |
| 6 | " Check that loading startup.vim works. |
Bram Moolenaar | b9a46fe | 2016-07-29 18:13:42 +0200 | [diff] [blame] | 7 | func Test_startup_script() |
| 8 | set compatible |
| 9 | source $VIMRUNTIME/defaults.vim |
| 10 | |
| 11 | call assert_equal(0, &compatible) |
| 12 | endfunc |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 13 | |
| 14 | " Verify the order in which plugins are loaded: |
| 15 | " 1. plugins in non-after directories |
| 16 | " 2. packages |
| 17 | " 3. plugins in after directories |
| 18 | func Test_after_comes_later() |
Bram Moolenaar | 3286043 | 2016-08-06 19:24:23 +0200 | [diff] [blame] | 19 | if !has('packages') |
| 20 | return |
| 21 | endif |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 22 | let before = [ |
Bram Moolenaar | 446cce6 | 2016-08-06 21:37:27 +0200 | [diff] [blame] | 23 | \ 'set nocp viminfo+=nviminfo', |
| 24 | \ 'set guioptions+=M', |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 25 | \ 'let $HOME = "/does/not/exist"', |
| 26 | \ 'set loadplugins', |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 27 | \ 'set rtp=Xhere,Xafter,Xanother', |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 28 | \ 'set packpath=Xhere,Xafter', |
| 29 | \ 'set nomore', |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 30 | \ 'let g:sequence = ""', |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 31 | \ ] |
| 32 | let after = [ |
| 33 | \ 'redir! > Xtestout', |
| 34 | \ 'scriptnames', |
| 35 | \ 'redir END', |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 36 | \ 'redir! > Xsequence', |
| 37 | \ 'echo g:sequence', |
| 38 | \ 'redir END', |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 39 | \ 'quit', |
| 40 | \ ] |
| 41 | call mkdir('Xhere/plugin', 'p') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 42 | call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim') |
| 43 | call mkdir('Xanother/plugin', 'p') |
| 44 | call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 45 | call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 46 | 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] | 47 | |
| 48 | call mkdir('Xafter/plugin', 'p') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 49 | call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 50 | |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 51 | if RunVim(before, after, '') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 52 | |
Bram Moolenaar | 83b3c3d | 2016-08-06 19:16:43 +0200 | [diff] [blame] | 53 | let lines = readfile('Xtestout') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 54 | 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] | 55 | let found = [] |
| 56 | for line in lines |
| 57 | for one in expected |
| 58 | if line =~ one |
| 59 | call add(found, one) |
| 60 | endif |
| 61 | endfor |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 62 | endfor |
Bram Moolenaar | 83b3c3d | 2016-08-06 19:16:43 +0200 | [diff] [blame] | 63 | call assert_equal(expected, found) |
| 64 | endif |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 65 | |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 66 | call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', '')) |
| 67 | |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 68 | call delete('Xtestout') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 69 | call delete('Xsequence') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 70 | call delete('Xhere', 'rf') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 71 | call delete('Xanother', 'rf') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 72 | call delete('Xafter', 'rf') |
| 73 | endfunc |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 74 | |
Bram Moolenaar | ce876aa | 2017-06-04 17:47:42 +0200 | [diff] [blame] | 75 | func Test_pack_in_rtp_when_plugins_run() |
| 76 | if !has('packages') |
| 77 | return |
| 78 | endif |
| 79 | let before = [ |
| 80 | \ 'set nocp viminfo+=nviminfo', |
| 81 | \ 'set guioptions+=M', |
| 82 | \ 'let $HOME = "/does/not/exist"', |
| 83 | \ 'set loadplugins', |
| 84 | \ 'set rtp=Xhere', |
| 85 | \ 'set packpath=Xhere', |
| 86 | \ 'set nomore', |
| 87 | \ ] |
| 88 | let after = [ |
| 89 | \ 'quit', |
| 90 | \ ] |
| 91 | call mkdir('Xhere/plugin', 'p') |
| 92 | call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim') |
| 93 | call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p') |
| 94 | call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim') |
| 95 | |
| 96 | if RunVim(before, after, '') |
| 97 | |
| 98 | let lines = filter(readfile('Xtestout'), '!empty(v:val)') |
| 99 | call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0)) |
| 100 | call assert_match('autoloaded foo', get(lines, 1)) |
| 101 | endif |
| 102 | |
| 103 | call delete('Xtestout') |
| 104 | call delete('Xhere', 'rf') |
| 105 | endfunc |
| 106 | |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 107 | func Test_help_arg() |
Bram Moolenaar | 3321e9d | 2016-08-06 23:03:59 +0200 | [diff] [blame] | 108 | if !has('unix') && has('gui') |
| 109 | " this doesn't work with gvim on MS-Windows |
| 110 | return |
| 111 | endif |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 112 | if RunVim([], [], '--help >Xtestout') |
| 113 | let lines = readfile('Xtestout') |
| 114 | call assert_true(len(lines) > 20) |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 115 | call assert_match('Vi IMproved', lines[0]) |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 116 | |
| 117 | " check if couple of lines are there |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 118 | let found = [] |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 119 | for line in lines |
| 120 | if line =~ '-R.*Readonly mode' |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 121 | call add(found, 'Readonly mode') |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 122 | endif |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 123 | " Watch out for a second --version line in the Gnome version. |
| 124 | if line =~ '--version.*Print version information and exit' |
| 125 | call add(found, "--version") |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 126 | endif |
| 127 | endfor |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 128 | call assert_equal(['Readonly mode', '--version'], found) |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 129 | endif |
| 130 | call delete('Xtestout') |
| 131 | endfunc |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 132 | |
| 133 | func Test_compatible_args() |
| 134 | let after = [ |
| 135 | \ 'call writefile([string(&compatible)], "Xtestout")', |
| 136 | \ 'set viminfo+=nviminfo', |
| 137 | \ 'quit', |
| 138 | \ ] |
| 139 | if RunVim([], after, '-C') |
| 140 | let lines = readfile('Xtestout') |
| 141 | call assert_equal('1', lines[0]) |
| 142 | endif |
| 143 | |
| 144 | if RunVim([], after, '-N') |
| 145 | let lines = readfile('Xtestout') |
| 146 | call assert_equal('0', lines[0]) |
| 147 | endif |
| 148 | |
| 149 | call delete('Xtestout') |
| 150 | endfunc |
| 151 | |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 152 | " Test the -o[N] and -O[N] arguments to open N windows split |
| 153 | " horizontally or vertically. |
| 154 | func Test_o_arg() |
| 155 | let after = [ |
| 156 | \ 'call writefile([winnr("$"), |
| 157 | \ winheight(1), winheight(2), &lines, |
| 158 | \ winwidth(1), winwidth(2), &columns, |
| 159 | \ bufname(winbufnr(1)), bufname(winbufnr(2))], |
| 160 | \ "Xtestout")', |
| 161 | \ 'qall', |
| 162 | \ ] |
| 163 | if RunVim([], after, '-o2') |
| 164 | " Open 2 windows split horizontally. Expect: |
| 165 | " - 2 windows |
| 166 | " - both windows should have the same or almost the same height |
| 167 | " - sum of both windows height (+ 3 for both statusline and Ex command) |
| 168 | " should be equal to the number of lines |
| 169 | " - both windows should have the same width which should be equal to the |
| 170 | " number of columns |
| 171 | " - buffer of both windows should have no name |
| 172 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 173 | call assert_equal('2', wn) |
| 174 | call assert_inrange(0, 1, wh1 - wh2) |
| 175 | call assert_equal(string(wh1 + wh2 + 3), ln) |
| 176 | call assert_equal(ww1, ww2) |
| 177 | call assert_equal(ww1, cn) |
| 178 | call assert_equal('', bn1) |
| 179 | call assert_equal('', bn2) |
| 180 | endif |
| 181 | |
| 182 | if RunVim([], after, '-o foo bar') |
| 183 | " Same expectations as for -o2 but buffer names should be foo and bar |
| 184 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 185 | call assert_equal('2', wn) |
| 186 | call assert_inrange(0, 1, wh1 - wh2) |
| 187 | call assert_equal(string(wh1 + wh2 + 3), ln) |
| 188 | call assert_equal(ww1, ww2) |
| 189 | call assert_equal(ww1, cn) |
| 190 | call assert_equal('foo', bn1) |
| 191 | call assert_equal('bar', bn2) |
| 192 | endif |
| 193 | |
| 194 | if RunVim([], after, '-O2') |
| 195 | " Open 2 windows split vertically. Expect: |
| 196 | " - 2 windows |
| 197 | " - both windows should have the same or almost the same width |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 198 | " - sum of both windows width (+ 1 for the separator) should be equal to |
| 199 | " the number of columns |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 200 | " - both windows should have the same height |
| 201 | " - window height (+ 2 for the statusline and Ex command) should be equal |
| 202 | " to the number of lines |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 203 | " - buffer of both windows should have no name |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 204 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 205 | call assert_equal('2', wn) |
| 206 | call assert_inrange(0, 1, ww1 - ww2) |
| 207 | call assert_equal(string(ww1 + ww2 + 1), cn) |
| 208 | call assert_equal(wh1, wh2) |
| 209 | call assert_equal(string(wh1 + 2), ln) |
| 210 | call assert_equal('', bn1) |
| 211 | call assert_equal('', bn2) |
| 212 | endif |
| 213 | |
| 214 | if RunVim([], after, '-O foo bar') |
| 215 | " Same expectations as for -O2 but buffer names should be foo and bar |
| 216 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 217 | call assert_equal('2', wn) |
| 218 | call assert_inrange(0, 1, ww1 - ww2) |
| 219 | call assert_equal(string(ww1 + ww2 + 1), cn) |
| 220 | call assert_equal(wh1, wh2) |
| 221 | call assert_equal(string(wh1 + 2), ln) |
| 222 | call assert_equal('foo', bn1) |
| 223 | call assert_equal('bar', bn2) |
| 224 | endif |
| 225 | |
| 226 | call delete('Xtestout') |
| 227 | endfunc |
| 228 | |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 229 | " Test the -p[N] argument to open N tabpages. |
| 230 | func Test_p_arg() |
| 231 | let after = [ |
| 232 | \ 'call writefile(split(execute("tabs"), "\n"), "Xtestout")', |
| 233 | \ 'qall', |
| 234 | \ ] |
| 235 | if RunVim([], after, '-p2') |
| 236 | let lines = readfile('Xtestout') |
| 237 | call assert_equal(4, len(lines)) |
| 238 | call assert_equal('Tab page 1', lines[0]) |
| 239 | call assert_equal('> [No Name]', lines[1]) |
| 240 | call assert_equal('Tab page 2', lines[2]) |
| 241 | call assert_equal(' [No Name]', lines[3]) |
| 242 | endif |
| 243 | |
| 244 | if RunVim([], after, '-p foo bar') |
| 245 | let lines = readfile('Xtestout') |
| 246 | call assert_equal(4, len(lines)) |
| 247 | call assert_equal('Tab page 1', lines[0]) |
| 248 | call assert_equal('> foo', lines[1]) |
| 249 | call assert_equal('Tab page 2', lines[2]) |
| 250 | call assert_equal(' bar', lines[3]) |
| 251 | endif |
| 252 | |
| 253 | call delete('Xtestout') |
| 254 | endfunc |
| 255 | |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 256 | " Test the -V[N] argument to set the 'verbose' option to [N] |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 257 | func Test_V_arg() |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 258 | if has('gui_running') |
| 259 | " Can't catch the output of gvim. |
| 260 | return |
| 261 | endif |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 262 | let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq') |
| 263 | call assert_equal(" verbose=0\n", out) |
| 264 | |
| 265 | let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq') |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 266 | call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nSearching for \"filetype\.vim\".*\n", out) |
| 267 | call assert_match(" verbose=2\n", out) |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 268 | |
| 269 | let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq') |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 270 | 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] | 271 | endfunc |
| 272 | |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 273 | " Test the '-q [errorfile]' argument. |
| 274 | func Test_q_arg() |
| 275 | let source_file = has('win32') ? '..\memfile.c' : '../memfile.c' |
| 276 | let after = [ |
| 277 | \ 'call writefile([&errorfile, string(getpos("."))], "Xtestout")', |
| 278 | \ 'copen', |
| 279 | \ 'w >> Xtestout', |
| 280 | \ 'qall' |
| 281 | \ ] |
| 282 | |
| 283 | " Test with default argument '-q'. |
| 284 | call assert_equal('errors.err', &errorfile) |
| 285 | call writefile(["../memfile.c:1482:5: error: expected ';' before '}' token"], 'errors.err') |
| 286 | if RunVim([], after, '-q') |
| 287 | let lines = readfile('Xtestout') |
| 288 | call assert_equal(['errors.err', |
| 289 | \ '[0, 1482, 5, 0]', |
| 290 | \ source_file . "|1482 col 5| error: expected ';' before '}' token"], |
| 291 | \ lines) |
| 292 | endif |
| 293 | call delete('Xtestout') |
| 294 | call delete('errors.err') |
| 295 | |
| 296 | " Test with explicit argument '-q Xerrors' (with space). |
| 297 | call writefile(["../memfile.c:1482:5: error: expected ';' before '}' token"], 'Xerrors') |
| 298 | if RunVim([], after, '-q Xerrors') |
| 299 | let lines = readfile('Xtestout') |
| 300 | call assert_equal(['Xerrors', |
| 301 | \ '[0, 1482, 5, 0]', |
| 302 | \ source_file . "|1482 col 5| error: expected ';' before '}' token"], |
| 303 | \ lines) |
| 304 | endif |
| 305 | call delete('Xtestout') |
| 306 | |
| 307 | " Test with explicit argument '-qXerrors' (without space). |
| 308 | if RunVim([], after, '-qXerrors') |
| 309 | let lines = readfile('Xtestout') |
| 310 | call assert_equal(['Xerrors', |
| 311 | \ '[0, 1482, 5, 0]', |
| 312 | \ source_file . "|1482 col 5| error: expected ';' before '}' token"], |
| 313 | \ lines) |
| 314 | endif |
| 315 | |
| 316 | call delete('Xtestout') |
| 317 | call delete('Xerrors') |
| 318 | endfunc |
| 319 | |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 320 | " Test the -V[N]{filename} argument to set the 'verbose' option to N |
| 321 | " and set 'verbosefile' to filename. |
| 322 | func Test_V_file_arg() |
Bram Moolenaar | 4841a7c | 2018-09-22 14:08:49 +0200 | [diff] [blame] | 323 | if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq') |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 324 | let out = join(readfile('Xverbosefile'), "\n") |
| 325 | call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out) |
| 326 | call assert_match("\n verbose=2\n", out) |
| 327 | call assert_match("\n verbosefile=Xverbosefile", out) |
| 328 | endif |
| 329 | |
| 330 | call delete('Xverbosefile') |
| 331 | endfunc |
| 332 | |
| 333 | " Test the -m, -M and -R arguments: |
| 334 | " -m resets 'write' |
| 335 | " -M resets 'modifiable' and 'write' |
| 336 | " -R sets 'readonly' |
| 337 | func Test_m_M_R() |
| 338 | let after = [ |
| 339 | \ 'call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout")', |
| 340 | \ 'qall', |
| 341 | \ ] |
| 342 | if RunVim([], after, '') |
| 343 | let lines = readfile('Xtestout') |
| 344 | call assert_equal(['1', '1', '0', '200'], lines) |
| 345 | endif |
| 346 | if RunVim([], after, '-m') |
| 347 | let lines = readfile('Xtestout') |
| 348 | call assert_equal(['0', '1', '0', '200'], lines) |
| 349 | endif |
| 350 | if RunVim([], after, '-M') |
| 351 | let lines = readfile('Xtestout') |
| 352 | call assert_equal(['0', '0', '0', '200'], lines) |
| 353 | endif |
| 354 | if RunVim([], after, '-R') |
| 355 | let lines = readfile('Xtestout') |
| 356 | call assert_equal(['1', '1', '1', '10000'], lines) |
| 357 | endif |
| 358 | |
| 359 | call delete('Xtestout') |
| 360 | endfunc |
| 361 | |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 362 | " Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes). |
| 363 | func Test_A_F_H_arg() |
| 364 | let after = [ |
| 365 | \ 'call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout")', |
| 366 | \ 'qall', |
| 367 | \ ] |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 368 | " Use silent Ex mode to avoid the hit-Enter prompt for the warning that |
| 369 | " 'encoding' is not utf-8. |
| 370 | if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A') |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 371 | let lines = readfile('Xtestout') |
| 372 | call assert_equal(['1', '1', '0', '0'], lines) |
| 373 | endif |
| 374 | |
| 375 | if has('farsi') && RunVim([], after, '-F') |
| 376 | let lines = readfile('Xtestout') |
| 377 | call assert_equal(['1', '0', '1', '0'], lines) |
| 378 | endif |
| 379 | |
| 380 | if has('rightleft') && RunVim([], after, '-H') |
| 381 | let lines = readfile('Xtestout') |
| 382 | call assert_equal(['1', '0', '0', '1'], lines) |
| 383 | endif |
| 384 | |
| 385 | call delete('Xtestout') |
| 386 | endfunc |
| 387 | |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 388 | func Test_invalid_args() |
| 389 | if !has('unix') || has('gui_running') |
| 390 | " can't get output of Vim. |
| 391 | return |
| 392 | endif |
| 393 | |
| 394 | for opt in ['-Y', '--does-not-exist'] |
| 395 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 396 | call assert_equal(1, v:shell_error) |
| 397 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 398 | call assert_equal('Unknown option argument: "' .. opt .. '"', out[1]) |
| 399 | call assert_equal('More info with: "vim -h"', out[2]) |
| 400 | endfor |
| 401 | |
| 402 | for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime'] |
| 403 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 404 | call assert_equal(1, v:shell_error) |
| 405 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 406 | call assert_equal('Argument missing after: "' .. opt .. '"', out[1]) |
| 407 | call assert_equal('More info with: "vim -h"', out[2]) |
| 408 | endfor |
| 409 | |
| 410 | if has('clientserver') |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 411 | for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr', |
| 412 | \ '--remote-tab', '--remote-tab-wait', |
| 413 | \ '--remote-tab-wait-silent', '--remote-tab-silent', |
| 414 | \ '--remote-wait', '--remote-wait-silent', |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 415 | \ '--servername', |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 416 | \ ] |
| 417 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 418 | call assert_equal(1, v:shell_error) |
| 419 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 420 | call assert_equal('Argument missing after: "' .. opt .. '"', out[1]) |
| 421 | call assert_equal('More info with: "vim -h"', out[2]) |
| 422 | endfor |
| 423 | endif |
| 424 | |
Bram Moolenaar | 240f7ab | 2019-05-08 17:58:15 +0200 | [diff] [blame] | 425 | if has('gui_gtk') |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 426 | let out = split(system(GetVimCommand() .. ' --display'), "\n") |
| 427 | call assert_equal(1, v:shell_error) |
| 428 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 429 | call assert_equal('Argument missing after: "--display"', out[1]) |
| 430 | call assert_equal('More info with: "vim -h"', out[2]) |
| 431 | endif |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 432 | |
Bram Moolenaar | 5416b75 | 2019-05-08 18:36:43 +0200 | [diff] [blame] | 433 | if has('xterm_clipboard') |
Bram Moolenaar | 240f7ab | 2019-05-08 17:58:15 +0200 | [diff] [blame] | 434 | let out = split(system(GetVimCommand() .. ' -display'), "\n") |
| 435 | call assert_equal(1, v:shell_error) |
| 436 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 437 | call assert_equal('Argument missing after: "-display"', out[1]) |
| 438 | call assert_equal('More info with: "vim -h"', out[2]) |
| 439 | endif |
| 440 | |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 441 | let out = split(system(GetVimCommand() .. ' -ix'), "\n") |
| 442 | call assert_equal(1, v:shell_error) |
| 443 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 444 | call assert_equal('Garbage after option argument: "-ix"', out[1]) |
| 445 | call assert_equal('More info with: "vim -h"', out[2]) |
| 446 | |
| 447 | let out = split(system(GetVimCommand() .. ' - xxx'), "\n") |
| 448 | call assert_equal(1, v:shell_error) |
| 449 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 450 | call assert_equal('Too many edit arguments: "xxx"', out[1]) |
| 451 | call assert_equal('More info with: "vim -h"', out[2]) |
| 452 | |
| 453 | " Detect invalid repeated arguments '-t foo -t foo", '-q foo -q foo'. |
| 454 | for opt in ['-t', '-q'] |
| 455 | let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n") |
| 456 | call assert_equal(1, v:shell_error) |
| 457 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 458 | call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1]) |
| 459 | call assert_equal('More info with: "vim -h"', out[2]) |
| 460 | endfor |
| 461 | |
| 462 | for opt in [' -cq', ' --cmd q', ' +', ' -S foo'] |
| 463 | let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n") |
| 464 | call assert_equal(1, v:shell_error) |
| 465 | " FIXME: The error message given by Vim is not ideal in case of repeated |
| 466 | " -S foo since it does not mention -S. |
| 467 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 468 | call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1]) |
| 469 | call assert_equal('More info with: "vim -h"', out[2]) |
| 470 | endfor |
| 471 | |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 472 | if has('gui_gtk') |
| 473 | for opt in ['--socketid x', '--socketid 0xg'] |
| 474 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 475 | call assert_equal(1, v:shell_error) |
| 476 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 477 | call assert_equal('Invalid argument for: "--socketid"', out[1]) |
| 478 | call assert_equal('More info with: "vim -h"', out[2]) |
| 479 | endfor |
| 480 | endif |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 481 | endfunc |
| 482 | |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 483 | func Test_file_args() |
| 484 | let after = [ |
| 485 | \ 'call writefile(argv(), "Xtestout")', |
| 486 | \ 'qall', |
| 487 | \ ] |
| 488 | if RunVim([], after, '') |
| 489 | let lines = readfile('Xtestout') |
| 490 | call assert_equal(0, len(lines)) |
| 491 | endif |
| 492 | |
| 493 | if RunVim([], after, 'one') |
| 494 | let lines = readfile('Xtestout') |
| 495 | call assert_equal(1, len(lines)) |
| 496 | call assert_equal('one', lines[0]) |
| 497 | endif |
| 498 | |
| 499 | if RunVim([], after, 'one two three') |
| 500 | let lines = readfile('Xtestout') |
| 501 | call assert_equal(3, len(lines)) |
| 502 | call assert_equal('one', lines[0]) |
| 503 | call assert_equal('two', lines[1]) |
| 504 | call assert_equal('three', lines[2]) |
| 505 | endif |
| 506 | |
| 507 | if RunVim([], after, 'one -c echo two') |
| 508 | let lines = readfile('Xtestout') |
| 509 | call assert_equal(2, len(lines)) |
| 510 | call assert_equal('one', lines[0]) |
| 511 | call assert_equal('two', lines[1]) |
| 512 | endif |
| 513 | |
| 514 | if RunVim([], after, 'one -- -c echo two') |
| 515 | let lines = readfile('Xtestout') |
| 516 | call assert_equal(4, len(lines)) |
| 517 | call assert_equal('one', lines[0]) |
| 518 | call assert_equal('-c', lines[1]) |
| 519 | call assert_equal('echo', lines[2]) |
| 520 | call assert_equal('two', lines[3]) |
| 521 | endif |
| 522 | |
| 523 | call delete('Xtestout') |
| 524 | endfunc |
| 525 | |
| 526 | func Test_startuptime() |
| 527 | if !has('startuptime') |
| 528 | return |
| 529 | endif |
| 530 | let after = ['qall'] |
| 531 | if RunVim([], after, '--startuptime Xtestout one') |
| 532 | let lines = readfile('Xtestout') |
| 533 | let expected = ['--- VIM STARTING ---', 'parsing arguments', |
| 534 | \ 'shell init', 'inits 3', 'start termcap', 'opening buffers'] |
| 535 | let found = [] |
| 536 | for line in lines |
| 537 | for exp in expected |
| 538 | if line =~ exp |
| 539 | call add(found, exp) |
| 540 | endif |
| 541 | endfor |
| 542 | endfor |
| 543 | call assert_equal(expected, found) |
| 544 | endif |
| 545 | call delete('Xtestout') |
| 546 | endfunc |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 547 | |
| 548 | func Test_read_stdin() |
| 549 | let after = [ |
| 550 | \ 'write Xtestout', |
| 551 | \ 'quit!', |
| 552 | \ ] |
| 553 | if RunVimPiped([], after, '-', 'echo something | ') |
| 554 | let lines = readfile('Xtestout') |
Bram Moolenaar | e4a76ad | 2016-08-07 16:50:10 +0200 | [diff] [blame] | 555 | " MS-Windows adds a space after the word |
| 556 | call assert_equal(['something'], split(lines[0])) |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 557 | endif |
| 558 | call delete('Xtestout') |
| 559 | endfunc |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 560 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 561 | func Test_set_shell() |
| 562 | let after = [ |
| 563 | \ 'call writefile([&shell], "Xtestout")', |
| 564 | \ 'quit!', |
| 565 | \ ] |
| 566 | let $SHELL = '/bin/with space/sh' |
| 567 | if RunVimPiped([], after, '', '') |
| 568 | let lines = readfile('Xtestout') |
| 569 | " MS-Windows adds a space after the word |
| 570 | call assert_equal('/bin/with\ space/sh', lines[0]) |
| 571 | endif |
| 572 | call delete('Xtestout') |
| 573 | endfunc |
| 574 | |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 575 | func Test_progpath() |
| 576 | " Tests normally run with "./vim" or "../vim", these must have been expanded |
| 577 | " to a full path. |
| 578 | if has('unix') |
| 579 | call assert_equal('/', v:progpath[0]) |
| 580 | elseif has('win32') |
| 581 | call assert_equal(':', v:progpath[1]) |
| 582 | call assert_match('[/\\]', v:progpath[2]) |
| 583 | endif |
| 584 | |
| 585 | " Only expect "vim" to appear in v:progname. |
| 586 | call assert_match('vim\c', v:progname) |
| 587 | endfunc |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 588 | |
| 589 | func Test_silent_ex_mode() |
| 590 | if !has('unix') || has('gui_running') |
| 591 | " can't get output of Vim. |
| 592 | return |
| 593 | endif |
| 594 | |
| 595 | " This caused an ml_get error. |
| 596 | let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq') |
| 597 | call assert_notmatch('E315:', out) |
| 598 | endfunc |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 599 | |
| 600 | func Test_default_term() |
| 601 | if !has('unix') || has('gui_running') |
| 602 | " can't get output of Vim. |
| 603 | return |
| 604 | endif |
| 605 | |
| 606 | let save_term = $TERM |
Bram Moolenaar | 08f88b1 | 2017-04-02 17:21:16 +0200 | [diff] [blame] | 607 | let $TERM = 'unknownxxx' |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 608 | let out = system(GetVimCommand() . ' -c''set term'' -c cq') |
| 609 | call assert_match("defaulting to 'ansi'", out) |
| 610 | let $TERM = save_term |
| 611 | endfunc |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 612 | |
| 613 | func Test_zzz_startinsert() |
| 614 | " Test :startinsert |
| 615 | call writefile(['123456'], 'Xtestout') |
| 616 | let after = [ |
| 617 | \ ':startinsert', |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 618 | \ 'call feedkeys("foobar\<c-o>:wq\<cr>","t")' |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 619 | \ ] |
| 620 | if RunVim([], after, 'Xtestout') |
| 621 | let lines = readfile('Xtestout') |
| 622 | call assert_equal(['foobar123456'], lines) |
| 623 | endif |
| 624 | " Test :startinsert! |
| 625 | call writefile(['123456'], 'Xtestout') |
| 626 | let after = [ |
| 627 | \ ':startinsert!', |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 628 | \ 'call feedkeys("foobar\<c-o>:wq\<cr>","t")' |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 629 | \ ] |
| 630 | if RunVim([], after, 'Xtestout') |
| 631 | let lines = readfile('Xtestout') |
| 632 | call assert_equal(['123456foobar'], lines) |
| 633 | endif |
| 634 | call delete('Xtestout') |
| 635 | endfunc |
Bram Moolenaar | 97c2c05 | 2019-02-22 13:42:07 +0100 | [diff] [blame] | 636 | |
| 637 | func Test_issue_3969() |
| 638 | if has('gui_running') |
| 639 | " Can't catch the output of gvim. |
| 640 | return |
| 641 | endif |
| 642 | " Check that message is not truncated. |
| 643 | let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq') |
| 644 | call assert_equal('hello', out) |
| 645 | endfunc |
Bram Moolenaar | c75e812 | 2019-04-21 15:55:10 +0200 | [diff] [blame] | 646 | |
| 647 | func Test_start_with_tabs() |
| 648 | if !CanRunVimInTerminal() |
| 649 | return |
| 650 | endif |
| 651 | |
| 652 | let buf = RunVimInTerminal('-p a b c', {}) |
| 653 | call VerifyScreenDump(buf, 'Test_start_with_tabs', {}) |
| 654 | |
| 655 | " clean up |
| 656 | call StopVimInTerminal(buf) |
| 657 | endfunc |