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 | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 388 | func Test_file_args() |
| 389 | let after = [ |
| 390 | \ 'call writefile(argv(), "Xtestout")', |
| 391 | \ 'qall', |
| 392 | \ ] |
| 393 | if RunVim([], after, '') |
| 394 | let lines = readfile('Xtestout') |
| 395 | call assert_equal(0, len(lines)) |
| 396 | endif |
| 397 | |
| 398 | if RunVim([], after, 'one') |
| 399 | let lines = readfile('Xtestout') |
| 400 | call assert_equal(1, len(lines)) |
| 401 | call assert_equal('one', lines[0]) |
| 402 | endif |
| 403 | |
| 404 | if RunVim([], after, 'one two three') |
| 405 | let lines = readfile('Xtestout') |
| 406 | call assert_equal(3, len(lines)) |
| 407 | call assert_equal('one', lines[0]) |
| 408 | call assert_equal('two', lines[1]) |
| 409 | call assert_equal('three', lines[2]) |
| 410 | endif |
| 411 | |
| 412 | if RunVim([], after, 'one -c echo two') |
| 413 | let lines = readfile('Xtestout') |
| 414 | call assert_equal(2, len(lines)) |
| 415 | call assert_equal('one', lines[0]) |
| 416 | call assert_equal('two', lines[1]) |
| 417 | endif |
| 418 | |
| 419 | if RunVim([], after, 'one -- -c echo two') |
| 420 | let lines = readfile('Xtestout') |
| 421 | call assert_equal(4, len(lines)) |
| 422 | call assert_equal('one', lines[0]) |
| 423 | call assert_equal('-c', lines[1]) |
| 424 | call assert_equal('echo', lines[2]) |
| 425 | call assert_equal('two', lines[3]) |
| 426 | endif |
| 427 | |
| 428 | call delete('Xtestout') |
| 429 | endfunc |
| 430 | |
| 431 | func Test_startuptime() |
| 432 | if !has('startuptime') |
| 433 | return |
| 434 | endif |
| 435 | let after = ['qall'] |
| 436 | if RunVim([], after, '--startuptime Xtestout one') |
| 437 | let lines = readfile('Xtestout') |
| 438 | let expected = ['--- VIM STARTING ---', 'parsing arguments', |
| 439 | \ 'shell init', 'inits 3', 'start termcap', 'opening buffers'] |
| 440 | let found = [] |
| 441 | for line in lines |
| 442 | for exp in expected |
| 443 | if line =~ exp |
| 444 | call add(found, exp) |
| 445 | endif |
| 446 | endfor |
| 447 | endfor |
| 448 | call assert_equal(expected, found) |
| 449 | endif |
| 450 | call delete('Xtestout') |
| 451 | endfunc |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 452 | |
| 453 | func Test_read_stdin() |
| 454 | let after = [ |
| 455 | \ 'write Xtestout', |
| 456 | \ 'quit!', |
| 457 | \ ] |
| 458 | if RunVimPiped([], after, '-', 'echo something | ') |
| 459 | let lines = readfile('Xtestout') |
Bram Moolenaar | e4a76ad | 2016-08-07 16:50:10 +0200 | [diff] [blame] | 460 | " MS-Windows adds a space after the word |
| 461 | call assert_equal(['something'], split(lines[0])) |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 462 | endif |
| 463 | call delete('Xtestout') |
| 464 | endfunc |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 465 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 466 | func Test_set_shell() |
| 467 | let after = [ |
| 468 | \ 'call writefile([&shell], "Xtestout")', |
| 469 | \ 'quit!', |
| 470 | \ ] |
| 471 | let $SHELL = '/bin/with space/sh' |
| 472 | if RunVimPiped([], after, '', '') |
| 473 | let lines = readfile('Xtestout') |
| 474 | " MS-Windows adds a space after the word |
| 475 | call assert_equal('/bin/with\ space/sh', lines[0]) |
| 476 | endif |
| 477 | call delete('Xtestout') |
| 478 | endfunc |
| 479 | |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 480 | func Test_progpath() |
| 481 | " Tests normally run with "./vim" or "../vim", these must have been expanded |
| 482 | " to a full path. |
| 483 | if has('unix') |
| 484 | call assert_equal('/', v:progpath[0]) |
| 485 | elseif has('win32') |
| 486 | call assert_equal(':', v:progpath[1]) |
| 487 | call assert_match('[/\\]', v:progpath[2]) |
| 488 | endif |
| 489 | |
| 490 | " Only expect "vim" to appear in v:progname. |
| 491 | call assert_match('vim\c', v:progname) |
| 492 | endfunc |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 493 | |
| 494 | func Test_silent_ex_mode() |
| 495 | if !has('unix') || has('gui_running') |
| 496 | " can't get output of Vim. |
| 497 | return |
| 498 | endif |
| 499 | |
| 500 | " This caused an ml_get error. |
| 501 | let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq') |
| 502 | call assert_notmatch('E315:', out) |
| 503 | endfunc |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 504 | |
| 505 | func Test_default_term() |
| 506 | if !has('unix') || has('gui_running') |
| 507 | " can't get output of Vim. |
| 508 | return |
| 509 | endif |
| 510 | |
| 511 | let save_term = $TERM |
Bram Moolenaar | 08f88b1 | 2017-04-02 17:21:16 +0200 | [diff] [blame] | 512 | let $TERM = 'unknownxxx' |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 513 | let out = system(GetVimCommand() . ' -c''set term'' -c cq') |
| 514 | call assert_match("defaulting to 'ansi'", out) |
| 515 | let $TERM = save_term |
| 516 | endfunc |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 517 | |
| 518 | func Test_zzz_startinsert() |
| 519 | " Test :startinsert |
| 520 | call writefile(['123456'], 'Xtestout') |
| 521 | let after = [ |
| 522 | \ ':startinsert', |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 523 | \ 'call feedkeys("foobar\<c-o>:wq\<cr>","t")' |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 524 | \ ] |
| 525 | if RunVim([], after, 'Xtestout') |
| 526 | let lines = readfile('Xtestout') |
| 527 | call assert_equal(['foobar123456'], lines) |
| 528 | endif |
| 529 | " Test :startinsert! |
| 530 | call writefile(['123456'], 'Xtestout') |
| 531 | let after = [ |
| 532 | \ ':startinsert!', |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 533 | \ 'call feedkeys("foobar\<c-o>:wq\<cr>","t")' |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 534 | \ ] |
| 535 | if RunVim([], after, 'Xtestout') |
| 536 | let lines = readfile('Xtestout') |
| 537 | call assert_equal(['123456foobar'], lines) |
| 538 | endif |
| 539 | call delete('Xtestout') |
| 540 | endfunc |
Bram Moolenaar | 97c2c05 | 2019-02-22 13:42:07 +0100 | [diff] [blame] | 541 | |
| 542 | func Test_issue_3969() |
| 543 | if has('gui_running') |
| 544 | " Can't catch the output of gvim. |
| 545 | return |
| 546 | endif |
| 547 | " Check that message is not truncated. |
| 548 | let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq') |
| 549 | call assert_equal('hello', out) |
| 550 | endfunc |
Bram Moolenaar | c75e812 | 2019-04-21 15:55:10 +0200 | [diff] [blame] | 551 | |
| 552 | func Test_start_with_tabs() |
| 553 | if !CanRunVimInTerminal() |
| 554 | return |
| 555 | endif |
| 556 | |
| 557 | let buf = RunVimInTerminal('-p a b c', {}) |
| 558 | call VerifyScreenDump(buf, 'Test_start_with_tabs', {}) |
| 559 | |
| 560 | " clean up |
| 561 | call StopVimInTerminal(buf) |
| 562 | endfunc |