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 | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 5 | source term_util.vim |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 6 | source check.vim |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 7 | |
| 8 | " Check that loading startup.vim works. |
Bram Moolenaar | b9a46fe | 2016-07-29 18:13:42 +0200 | [diff] [blame] | 9 | func Test_startup_script() |
| 10 | set compatible |
| 11 | source $VIMRUNTIME/defaults.vim |
| 12 | |
| 13 | call assert_equal(0, &compatible) |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 14 | " Restore some options, so that the following tests doesn't break |
| 15 | set nomore |
| 16 | set noshowmode |
Bram Moolenaar | b9a46fe | 2016-07-29 18:13:42 +0200 | [diff] [blame] | 17 | endfunc |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 18 | |
| 19 | " Verify the order in which plugins are loaded: |
| 20 | " 1. plugins in non-after directories |
| 21 | " 2. packages |
| 22 | " 3. plugins in after directories |
| 23 | func Test_after_comes_later() |
Bram Moolenaar | 3286043 | 2016-08-06 19:24:23 +0200 | [diff] [blame] | 24 | if !has('packages') |
| 25 | return |
| 26 | endif |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 27 | let before =<< trim [CODE] |
| 28 | set nocp viminfo+=nviminfo |
| 29 | set guioptions+=M |
| 30 | let $HOME = "/does/not/exist" |
| 31 | set loadplugins |
| 32 | set rtp=Xhere,Xafter,Xanother |
| 33 | set packpath=Xhere,Xafter |
| 34 | set nomore |
| 35 | let g:sequence = "" |
| 36 | [CODE] |
| 37 | |
| 38 | let after =<< trim [CODE] |
| 39 | redir! > Xtestout |
| 40 | scriptnames |
| 41 | redir END |
| 42 | redir! > Xsequence |
| 43 | echo g:sequence |
| 44 | redir END |
| 45 | quit |
| 46 | [CODE] |
| 47 | |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 48 | call mkdir('Xhere/plugin', 'p') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 49 | call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim') |
| 50 | call mkdir('Xanother/plugin', 'p') |
| 51 | call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 52 | call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 53 | 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] | 54 | |
| 55 | call mkdir('Xafter/plugin', 'p') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 56 | call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 57 | |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 58 | if RunVim(before, after, '') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 59 | |
Bram Moolenaar | 83b3c3d | 2016-08-06 19:16:43 +0200 | [diff] [blame] | 60 | let lines = readfile('Xtestout') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 61 | 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] | 62 | let found = [] |
| 63 | for line in lines |
| 64 | for one in expected |
| 65 | if line =~ one |
| 66 | call add(found, one) |
| 67 | endif |
| 68 | endfor |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 69 | endfor |
Bram Moolenaar | 83b3c3d | 2016-08-06 19:16:43 +0200 | [diff] [blame] | 70 | call assert_equal(expected, found) |
| 71 | endif |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 72 | |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 73 | call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', '')) |
| 74 | |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 75 | call delete('Xtestout') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 76 | call delete('Xsequence') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 77 | call delete('Xhere', 'rf') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 78 | call delete('Xanother', 'rf') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 79 | call delete('Xafter', 'rf') |
| 80 | endfunc |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 81 | |
Bram Moolenaar | ce876aa | 2017-06-04 17:47:42 +0200 | [diff] [blame] | 82 | func Test_pack_in_rtp_when_plugins_run() |
| 83 | if !has('packages') |
| 84 | return |
| 85 | endif |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 86 | let before =<< trim [CODE] |
| 87 | set nocp viminfo+=nviminfo |
| 88 | set guioptions+=M |
| 89 | let $HOME = "/does/not/exist" |
| 90 | set loadplugins |
| 91 | set rtp=Xhere |
| 92 | set packpath=Xhere |
| 93 | set nomore |
| 94 | [CODE] |
| 95 | |
Bram Moolenaar | ce876aa | 2017-06-04 17:47:42 +0200 | [diff] [blame] | 96 | let after = [ |
| 97 | \ 'quit', |
| 98 | \ ] |
| 99 | call mkdir('Xhere/plugin', 'p') |
| 100 | call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim') |
| 101 | call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p') |
| 102 | call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim') |
| 103 | |
| 104 | if RunVim(before, after, '') |
| 105 | |
| 106 | let lines = filter(readfile('Xtestout'), '!empty(v:val)') |
| 107 | call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0)) |
| 108 | call assert_match('autoloaded foo', get(lines, 1)) |
| 109 | endif |
| 110 | |
| 111 | call delete('Xtestout') |
| 112 | call delete('Xhere', 'rf') |
| 113 | endfunc |
| 114 | |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 115 | func Test_help_arg() |
Bram Moolenaar | 3321e9d | 2016-08-06 23:03:59 +0200 | [diff] [blame] | 116 | if !has('unix') && has('gui') |
| 117 | " this doesn't work with gvim on MS-Windows |
| 118 | return |
| 119 | endif |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 120 | if RunVim([], [], '--help >Xtestout') |
| 121 | let lines = readfile('Xtestout') |
| 122 | call assert_true(len(lines) > 20) |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 123 | call assert_match('Vi IMproved', lines[0]) |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 124 | |
| 125 | " check if couple of lines are there |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 126 | let found = [] |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 127 | for line in lines |
| 128 | if line =~ '-R.*Readonly mode' |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 129 | call add(found, 'Readonly mode') |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 130 | endif |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 131 | " Watch out for a second --version line in the Gnome version. |
| 132 | if line =~ '--version.*Print version information and exit' |
| 133 | call add(found, "--version") |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 134 | endif |
| 135 | endfor |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 136 | call assert_equal(['Readonly mode', '--version'], found) |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 137 | endif |
| 138 | call delete('Xtestout') |
| 139 | endfunc |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 140 | |
| 141 | func Test_compatible_args() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 142 | let after =<< trim [CODE] |
| 143 | call writefile([string(&compatible)], "Xtestout") |
| 144 | set viminfo+=nviminfo |
| 145 | quit |
| 146 | [CODE] |
| 147 | |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 148 | if RunVim([], after, '-C') |
| 149 | let lines = readfile('Xtestout') |
| 150 | call assert_equal('1', lines[0]) |
| 151 | endif |
| 152 | |
| 153 | if RunVim([], after, '-N') |
| 154 | let lines = readfile('Xtestout') |
| 155 | call assert_equal('0', lines[0]) |
| 156 | endif |
| 157 | |
| 158 | call delete('Xtestout') |
| 159 | endfunc |
| 160 | |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 161 | " Test the -o[N] and -O[N] arguments to open N windows split |
| 162 | " horizontally or vertically. |
| 163 | func Test_o_arg() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 164 | let after =<< trim [CODE] |
Bram Moolenaar | e96a249 | 2019-06-25 04:12:16 +0200 | [diff] [blame] | 165 | set cpo&vim |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 166 | call writefile([winnr("$"), |
| 167 | \ winheight(1), winheight(2), &lines, |
| 168 | \ winwidth(1), winwidth(2), &columns, |
| 169 | \ bufname(winbufnr(1)), bufname(winbufnr(2))], |
| 170 | \ "Xtestout") |
| 171 | qall |
| 172 | [CODE] |
| 173 | |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 174 | if RunVim([], after, '-o2') |
| 175 | " Open 2 windows split horizontally. Expect: |
| 176 | " - 2 windows |
| 177 | " - both windows should have the same or almost the same height |
| 178 | " - sum of both windows height (+ 3 for both statusline and Ex command) |
| 179 | " should be equal to the number of lines |
| 180 | " - both windows should have the same width which should be equal to the |
| 181 | " number of columns |
| 182 | " - buffer of both windows should have no name |
| 183 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 184 | call assert_equal('2', wn) |
| 185 | call assert_inrange(0, 1, wh1 - wh2) |
| 186 | call assert_equal(string(wh1 + wh2 + 3), ln) |
| 187 | call assert_equal(ww1, ww2) |
| 188 | call assert_equal(ww1, cn) |
| 189 | call assert_equal('', bn1) |
| 190 | call assert_equal('', bn2) |
| 191 | endif |
| 192 | |
| 193 | if RunVim([], after, '-o foo bar') |
| 194 | " Same expectations as for -o2 but buffer names should be foo and bar |
| 195 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 196 | call assert_equal('2', wn) |
| 197 | call assert_inrange(0, 1, wh1 - wh2) |
| 198 | call assert_equal(string(wh1 + wh2 + 3), ln) |
| 199 | call assert_equal(ww1, ww2) |
| 200 | call assert_equal(ww1, cn) |
| 201 | call assert_equal('foo', bn1) |
| 202 | call assert_equal('bar', bn2) |
| 203 | endif |
| 204 | |
| 205 | if RunVim([], after, '-O2') |
| 206 | " Open 2 windows split vertically. Expect: |
| 207 | " - 2 windows |
| 208 | " - both windows should have the same or almost the same width |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 209 | " - sum of both windows width (+ 1 for the separator) should be equal to |
| 210 | " the number of columns |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 211 | " - both windows should have the same height |
| 212 | " - window height (+ 2 for the statusline and Ex command) should be equal |
| 213 | " to the number of lines |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 214 | " - buffer of both windows should have no name |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 215 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 216 | call assert_equal('2', wn) |
| 217 | call assert_inrange(0, 1, ww1 - ww2) |
| 218 | call assert_equal(string(ww1 + ww2 + 1), cn) |
| 219 | call assert_equal(wh1, wh2) |
| 220 | call assert_equal(string(wh1 + 2), ln) |
| 221 | call assert_equal('', bn1) |
| 222 | call assert_equal('', bn2) |
| 223 | endif |
| 224 | |
| 225 | if RunVim([], after, '-O foo bar') |
| 226 | " Same expectations as for -O2 but buffer names should be foo and bar |
| 227 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 228 | call assert_equal('2', wn) |
| 229 | call assert_inrange(0, 1, ww1 - ww2) |
| 230 | call assert_equal(string(ww1 + ww2 + 1), cn) |
| 231 | call assert_equal(wh1, wh2) |
| 232 | call assert_equal(string(wh1 + 2), ln) |
| 233 | call assert_equal('foo', bn1) |
| 234 | call assert_equal('bar', bn2) |
| 235 | endif |
| 236 | |
| 237 | call delete('Xtestout') |
| 238 | endfunc |
| 239 | |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 240 | " Test the -p[N] argument to open N tabpages. |
| 241 | func Test_p_arg() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 242 | let after =<< trim [CODE] |
| 243 | call writefile(split(execute("tabs"), "\n"), "Xtestout") |
| 244 | qall |
| 245 | [CODE] |
| 246 | |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 247 | if RunVim([], after, '-p2') |
| 248 | let lines = readfile('Xtestout') |
| 249 | call assert_equal(4, len(lines)) |
| 250 | call assert_equal('Tab page 1', lines[0]) |
| 251 | call assert_equal('> [No Name]', lines[1]) |
| 252 | call assert_equal('Tab page 2', lines[2]) |
| 253 | call assert_equal(' [No Name]', lines[3]) |
| 254 | endif |
| 255 | |
| 256 | if RunVim([], after, '-p foo bar') |
| 257 | let lines = readfile('Xtestout') |
| 258 | call assert_equal(4, len(lines)) |
| 259 | call assert_equal('Tab page 1', lines[0]) |
| 260 | call assert_equal('> foo', lines[1]) |
| 261 | call assert_equal('Tab page 2', lines[2]) |
| 262 | call assert_equal(' bar', lines[3]) |
| 263 | endif |
| 264 | |
| 265 | call delete('Xtestout') |
| 266 | endfunc |
| 267 | |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 268 | " Test the -V[N] argument to set the 'verbose' option to [N] |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 269 | func Test_V_arg() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 270 | " Can't catch the output of gvim. |
| 271 | CheckNotGui |
| 272 | |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 273 | let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq') |
| 274 | call assert_equal(" verbose=0\n", out) |
| 275 | |
| 276 | let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq') |
Bram Moolenaar | 4515bcd | 2020-05-03 18:21:04 +0200 | [diff] [blame] | 277 | call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline \\d\\+: sourcing \"[^\"]*runtime[\\/]filetype\.vim\".*\n", out) |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 278 | call assert_match(" verbose=2\n", out) |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 279 | |
| 280 | let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq') |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 281 | 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] | 282 | endfunc |
| 283 | |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 284 | " Test the '-q [errorfile]' argument. |
| 285 | func Test_q_arg() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 286 | CheckFeature quickfix |
| 287 | |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 288 | let lines =<< trim END |
| 289 | /* some file with an error */ |
| 290 | main() { |
| 291 | functionCall(arg; arg, arg); |
| 292 | return 666 |
| 293 | } |
| 294 | END |
| 295 | call writefile(lines, 'Xbadfile.c') |
| 296 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 297 | let after =<< trim [CODE] |
| 298 | call writefile([&errorfile, string(getpos("."))], "Xtestout") |
| 299 | copen |
| 300 | w >> Xtestout |
| 301 | qall |
| 302 | [CODE] |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 303 | |
| 304 | " Test with default argument '-q'. |
| 305 | call assert_equal('errors.err', &errorfile) |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 306 | call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'errors.err') |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 307 | if RunVim([], after, '-q') |
| 308 | let lines = readfile('Xtestout') |
| 309 | call assert_equal(['errors.err', |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 310 | \ '[0, 4, 12, 0]', |
| 311 | \ "Xbadfile.c|4 col 12| 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 | call delete('errors.err') |
| 316 | |
| 317 | " Test with explicit argument '-q Xerrors' (with space). |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 318 | call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'Xerrors') |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 319 | if RunVim([], after, '-q Xerrors') |
| 320 | let lines = readfile('Xtestout') |
| 321 | call assert_equal(['Xerrors', |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 322 | \ '[0, 4, 12, 0]', |
| 323 | \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"], |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 324 | \ lines) |
| 325 | endif |
| 326 | call delete('Xtestout') |
| 327 | |
| 328 | " Test with explicit argument '-qXerrors' (without space). |
| 329 | if RunVim([], after, '-qXerrors') |
| 330 | let lines = readfile('Xtestout') |
| 331 | call assert_equal(['Xerrors', |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 332 | \ '[0, 4, 12, 0]', |
| 333 | \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"], |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 334 | \ lines) |
| 335 | endif |
| 336 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 337 | " Test with a non-existing error file (exits with value 3) |
| 338 | let out = system(GetVimCommand() .. ' -q xyz.err') |
| 339 | call assert_equal(3, v:shell_error) |
| 340 | |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 341 | call delete('Xbadfile.c') |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 342 | call delete('Xtestout') |
| 343 | call delete('Xerrors') |
| 344 | endfunc |
| 345 | |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 346 | " Test the -V[N]{filename} argument to set the 'verbose' option to N |
| 347 | " and set 'verbosefile' to filename. |
| 348 | func Test_V_file_arg() |
Bram Moolenaar | 4841a7c | 2018-09-22 14:08:49 +0200 | [diff] [blame] | 349 | if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq') |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 350 | let out = join(readfile('Xverbosefile'), "\n") |
| 351 | call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out) |
| 352 | call assert_match("\n verbose=2\n", out) |
| 353 | call assert_match("\n verbosefile=Xverbosefile", out) |
| 354 | endif |
| 355 | |
| 356 | call delete('Xverbosefile') |
| 357 | endfunc |
| 358 | |
| 359 | " Test the -m, -M and -R arguments: |
| 360 | " -m resets 'write' |
| 361 | " -M resets 'modifiable' and 'write' |
| 362 | " -R sets 'readonly' |
| 363 | func Test_m_M_R() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 364 | let after =<< trim [CODE] |
| 365 | call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout") |
| 366 | qall |
| 367 | [CODE] |
| 368 | |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 369 | if RunVim([], after, '') |
| 370 | let lines = readfile('Xtestout') |
| 371 | call assert_equal(['1', '1', '0', '200'], lines) |
| 372 | endif |
| 373 | if RunVim([], after, '-m') |
| 374 | let lines = readfile('Xtestout') |
| 375 | call assert_equal(['0', '1', '0', '200'], lines) |
| 376 | endif |
| 377 | if RunVim([], after, '-M') |
| 378 | let lines = readfile('Xtestout') |
| 379 | call assert_equal(['0', '0', '0', '200'], lines) |
| 380 | endif |
| 381 | if RunVim([], after, '-R') |
| 382 | let lines = readfile('Xtestout') |
| 383 | call assert_equal(['1', '1', '1', '10000'], lines) |
| 384 | endif |
| 385 | |
| 386 | call delete('Xtestout') |
| 387 | endfunc |
| 388 | |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 389 | " Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes). |
| 390 | func Test_A_F_H_arg() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 391 | let after =<< trim [CODE] |
| 392 | call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout") |
| 393 | qall |
| 394 | [CODE] |
| 395 | |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 396 | " Use silent Ex mode to avoid the hit-Enter prompt for the warning that |
| 397 | " 'encoding' is not utf-8. |
| 398 | if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A') |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 399 | let lines = readfile('Xtestout') |
| 400 | call assert_equal(['1', '1', '0', '0'], lines) |
| 401 | endif |
| 402 | |
| 403 | if has('farsi') && RunVim([], after, '-F') |
| 404 | let lines = readfile('Xtestout') |
| 405 | call assert_equal(['1', '0', '1', '0'], lines) |
| 406 | endif |
| 407 | |
| 408 | if has('rightleft') && RunVim([], after, '-H') |
| 409 | let lines = readfile('Xtestout') |
| 410 | call assert_equal(['1', '0', '0', '1'], lines) |
| 411 | endif |
| 412 | |
| 413 | call delete('Xtestout') |
| 414 | endfunc |
| 415 | |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 416 | func Test_invalid_args() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 417 | " must be able to get the output of Vim. |
| 418 | CheckUnix |
| 419 | CheckNotGui |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 420 | |
| 421 | for opt in ['-Y', '--does-not-exist'] |
| 422 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 423 | call assert_equal(1, v:shell_error) |
| 424 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 425 | call assert_equal('Unknown option argument: "' .. opt .. '"', out[1]) |
| 426 | call assert_equal('More info with: "vim -h"', out[2]) |
| 427 | endfor |
| 428 | |
| 429 | for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime'] |
| 430 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 431 | call assert_equal(1, v:shell_error) |
| 432 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 433 | call assert_equal('Argument missing after: "' .. opt .. '"', out[1]) |
| 434 | call assert_equal('More info with: "vim -h"', out[2]) |
| 435 | endfor |
| 436 | |
| 437 | if has('clientserver') |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 438 | for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr', |
| 439 | \ '--remote-tab', '--remote-tab-wait', |
| 440 | \ '--remote-tab-wait-silent', '--remote-tab-silent', |
| 441 | \ '--remote-wait', '--remote-wait-silent', |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 442 | \ '--servername', |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 443 | \ ] |
| 444 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\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: "' .. opt .. '"', out[1]) |
| 448 | call assert_equal('More info with: "vim -h"', out[2]) |
| 449 | endfor |
| 450 | endif |
| 451 | |
Bram Moolenaar | 240f7ab | 2019-05-08 17:58:15 +0200 | [diff] [blame] | 452 | if has('gui_gtk') |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 453 | let out = split(system(GetVimCommand() .. ' --display'), "\n") |
| 454 | call assert_equal(1, v:shell_error) |
| 455 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 456 | call assert_equal('Argument missing after: "--display"', out[1]) |
| 457 | call assert_equal('More info with: "vim -h"', out[2]) |
| 458 | endif |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 459 | |
Bram Moolenaar | 5416b75 | 2019-05-08 18:36:43 +0200 | [diff] [blame] | 460 | if has('xterm_clipboard') |
Bram Moolenaar | 240f7ab | 2019-05-08 17:58:15 +0200 | [diff] [blame] | 461 | let out = split(system(GetVimCommand() .. ' -display'), "\n") |
| 462 | call assert_equal(1, v:shell_error) |
| 463 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 464 | call assert_equal('Argument missing after: "-display"', out[1]) |
| 465 | call assert_equal('More info with: "vim -h"', out[2]) |
| 466 | endif |
| 467 | |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 468 | let out = split(system(GetVimCommand() .. ' -ix'), "\n") |
| 469 | call assert_equal(1, v:shell_error) |
| 470 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 471 | call assert_equal('Garbage after option argument: "-ix"', out[1]) |
| 472 | call assert_equal('More info with: "vim -h"', out[2]) |
| 473 | |
| 474 | let out = split(system(GetVimCommand() .. ' - xxx'), "\n") |
| 475 | call assert_equal(1, v:shell_error) |
| 476 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 477 | call assert_equal('Too many edit arguments: "xxx"', out[1]) |
| 478 | call assert_equal('More info with: "vim -h"', out[2]) |
| 479 | |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 480 | if has('quickfix') |
| 481 | " Detect invalid repeated arguments '-t foo -t foo", '-q foo -q foo'. |
| 482 | for opt in ['-t', '-q'] |
| 483 | let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n") |
| 484 | call assert_equal(1, v:shell_error) |
| 485 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 486 | call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1]) |
| 487 | call assert_equal('More info with: "vim -h"', out[2]) |
| 488 | endfor |
| 489 | endif |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 490 | |
| 491 | for opt in [' -cq', ' --cmd q', ' +', ' -S foo'] |
| 492 | let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n") |
| 493 | call assert_equal(1, v:shell_error) |
| 494 | " FIXME: The error message given by Vim is not ideal in case of repeated |
| 495 | " -S foo since it does not mention -S. |
| 496 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 497 | call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1]) |
| 498 | call assert_equal('More info with: "vim -h"', out[2]) |
| 499 | endfor |
| 500 | |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 501 | if has('gui_gtk') |
| 502 | for opt in ['--socketid x', '--socketid 0xg'] |
| 503 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 504 | call assert_equal(1, v:shell_error) |
| 505 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 506 | call assert_equal('Invalid argument for: "--socketid"', out[1]) |
| 507 | call assert_equal('More info with: "vim -h"', out[2]) |
| 508 | endfor |
| 509 | endif |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 510 | endfunc |
| 511 | |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 512 | func Test_file_args() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 513 | let after =<< trim [CODE] |
| 514 | call writefile(argv(), "Xtestout") |
| 515 | qall |
| 516 | [CODE] |
| 517 | |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 518 | if RunVim([], after, '') |
| 519 | let lines = readfile('Xtestout') |
| 520 | call assert_equal(0, len(lines)) |
| 521 | endif |
| 522 | |
| 523 | if RunVim([], after, 'one') |
| 524 | let lines = readfile('Xtestout') |
| 525 | call assert_equal(1, len(lines)) |
| 526 | call assert_equal('one', lines[0]) |
| 527 | endif |
| 528 | |
| 529 | if RunVim([], after, 'one two three') |
| 530 | let lines = readfile('Xtestout') |
| 531 | call assert_equal(3, len(lines)) |
| 532 | call assert_equal('one', lines[0]) |
| 533 | call assert_equal('two', lines[1]) |
| 534 | call assert_equal('three', lines[2]) |
| 535 | endif |
| 536 | |
| 537 | if RunVim([], after, 'one -c echo two') |
| 538 | let lines = readfile('Xtestout') |
| 539 | call assert_equal(2, len(lines)) |
| 540 | call assert_equal('one', lines[0]) |
| 541 | call assert_equal('two', lines[1]) |
| 542 | endif |
| 543 | |
| 544 | if RunVim([], after, 'one -- -c echo two') |
| 545 | let lines = readfile('Xtestout') |
| 546 | call assert_equal(4, len(lines)) |
| 547 | call assert_equal('one', lines[0]) |
| 548 | call assert_equal('-c', lines[1]) |
| 549 | call assert_equal('echo', lines[2]) |
| 550 | call assert_equal('two', lines[3]) |
| 551 | endif |
| 552 | |
| 553 | call delete('Xtestout') |
| 554 | endfunc |
| 555 | |
| 556 | func Test_startuptime() |
| 557 | if !has('startuptime') |
| 558 | return |
| 559 | endif |
| 560 | let after = ['qall'] |
| 561 | if RunVim([], after, '--startuptime Xtestout one') |
| 562 | let lines = readfile('Xtestout') |
| 563 | let expected = ['--- VIM STARTING ---', 'parsing arguments', |
| 564 | \ 'shell init', 'inits 3', 'start termcap', 'opening buffers'] |
| 565 | let found = [] |
| 566 | for line in lines |
| 567 | for exp in expected |
| 568 | if line =~ exp |
| 569 | call add(found, exp) |
| 570 | endif |
| 571 | endfor |
| 572 | endfor |
| 573 | call assert_equal(expected, found) |
| 574 | endif |
| 575 | call delete('Xtestout') |
| 576 | endfunc |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 577 | |
| 578 | func Test_read_stdin() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 579 | let after =<< trim [CODE] |
| 580 | write Xtestout |
| 581 | quit! |
| 582 | [CODE] |
| 583 | |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 584 | if RunVimPiped([], after, '-', 'echo something | ') |
| 585 | let lines = readfile('Xtestout') |
Bram Moolenaar | e4a76ad | 2016-08-07 16:50:10 +0200 | [diff] [blame] | 586 | " MS-Windows adds a space after the word |
| 587 | call assert_equal(['something'], split(lines[0])) |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 588 | endif |
| 589 | call delete('Xtestout') |
| 590 | endfunc |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 591 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 592 | func Test_set_shell() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 593 | let after =<< trim [CODE] |
| 594 | call writefile([&shell], "Xtestout") |
| 595 | quit! |
| 596 | [CODE] |
| 597 | |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 598 | if has('win32') |
| 599 | let $SHELL = 'C:\with space\cmd.exe' |
| 600 | let expected = '"C:\with space\cmd.exe"' |
| 601 | else |
| 602 | let $SHELL = '/bin/with space/sh' |
| 603 | let expected = '/bin/with\ space/sh' |
| 604 | endif |
| 605 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 606 | if RunVimPiped([], after, '', '') |
| 607 | let lines = readfile('Xtestout') |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 608 | call assert_equal(expected, lines[0]) |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 609 | endif |
| 610 | call delete('Xtestout') |
| 611 | endfunc |
| 612 | |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 613 | func Test_progpath() |
| 614 | " Tests normally run with "./vim" or "../vim", these must have been expanded |
| 615 | " to a full path. |
| 616 | if has('unix') |
| 617 | call assert_equal('/', v:progpath[0]) |
| 618 | elseif has('win32') |
| 619 | call assert_equal(':', v:progpath[1]) |
| 620 | call assert_match('[/\\]', v:progpath[2]) |
| 621 | endif |
| 622 | |
| 623 | " Only expect "vim" to appear in v:progname. |
| 624 | call assert_match('vim\c', v:progname) |
| 625 | endfunc |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 626 | |
| 627 | func Test_silent_ex_mode() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 628 | " must be able to get the output of Vim. |
| 629 | CheckUnix |
| 630 | CheckNotGui |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 631 | |
| 632 | " This caused an ml_get error. |
| 633 | let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq') |
| 634 | call assert_notmatch('E315:', out) |
| 635 | endfunc |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 636 | |
| 637 | func Test_default_term() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 638 | " must be able to get the output of Vim. |
| 639 | CheckUnix |
| 640 | CheckNotGui |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 641 | |
| 642 | let save_term = $TERM |
Bram Moolenaar | 08f88b1 | 2017-04-02 17:21:16 +0200 | [diff] [blame] | 643 | let $TERM = 'unknownxxx' |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 644 | let out = system(GetVimCommand() . ' -c''set term'' -c cq') |
| 645 | call assert_match("defaulting to 'ansi'", out) |
| 646 | let $TERM = save_term |
| 647 | endfunc |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 648 | |
| 649 | func Test_zzz_startinsert() |
| 650 | " Test :startinsert |
| 651 | call writefile(['123456'], 'Xtestout') |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 652 | let after =<< trim [CODE] |
| 653 | :startinsert |
| 654 | call feedkeys("foobar\<c-o>:wq\<cr>","t") |
| 655 | [CODE] |
| 656 | |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 657 | if RunVim([], after, 'Xtestout') |
| 658 | let lines = readfile('Xtestout') |
| 659 | call assert_equal(['foobar123456'], lines) |
| 660 | endif |
| 661 | " Test :startinsert! |
| 662 | call writefile(['123456'], 'Xtestout') |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 663 | let after =<< trim [CODE] |
| 664 | :startinsert! |
| 665 | call feedkeys("foobar\<c-o>:wq\<cr>","t") |
| 666 | [CODE] |
| 667 | |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 668 | if RunVim([], after, 'Xtestout') |
| 669 | let lines = readfile('Xtestout') |
| 670 | call assert_equal(['123456foobar'], lines) |
| 671 | endif |
| 672 | call delete('Xtestout') |
| 673 | endfunc |
Bram Moolenaar | 97c2c05 | 2019-02-22 13:42:07 +0100 | [diff] [blame] | 674 | |
| 675 | func Test_issue_3969() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 676 | " Can't catch the output of gvim. |
| 677 | CheckNotGui |
| 678 | |
Bram Moolenaar | 97c2c05 | 2019-02-22 13:42:07 +0100 | [diff] [blame] | 679 | " Check that message is not truncated. |
| 680 | let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq') |
| 681 | call assert_equal('hello', out) |
| 682 | endfunc |
Bram Moolenaar | c75e812 | 2019-04-21 15:55:10 +0200 | [diff] [blame] | 683 | |
| 684 | func Test_start_with_tabs() |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 685 | CheckRunVimInTerminal |
Bram Moolenaar | c75e812 | 2019-04-21 15:55:10 +0200 | [diff] [blame] | 686 | |
| 687 | let buf = RunVimInTerminal('-p a b c', {}) |
| 688 | call VerifyScreenDump(buf, 'Test_start_with_tabs', {}) |
| 689 | |
| 690 | " clean up |
| 691 | call StopVimInTerminal(buf) |
| 692 | endfunc |
Bram Moolenaar | 69bf634 | 2019-10-29 04:16:57 +0100 | [diff] [blame] | 693 | |
| 694 | func Test_v_argv() |
| 695 | " Can't catch the output of gvim. |
| 696 | CheckNotGui |
| 697 | |
| 698 | let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q') |
| 699 | let list = out->split("', '") |
| 700 | call assert_match('vim', list[0]) |
| 701 | let idx = index(list, 'arg1') |
| 702 | call assert_true(idx > 2) |
| 703 | call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:]) |
| 704 | endfunc |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 705 | |
| 706 | " Test for the "-r" recovery mode option |
| 707 | func Test_r_arg() |
| 708 | " Can't catch the output of gvim. |
| 709 | CheckNotGui |
| 710 | CheckUnix |
| 711 | CheckEnglish |
| 712 | let cmd = GetVimCommand() |
| 713 | " There can be swap files anywhere, only check for the headers. |
| 714 | let expected =<< trim END |
| 715 | Swap files found:.* |
| 716 | In current directory:.* |
| 717 | In directory \~/tmp:.* |
| 718 | In directory /var/tmp:.* |
| 719 | In directory /tmp:.* |
| 720 | END |
| 721 | call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', '')) |
| 722 | endfunc |
| 723 | |
| 724 | " Test for the '-t' option to jump to a tag |
| 725 | func Test_t_arg() |
| 726 | let before =<< trim [CODE] |
| 727 | set tags=Xtags |
| 728 | [CODE] |
| 729 | let after =<< trim [CODE] |
| 730 | let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.') |
| 731 | call writefile([s], "Xtestout") |
| 732 | qall |
| 733 | [CODE] |
| 734 | |
| 735 | call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", |
| 736 | \ "first\tXfile1\t/^ \\zsfirst$/", |
| 737 | \ "second\tXfile1\t/^ \\zssecond$/", |
| 738 | \ "third\tXfile1\t/^ \\zsthird$/"], |
| 739 | \ 'Xtags') |
| 740 | call writefile([' first', ' second', ' third'], 'Xfile1') |
| 741 | |
| 742 | if RunVim(before, after, '-t second') |
| 743 | call assert_equal(['Xfile1:L2C5'], readfile('Xtestout')) |
| 744 | call delete('Xtestout') |
| 745 | endif |
| 746 | |
| 747 | call delete('Xtags') |
| 748 | call delete('Xfile1') |
| 749 | endfunc |
| 750 | |
| 751 | " Test for entering the insert mode on startup |
| 752 | func Test_start_insertmode() |
| 753 | let before =<< trim [CODE] |
| 754 | set insertmode |
| 755 | [CODE] |
| 756 | let after =<< trim [CODE] |
| 757 | call writefile(['insertmode=' .. &insertmode], 'Xtestout') |
| 758 | qall |
| 759 | [CODE] |
| 760 | if RunVim(before, after, '') |
| 761 | call assert_equal(['insertmode=1'], readfile('Xtestout')) |
| 762 | call delete('Xtestout') |
| 763 | endif |
| 764 | endfunc |
| 765 | |
| 766 | " Test for enabling the binary mode on startup |
| 767 | func Test_b_arg() |
| 768 | let after =<< trim [CODE] |
| 769 | call writefile(['binary=' .. &binary], 'Xtestout') |
| 770 | qall |
| 771 | [CODE] |
| 772 | if RunVim([], after, '-b') |
| 773 | call assert_equal(['binary=1'], readfile('Xtestout')) |
| 774 | call delete('Xtestout') |
| 775 | endif |
| 776 | endfunc |
| 777 | |
| 778 | " Test for enabling the lisp mode on startup |
| 779 | func Test_l_arg() |
| 780 | let after =<< trim [CODE] |
| 781 | let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch |
| 782 | call writefile([s], 'Xtestout') |
| 783 | qall |
| 784 | [CODE] |
| 785 | if RunVim([], after, '-l') |
| 786 | call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout')) |
| 787 | call delete('Xtestout') |
| 788 | endif |
| 789 | endfunc |
| 790 | |
| 791 | " Test for specifying a non-existing vimrc file using "-u" |
| 792 | func Test_missing_vimrc() |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 793 | CheckRunVimInTerminal |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 794 | let after =<< trim [CODE] |
| 795 | call assert_match('^E282:', v:errmsg) |
| 796 | call writefile(v:errors, 'Xtestout') |
| 797 | [CODE] |
| 798 | call writefile(after, 'Xafter') |
| 799 | |
| 800 | let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter' |
| 801 | let buf = term_start(cmd, {'term_rows' : 10}) |
| 802 | call WaitForAssert({-> assert_equal("running", term_getstatus(buf))}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 803 | call TermWait(buf) |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 804 | call term_sendkeys(buf, "\n:") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 805 | call TermWait(buf) |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 806 | call WaitForAssert({-> assert_match(':', term_getline(buf, 10))}) |
| 807 | call StopVimInTerminal(buf) |
| 808 | call assert_equal([], readfile('Xtestout')) |
| 809 | call delete('Xafter') |
| 810 | call delete('Xtestout') |
| 811 | endfunc |
| 812 | |
| 813 | " Test for using the $VIMINIT environment variable |
| 814 | func Test_VIMINIT() |
| 815 | let after =<< trim [CODE] |
| 816 | call assert_equal(1, exists('viminit_found')) |
| 817 | call assert_equal('yes', viminit_found) |
| 818 | call writefile(v:errors, 'Xtestout') |
| 819 | qall |
| 820 | [CODE] |
| 821 | call writefile(after, 'Xafter') |
| 822 | let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' |
| 823 | call setenv('VIMINIT', 'let viminit_found="yes"') |
| 824 | exe "silent !" . cmd |
| 825 | call assert_equal([], readfile('Xtestout')) |
| 826 | call delete('Xtestout') |
| 827 | call delete('Xafter') |
| 828 | endfunc |
| 829 | |
| 830 | " Test for using the $EXINIT environment variable |
| 831 | func Test_EXINIT() |
| 832 | let after =<< trim [CODE] |
| 833 | call assert_equal(1, exists('exinit_found')) |
| 834 | call assert_equal('yes', exinit_found) |
| 835 | call writefile(v:errors, 'Xtestout') |
| 836 | qall |
| 837 | [CODE] |
| 838 | call writefile(after, 'Xafter') |
| 839 | let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' |
| 840 | call setenv('EXINIT', 'let exinit_found="yes"') |
| 841 | exe "silent !" . cmd |
| 842 | call assert_equal([], readfile('Xtestout')) |
| 843 | call delete('Xtestout') |
| 844 | call delete('Xafter') |
| 845 | endfunc |
| 846 | |
| 847 | " Test for using the 'exrc' option |
| 848 | func Test_exrc() |
| 849 | let after =<< trim [CODE] |
| 850 | call assert_equal(1, &exrc) |
| 851 | call assert_equal(1, &secure) |
| 852 | call assert_equal(37, exrc_found) |
| 853 | call writefile(v:errors, 'Xtestout') |
| 854 | qall |
| 855 | [CODE] |
| 856 | call mkdir('Xdir') |
| 857 | call writefile(['let exrc_found=37'], 'Xdir/.exrc') |
| 858 | call writefile(after, 'Xdir/Xafter') |
| 859 | let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xdir" --cmd "set enc=utf8 exrc secure"' |
| 860 | exe "silent !" . cmd |
| 861 | call assert_equal([], readfile('Xdir/Xtestout')) |
| 862 | call delete('Xdir', 'rf') |
| 863 | endfunc |
| 864 | |
| 865 | " Test for starting Vim with a non-terminal as input/output |
| 866 | func Test_io_not_a_terminal() |
| 867 | " Can't catch the output of gvim. |
| 868 | CheckNotGui |
| 869 | CheckUnix |
| 870 | CheckEnglish |
| 871 | let l = systemlist(GetVimProg() .. ' --ttyfail') |
| 872 | call assert_equal(['Vim: Warning: Output is not to a terminal', |
| 873 | \ 'Vim: Warning: Input is not from a terminal'], l) |
| 874 | endfunc |
| 875 | |
| 876 | " Test for the "-w scriptout" argument |
| 877 | func Test_w_arg() |
| 878 | " Can't catch the output of gvim. |
| 879 | CheckNotGui |
| 880 | call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'b') |
| 881 | if RunVim([], [], '-s Xscriptin -w Xscriptout') |
| 882 | call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout')) |
| 883 | call delete('Xscriptout') |
| 884 | endif |
| 885 | call delete('Xscriptin') |
| 886 | |
| 887 | " Test for failing to open the script output file. This test works only when |
| 888 | " the language is English. |
| 889 | if v:lang == "C" || v:lang =~ '^[Ee]n' |
| 890 | call mkdir("Xdir") |
| 891 | let m = system(GetVimCommand() .. " -w Xdir") |
| 892 | call assert_equal("Cannot open for script output: \"Xdir\"\n", m) |
| 893 | call delete("Xdir", 'rf') |
| 894 | endif |
| 895 | endfunc |
| 896 | |
| 897 | " Test for the "-s scriptin" argument |
| 898 | func Test_s_arg() |
| 899 | " Can't catch the output of gvim. |
| 900 | CheckNotGui |
| 901 | CheckEnglish |
| 902 | " Test for failing to open the script input file. |
| 903 | let m = system(GetVimCommand() .. " -s abcxyz") |
| 904 | call assert_equal("Cannot open for reading: \"abcxyz\"\n", m) |
| 905 | |
| 906 | call writefile([], 'Xinput') |
| 907 | let m = system(GetVimCommand() .. " -s Xinput -s Xinput") |
| 908 | call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m) |
| 909 | call delete('Xinput') |
| 910 | endfunc |
| 911 | |
| 912 | " Test for the "-n" (no swap file) argument |
| 913 | func Test_n_arg() |
| 914 | let after =<< trim [CODE] |
| 915 | call assert_equal(0, &updatecount) |
| 916 | call writefile(v:errors, 'Xtestout') |
| 917 | qall |
| 918 | [CODE] |
| 919 | if RunVim([], after, '-n') |
| 920 | call assert_equal([], readfile('Xtestout')) |
| 921 | call delete('Xtestout') |
| 922 | endif |
| 923 | call delete('Xafter') |
| 924 | endfunc |
| 925 | |
| 926 | " Test for the "-h" (help) argument |
| 927 | func Test_h_arg() |
| 928 | " Can't catch the output of gvim. |
| 929 | CheckNotGui |
| 930 | let l = systemlist(GetVimProg() .. ' -h') |
| 931 | call assert_match('^VIM - Vi IMproved', l[0]) |
| 932 | let l = systemlist(GetVimProg() .. ' -?') |
| 933 | call assert_match('^VIM - Vi IMproved', l[0]) |
| 934 | endfunc |
| 935 | |
| 936 | " Test for the "-F" (farsi) argument |
| 937 | func Test_F_arg() |
| 938 | " Can't catch the output of gvim. |
| 939 | CheckNotGui |
| 940 | let l = systemlist(GetVimProg() .. ' -F') |
| 941 | call assert_match('^E27:', l[0]) |
| 942 | endfunc |
| 943 | |
| 944 | " Test for the "-E" (improved Ex mode) argument |
| 945 | func Test_E_arg() |
| 946 | let after =<< trim [CODE] |
| 947 | call assert_equal('cv', mode(1)) |
| 948 | call writefile(v:errors, 'Xtestout') |
| 949 | qall |
| 950 | [CODE] |
| 951 | if RunVim([], after, '-E') |
| 952 | call assert_equal([], readfile('Xtestout')) |
| 953 | call delete('Xtestout') |
| 954 | endif |
| 955 | call delete('Xafter') |
| 956 | endfunc |
| 957 | |
| 958 | " Test for too many edit argument errors |
| 959 | func Test_too_many_edit_args() |
| 960 | " Can't catch the output of gvim. |
| 961 | CheckNotGui |
| 962 | CheckEnglish |
| 963 | let l = systemlist(GetVimProg() .. ' - -') |
| 964 | call assert_match('^Too many edit arguments: "-"', l[1]) |
| 965 | endfunc |
| 966 | |
| 967 | " vim: shiftwidth=2 sts=2 expandtab |