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