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