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