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 | f8c52e8 | 2021-03-17 12:27:23 +0100 | [diff] [blame] | 112 | " This does not work with a GUI-only binary, such as on MS-Windows. |
| 113 | CheckAnyOf Unix NotGui |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 114 | |
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 | |
Christian Brabandt | 1d3a14e | 2021-05-29 19:53:50 +0200 | [diff] [blame] | 279 | " Test that an error is shown when the defaults.vim file could not be read |
Bram Moolenaar | a83d060 | 2021-06-02 16:49:32 +0200 | [diff] [blame] | 280 | func Test_defaults_error() |
| 281 | " Can't catch the output of gvim. |
| 282 | CheckNotGui |
| 283 | CheckNotMSWindows |
| 284 | " For unknown reasons freeing all memory does not work here, even though |
| 285 | " EXITFREE is defined. |
| 286 | CheckNotAsan |
| 287 | |
| 288 | let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' --clean -cq') |
| 289 | call assert_match("E1187: Failed to source defaults.vim", out) |
| 290 | |
| 291 | let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' -u DEFAULTS -cq') |
| 292 | call assert_match("E1187: Failed to source defaults.vim", out) |
| 293 | endfunc |
Christian Brabandt | 1d3a14e | 2021-05-29 19:53:50 +0200 | [diff] [blame] | 294 | |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 295 | " Test the '-q [errorfile]' argument. |
| 296 | func Test_q_arg() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 297 | CheckFeature quickfix |
| 298 | |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 299 | let lines =<< trim END |
| 300 | /* some file with an error */ |
| 301 | main() { |
| 302 | functionCall(arg; arg, arg); |
| 303 | return 666 |
| 304 | } |
| 305 | END |
| 306 | call writefile(lines, 'Xbadfile.c') |
| 307 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 308 | let after =<< trim [CODE] |
| 309 | call writefile([&errorfile, string(getpos("."))], "Xtestout") |
| 310 | copen |
| 311 | w >> Xtestout |
| 312 | qall |
| 313 | [CODE] |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 314 | |
| 315 | " Test with default argument '-q'. |
| 316 | call assert_equal('errors.err', &errorfile) |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 317 | call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'errors.err') |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 318 | if RunVim([], after, '-q') |
| 319 | let lines = readfile('Xtestout') |
| 320 | call assert_equal(['errors.err', |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 321 | \ '[0, 4, 12, 0]', |
| 322 | \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"], |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 323 | \ lines) |
| 324 | endif |
| 325 | call delete('Xtestout') |
| 326 | call delete('errors.err') |
| 327 | |
| 328 | " Test with explicit argument '-q Xerrors' (with space). |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 329 | call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'Xerrors') |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 330 | if RunVim([], after, '-q Xerrors') |
| 331 | let lines = readfile('Xtestout') |
| 332 | call assert_equal(['Xerrors', |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 333 | \ '[0, 4, 12, 0]', |
| 334 | \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"], |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 335 | \ lines) |
| 336 | endif |
| 337 | call delete('Xtestout') |
| 338 | |
| 339 | " Test with explicit argument '-qXerrors' (without space). |
| 340 | if RunVim([], after, '-qXerrors') |
| 341 | let lines = readfile('Xtestout') |
| 342 | call assert_equal(['Xerrors', |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 343 | \ '[0, 4, 12, 0]', |
| 344 | \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"], |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 345 | \ lines) |
| 346 | endif |
| 347 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 348 | " Test with a non-existing error file (exits with value 3) |
| 349 | let out = system(GetVimCommand() .. ' -q xyz.err') |
| 350 | call assert_equal(3, v:shell_error) |
| 351 | |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 352 | call delete('Xbadfile.c') |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 353 | call delete('Xtestout') |
| 354 | call delete('Xerrors') |
| 355 | endfunc |
| 356 | |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 357 | " Test the -V[N]{filename} argument to set the 'verbose' option to N |
| 358 | " and set 'verbosefile' to filename. |
| 359 | func Test_V_file_arg() |
Bram Moolenaar | 4841a7c | 2018-09-22 14:08:49 +0200 | [diff] [blame] | 360 | if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq') |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 361 | let out = join(readfile('Xverbosefile'), "\n") |
| 362 | call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out) |
| 363 | call assert_match("\n verbose=2\n", out) |
| 364 | call assert_match("\n verbosefile=Xverbosefile", out) |
| 365 | endif |
| 366 | |
| 367 | call delete('Xverbosefile') |
| 368 | endfunc |
| 369 | |
| 370 | " Test the -m, -M and -R arguments: |
| 371 | " -m resets 'write' |
| 372 | " -M resets 'modifiable' and 'write' |
| 373 | " -R sets 'readonly' |
| 374 | func Test_m_M_R() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 375 | let after =<< trim [CODE] |
| 376 | call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout") |
| 377 | qall |
| 378 | [CODE] |
| 379 | |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 380 | if RunVim([], after, '') |
| 381 | let lines = readfile('Xtestout') |
| 382 | call assert_equal(['1', '1', '0', '200'], lines) |
| 383 | endif |
| 384 | if RunVim([], after, '-m') |
| 385 | let lines = readfile('Xtestout') |
| 386 | call assert_equal(['0', '1', '0', '200'], lines) |
| 387 | endif |
| 388 | if RunVim([], after, '-M') |
| 389 | let lines = readfile('Xtestout') |
| 390 | call assert_equal(['0', '0', '0', '200'], lines) |
| 391 | endif |
| 392 | if RunVim([], after, '-R') |
| 393 | let lines = readfile('Xtestout') |
| 394 | call assert_equal(['1', '1', '1', '10000'], lines) |
| 395 | endif |
| 396 | |
| 397 | call delete('Xtestout') |
| 398 | endfunc |
| 399 | |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 400 | " Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes). |
| 401 | func Test_A_F_H_arg() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 402 | let after =<< trim [CODE] |
| 403 | call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout") |
| 404 | qall |
| 405 | [CODE] |
| 406 | |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 407 | " Use silent Ex mode to avoid the hit-Enter prompt for the warning that |
| 408 | " 'encoding' is not utf-8. |
| 409 | if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A') |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 410 | let lines = readfile('Xtestout') |
| 411 | call assert_equal(['1', '1', '0', '0'], lines) |
| 412 | endif |
| 413 | |
| 414 | if has('farsi') && RunVim([], after, '-F') |
| 415 | let lines = readfile('Xtestout') |
| 416 | call assert_equal(['1', '0', '1', '0'], lines) |
| 417 | endif |
| 418 | |
| 419 | if has('rightleft') && RunVim([], after, '-H') |
| 420 | let lines = readfile('Xtestout') |
| 421 | call assert_equal(['1', '0', '0', '1'], lines) |
| 422 | endif |
| 423 | |
| 424 | call delete('Xtestout') |
| 425 | endfunc |
| 426 | |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 427 | " Test the --echo-wid argument (for GTK GUI only). |
| 428 | func Test_echo_wid() |
| 429 | CheckCanRunGui |
| 430 | CheckFeature gui_gtk |
| 431 | |
| 432 | if RunVim([], [], '-g --echo-wid -cq >Xtest_echo_wid') |
| 433 | let lines = readfile('Xtest_echo_wid') |
| 434 | call assert_equal(1, len(lines)) |
| 435 | call assert_match('^WID: \d\+$', lines[0]) |
| 436 | endif |
| 437 | |
| 438 | call delete('Xtest_echo_wid') |
| 439 | endfunction |
| 440 | |
| 441 | " Test the -reverse and +reverse arguments (for GUI only). |
| 442 | func Test_reverse() |
| 443 | CheckCanRunGui |
Bram Moolenaar | f8c52e8 | 2021-03-17 12:27:23 +0100 | [diff] [blame] | 444 | CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 445 | |
| 446 | let after =<< trim [CODE] |
| 447 | call writefile([&background], "Xtest_reverse") |
| 448 | qall |
| 449 | [CODE] |
| 450 | if RunVim([], after, '-f -g -reverse') |
| 451 | let lines = readfile('Xtest_reverse') |
| 452 | call assert_equal(['dark'], lines) |
| 453 | endif |
| 454 | if RunVim([], after, '-f -g +reverse') |
| 455 | let lines = readfile('Xtest_reverse') |
| 456 | call assert_equal(['light'], lines) |
| 457 | endif |
| 458 | |
| 459 | call delete('Xtest_reverse') |
| 460 | endfunc |
| 461 | |
| 462 | " Test the -background and -foreground arguments (for GUI only). |
| 463 | func Test_background_foreground() |
| 464 | CheckCanRunGui |
Bram Moolenaar | f8c52e8 | 2021-03-17 12:27:23 +0100 | [diff] [blame] | 465 | CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 466 | |
| 467 | " Is there a better way to check the effect of -background & -foreground |
| 468 | " other than merely looking at &background (dark or light)? |
| 469 | let after =<< trim [CODE] |
| 470 | call writefile([&background], "Xtest_fg_bg") |
| 471 | qall |
| 472 | [CODE] |
| 473 | if RunVim([], after, '-f -g -background darkred -foreground yellow') |
| 474 | let lines = readfile('Xtest_fg_bg') |
| 475 | call assert_equal(['dark'], lines) |
| 476 | endif |
| 477 | if RunVim([], after, '-f -g -background ivory -foreground darkgreen') |
| 478 | let lines = readfile('Xtest_fg_bg') |
| 479 | call assert_equal(['light'], lines) |
| 480 | endif |
| 481 | |
| 482 | call delete('Xtest_fg_bg') |
| 483 | endfunc |
| 484 | |
| 485 | " Test the -font argument (for GUI only). |
| 486 | func Test_font() |
| 487 | CheckCanRunGui |
| 488 | CheckNotMSWindows |
| 489 | |
| 490 | if has('gui_gtk') |
| 491 | let font = 'Courier 14' |
| 492 | elseif has('gui_motif') || has('gui_athena') |
| 493 | let font = '-misc-fixed-bold-*' |
| 494 | else |
| 495 | throw 'Skipped: test does not set a valid font for this GUI' |
| 496 | endif |
| 497 | |
| 498 | let after =<< trim [CODE] |
| 499 | call writefile([&guifont], "Xtest_font") |
| 500 | qall |
| 501 | [CODE] |
| 502 | |
| 503 | if RunVim([], after, '--nofork -g -font "' .. font .. '"') |
| 504 | let lines = readfile('Xtest_font') |
| 505 | call assert_equal([font], lines) |
| 506 | endif |
| 507 | |
| 508 | call delete('Xtest_font') |
| 509 | endfunc |
| 510 | |
| 511 | " Test the -geometry argument (for GUI only). |
| 512 | func Test_geometry() |
| 513 | CheckCanRunGui |
Bram Moolenaar | f8c52e8 | 2021-03-17 12:27:23 +0100 | [diff] [blame] | 514 | CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 515 | |
| 516 | if has('gui_motif') || has('gui_athena') |
| 517 | " FIXME: With GUI Athena or Motif, the value of getwinposx(), |
| 518 | " getwinposy() and getwinpos() do not match exactly the |
| 519 | " value given in -geometry. Why? |
| 520 | " So only check &columns and &lines for those GUIs. |
| 521 | let after =<< trim [CODE] |
| 522 | call writefile([&columns, &lines], "Xtest_geometry") |
| 523 | qall |
| 524 | [CODE] |
| 525 | if RunVim([], after, '-f -g -geometry 31x13+41+43') |
| 526 | let lines = readfile('Xtest_geometry') |
| 527 | call assert_equal(['31', '13'], lines) |
| 528 | endif |
| 529 | else |
| 530 | let after =<< trim [CODE] |
| 531 | call writefile([&columns, &lines, getwinposx(), getwinposy(), string(getwinpos())], "Xtest_geometry") |
| 532 | qall |
| 533 | [CODE] |
| 534 | if RunVim([], after, '-f -g -geometry 31x13+41+43') |
| 535 | let lines = readfile('Xtest_geometry') |
| 536 | call assert_equal(['31', '13', '41', '43', '[41, 43]'], lines) |
| 537 | endif |
| 538 | endif |
| 539 | |
| 540 | call delete('Xtest_geometry') |
| 541 | endfunc |
| 542 | |
| 543 | " Test the -iconic argument (for GUI only). |
| 544 | func Test_iconic() |
| 545 | CheckCanRunGui |
Bram Moolenaar | f8c52e8 | 2021-03-17 12:27:23 +0100 | [diff] [blame] | 546 | CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 547 | |
| 548 | call RunVim([], [], '-f -g -iconic -cq') |
| 549 | |
| 550 | " TODO: currently only start vim iconified, but does not |
| 551 | " check that vim is iconified. How could this be checked? |
| 552 | endfunc |
| 553 | |
| 554 | |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 555 | func Test_invalid_args() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 556 | " must be able to get the output of Vim. |
| 557 | CheckUnix |
| 558 | CheckNotGui |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 559 | |
| 560 | for opt in ['-Y', '--does-not-exist'] |
| 561 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 562 | call assert_equal(1, v:shell_error) |
| 563 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 564 | call assert_equal('Unknown option argument: "' .. opt .. '"', out[1]) |
| 565 | call assert_equal('More info with: "vim -h"', out[2]) |
| 566 | endfor |
| 567 | |
| 568 | for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime'] |
| 569 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 570 | call assert_equal(1, v:shell_error) |
| 571 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 572 | call assert_equal('Argument missing after: "' .. opt .. '"', out[1]) |
| 573 | call assert_equal('More info with: "vim -h"', out[2]) |
| 574 | endfor |
| 575 | |
| 576 | if has('clientserver') |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 577 | for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr', |
| 578 | \ '--remote-tab', '--remote-tab-wait', |
| 579 | \ '--remote-tab-wait-silent', '--remote-tab-silent', |
| 580 | \ '--remote-wait', '--remote-wait-silent', |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 581 | \ '--servername', |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 582 | \ ] |
| 583 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 584 | call assert_equal(1, v:shell_error) |
| 585 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 586 | call assert_equal('Argument missing after: "' .. opt .. '"', out[1]) |
| 587 | call assert_equal('More info with: "vim -h"', out[2]) |
| 588 | endfor |
| 589 | endif |
| 590 | |
Bram Moolenaar | 240f7ab | 2019-05-08 17:58:15 +0200 | [diff] [blame] | 591 | if has('gui_gtk') |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 592 | let out = split(system(GetVimCommand() .. ' --display'), "\n") |
| 593 | call assert_equal(1, v:shell_error) |
| 594 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 595 | call assert_equal('Argument missing after: "--display"', out[1]) |
| 596 | call assert_equal('More info with: "vim -h"', out[2]) |
| 597 | endif |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 598 | |
Bram Moolenaar | 5416b75 | 2019-05-08 18:36:43 +0200 | [diff] [blame] | 599 | if has('xterm_clipboard') |
Bram Moolenaar | 240f7ab | 2019-05-08 17:58:15 +0200 | [diff] [blame] | 600 | let out = split(system(GetVimCommand() .. ' -display'), "\n") |
| 601 | call assert_equal(1, v:shell_error) |
| 602 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 603 | call assert_equal('Argument missing after: "-display"', out[1]) |
| 604 | call assert_equal('More info with: "vim -h"', out[2]) |
| 605 | endif |
| 606 | |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 607 | let out = split(system(GetVimCommand() .. ' -ix'), "\n") |
| 608 | call assert_equal(1, v:shell_error) |
| 609 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 610 | call assert_equal('Garbage after option argument: "-ix"', out[1]) |
| 611 | call assert_equal('More info with: "vim -h"', out[2]) |
| 612 | |
| 613 | let out = split(system(GetVimCommand() .. ' - xxx'), "\n") |
| 614 | call assert_equal(1, v:shell_error) |
| 615 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 616 | call assert_equal('Too many edit arguments: "xxx"', out[1]) |
| 617 | call assert_equal('More info with: "vim -h"', out[2]) |
| 618 | |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 619 | if has('quickfix') |
| 620 | " Detect invalid repeated arguments '-t foo -t foo", '-q foo -q foo'. |
| 621 | for opt in ['-t', '-q'] |
| 622 | let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n") |
| 623 | call assert_equal(1, v:shell_error) |
| 624 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 625 | call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1]) |
| 626 | call assert_equal('More info with: "vim -h"', out[2]) |
| 627 | endfor |
| 628 | endif |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 629 | |
| 630 | for opt in [' -cq', ' --cmd q', ' +', ' -S foo'] |
| 631 | let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n") |
| 632 | call assert_equal(1, v:shell_error) |
| 633 | " FIXME: The error message given by Vim is not ideal in case of repeated |
| 634 | " -S foo since it does not mention -S. |
| 635 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 636 | call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1]) |
| 637 | call assert_equal('More info with: "vim -h"', out[2]) |
| 638 | endfor |
| 639 | |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 640 | if has('gui_gtk') |
Dominique Pelle | 6d37e8e | 2021-05-06 17:36:55 +0200 | [diff] [blame] | 641 | let out = split(system(GetVimCommand() .. ' --socketid'), "\n") |
| 642 | call assert_equal(1, v:shell_error) |
| 643 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 644 | call assert_equal('Argument missing after: "--socketid"', out[1]) |
| 645 | call assert_equal('More info with: "vim -h"', out[2]) |
| 646 | |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 647 | for opt in ['--socketid x', '--socketid 0xg'] |
| 648 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 649 | call assert_equal(1, v:shell_error) |
| 650 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 651 | call assert_equal('Invalid argument for: "--socketid"', out[1]) |
| 652 | call assert_equal('More info with: "vim -h"', out[2]) |
| 653 | endfor |
Dominique Pelle | 6d37e8e | 2021-05-06 17:36:55 +0200 | [diff] [blame] | 654 | |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 655 | endif |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 656 | endfunc |
| 657 | |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 658 | func Test_file_args() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 659 | let after =<< trim [CODE] |
| 660 | call writefile(argv(), "Xtestout") |
| 661 | qall |
| 662 | [CODE] |
| 663 | |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 664 | if RunVim([], after, '') |
| 665 | let lines = readfile('Xtestout') |
| 666 | call assert_equal(0, len(lines)) |
| 667 | endif |
| 668 | |
| 669 | if RunVim([], after, 'one') |
| 670 | let lines = readfile('Xtestout') |
| 671 | call assert_equal(1, len(lines)) |
| 672 | call assert_equal('one', lines[0]) |
| 673 | endif |
| 674 | |
| 675 | if RunVim([], after, 'one two three') |
| 676 | let lines = readfile('Xtestout') |
| 677 | call assert_equal(3, len(lines)) |
| 678 | call assert_equal('one', lines[0]) |
| 679 | call assert_equal('two', lines[1]) |
| 680 | call assert_equal('three', lines[2]) |
| 681 | endif |
| 682 | |
| 683 | if RunVim([], after, 'one -c echo two') |
| 684 | let lines = readfile('Xtestout') |
| 685 | call assert_equal(2, len(lines)) |
| 686 | call assert_equal('one', lines[0]) |
| 687 | call assert_equal('two', lines[1]) |
| 688 | endif |
| 689 | |
| 690 | if RunVim([], after, 'one -- -c echo two') |
| 691 | let lines = readfile('Xtestout') |
| 692 | call assert_equal(4, len(lines)) |
| 693 | call assert_equal('one', lines[0]) |
| 694 | call assert_equal('-c', lines[1]) |
| 695 | call assert_equal('echo', lines[2]) |
| 696 | call assert_equal('two', lines[3]) |
| 697 | endif |
| 698 | |
| 699 | call delete('Xtestout') |
| 700 | endfunc |
| 701 | |
| 702 | func Test_startuptime() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 703 | CheckFeature startuptime |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 704 | let after = ['qall'] |
| 705 | if RunVim([], after, '--startuptime Xtestout one') |
| 706 | let lines = readfile('Xtestout') |
| 707 | let expected = ['--- VIM STARTING ---', 'parsing arguments', |
| 708 | \ 'shell init', 'inits 3', 'start termcap', 'opening buffers'] |
| 709 | let found = [] |
| 710 | for line in lines |
| 711 | for exp in expected |
| 712 | if line =~ exp |
| 713 | call add(found, exp) |
| 714 | endif |
| 715 | endfor |
| 716 | endfor |
| 717 | call assert_equal(expected, found) |
| 718 | endif |
| 719 | call delete('Xtestout') |
| 720 | endfunc |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 721 | |
| 722 | func Test_read_stdin() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 723 | let after =<< trim [CODE] |
| 724 | write Xtestout |
| 725 | quit! |
| 726 | [CODE] |
| 727 | |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 728 | if RunVimPiped([], after, '-', 'echo something | ') |
| 729 | let lines = readfile('Xtestout') |
Bram Moolenaar | e4a76ad | 2016-08-07 16:50:10 +0200 | [diff] [blame] | 730 | " MS-Windows adds a space after the word |
| 731 | call assert_equal(['something'], split(lines[0])) |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 732 | endif |
| 733 | call delete('Xtestout') |
| 734 | endfunc |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 735 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 736 | func Test_set_shell() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 737 | let after =<< trim [CODE] |
| 738 | call writefile([&shell], "Xtestout") |
| 739 | quit! |
| 740 | [CODE] |
| 741 | |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 742 | if has('win32') |
| 743 | let $SHELL = 'C:\with space\cmd.exe' |
| 744 | let expected = '"C:\with space\cmd.exe"' |
| 745 | else |
| 746 | let $SHELL = '/bin/with space/sh' |
| 747 | let expected = '/bin/with\ space/sh' |
| 748 | endif |
| 749 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 750 | if RunVimPiped([], after, '', '') |
| 751 | let lines = readfile('Xtestout') |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 752 | call assert_equal(expected, lines[0]) |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 753 | endif |
| 754 | call delete('Xtestout') |
| 755 | endfunc |
| 756 | |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 757 | func Test_progpath() |
| 758 | " Tests normally run with "./vim" or "../vim", these must have been expanded |
| 759 | " to a full path. |
| 760 | if has('unix') |
| 761 | call assert_equal('/', v:progpath[0]) |
| 762 | elseif has('win32') |
| 763 | call assert_equal(':', v:progpath[1]) |
| 764 | call assert_match('[/\\]', v:progpath[2]) |
| 765 | endif |
| 766 | |
| 767 | " Only expect "vim" to appear in v:progname. |
| 768 | call assert_match('vim\c', v:progname) |
| 769 | endfunc |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 770 | |
| 771 | func Test_silent_ex_mode() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 772 | " must be able to get the output of Vim. |
| 773 | CheckUnix |
| 774 | CheckNotGui |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 775 | |
| 776 | " This caused an ml_get error. |
| 777 | let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq') |
| 778 | call assert_notmatch('E315:', out) |
| 779 | endfunc |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 780 | |
| 781 | func Test_default_term() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 782 | " must be able to get the output of Vim. |
| 783 | CheckUnix |
| 784 | CheckNotGui |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 785 | |
| 786 | let save_term = $TERM |
Bram Moolenaar | 08f88b1 | 2017-04-02 17:21:16 +0200 | [diff] [blame] | 787 | let $TERM = 'unknownxxx' |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 788 | let out = system(GetVimCommand() . ' -c''set term'' -c cq') |
| 789 | call assert_match("defaulting to 'ansi'", out) |
| 790 | let $TERM = save_term |
| 791 | endfunc |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 792 | |
| 793 | func Test_zzz_startinsert() |
| 794 | " Test :startinsert |
| 795 | call writefile(['123456'], 'Xtestout') |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 796 | let after =<< trim [CODE] |
| 797 | :startinsert |
| 798 | call feedkeys("foobar\<c-o>:wq\<cr>","t") |
| 799 | [CODE] |
| 800 | |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 801 | if RunVim([], after, 'Xtestout') |
| 802 | let lines = readfile('Xtestout') |
| 803 | call assert_equal(['foobar123456'], lines) |
| 804 | endif |
| 805 | " Test :startinsert! |
| 806 | call writefile(['123456'], 'Xtestout') |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 807 | let after =<< trim [CODE] |
| 808 | :startinsert! |
| 809 | call feedkeys("foobar\<c-o>:wq\<cr>","t") |
| 810 | [CODE] |
| 811 | |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 812 | if RunVim([], after, 'Xtestout') |
| 813 | let lines = readfile('Xtestout') |
| 814 | call assert_equal(['123456foobar'], lines) |
| 815 | endif |
| 816 | call delete('Xtestout') |
| 817 | endfunc |
Bram Moolenaar | 97c2c05 | 2019-02-22 13:42:07 +0100 | [diff] [blame] | 818 | |
| 819 | func Test_issue_3969() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 820 | " Can't catch the output of gvim. |
| 821 | CheckNotGui |
| 822 | |
Bram Moolenaar | 97c2c05 | 2019-02-22 13:42:07 +0100 | [diff] [blame] | 823 | " Check that message is not truncated. |
| 824 | let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq') |
| 825 | call assert_equal('hello', out) |
| 826 | endfunc |
Bram Moolenaar | c75e812 | 2019-04-21 15:55:10 +0200 | [diff] [blame] | 827 | |
| 828 | func Test_start_with_tabs() |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 829 | CheckRunVimInTerminal |
Bram Moolenaar | c75e812 | 2019-04-21 15:55:10 +0200 | [diff] [blame] | 830 | |
| 831 | let buf = RunVimInTerminal('-p a b c', {}) |
| 832 | call VerifyScreenDump(buf, 'Test_start_with_tabs', {}) |
| 833 | |
| 834 | " clean up |
| 835 | call StopVimInTerminal(buf) |
| 836 | endfunc |
Bram Moolenaar | 69bf634 | 2019-10-29 04:16:57 +0100 | [diff] [blame] | 837 | |
| 838 | func Test_v_argv() |
| 839 | " Can't catch the output of gvim. |
| 840 | CheckNotGui |
| 841 | |
| 842 | let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q') |
| 843 | let list = out->split("', '") |
| 844 | call assert_match('vim', list[0]) |
| 845 | let idx = index(list, 'arg1') |
| 846 | call assert_true(idx > 2) |
| 847 | call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:]) |
| 848 | endfunc |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 849 | |
| 850 | " Test for the "-r" recovery mode option |
| 851 | func Test_r_arg() |
| 852 | " Can't catch the output of gvim. |
| 853 | CheckNotGui |
| 854 | CheckUnix |
| 855 | CheckEnglish |
| 856 | let cmd = GetVimCommand() |
| 857 | " There can be swap files anywhere, only check for the headers. |
| 858 | let expected =<< trim END |
| 859 | Swap files found:.* |
| 860 | In current directory:.* |
| 861 | In directory \~/tmp:.* |
| 862 | In directory /var/tmp:.* |
| 863 | In directory /tmp:.* |
| 864 | END |
| 865 | call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', '')) |
| 866 | endfunc |
| 867 | |
| 868 | " Test for the '-t' option to jump to a tag |
| 869 | func Test_t_arg() |
| 870 | let before =<< trim [CODE] |
| 871 | set tags=Xtags |
| 872 | [CODE] |
| 873 | let after =<< trim [CODE] |
| 874 | let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.') |
| 875 | call writefile([s], "Xtestout") |
| 876 | qall |
| 877 | [CODE] |
| 878 | |
| 879 | call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", |
| 880 | \ "first\tXfile1\t/^ \\zsfirst$/", |
| 881 | \ "second\tXfile1\t/^ \\zssecond$/", |
| 882 | \ "third\tXfile1\t/^ \\zsthird$/"], |
| 883 | \ 'Xtags') |
| 884 | call writefile([' first', ' second', ' third'], 'Xfile1') |
| 885 | |
Bram Moolenaar | a2b3e7d | 2021-03-26 17:24:34 +0100 | [diff] [blame] | 886 | for t_arg in ['-t second', '-tsecond'] |
| 887 | if RunVim(before, after, '-t second') |
| 888 | call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'), t_arg) |
| 889 | call delete('Xtestout') |
| 890 | endif |
| 891 | endfor |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 892 | |
| 893 | call delete('Xtags') |
| 894 | call delete('Xfile1') |
| 895 | endfunc |
| 896 | |
Bram Moolenaar | 1f33e0a | 2020-12-19 13:32:07 +0100 | [diff] [blame] | 897 | " Test the '-T' argument which sets the 'term' option. |
| 898 | func Test_T_arg() |
| 899 | CheckNotGui |
| 900 | let after =<< trim [CODE] |
| 901 | call writefile([&term], "Xtest_T_arg") |
| 902 | qall |
| 903 | [CODE] |
| 904 | |
| 905 | for t in ['builtin_dumb', 'builtin_ansi'] |
| 906 | if RunVim([], after, '-T ' .. t) |
| 907 | let lines = readfile('Xtest_T_arg') |
| 908 | call assert_equal([t], lines) |
| 909 | endif |
| 910 | endfor |
| 911 | |
| 912 | call delete('Xtest_T_arg') |
| 913 | endfunc |
| 914 | |
| 915 | " Test the '-x' argument to read/write encrypted files. |
| 916 | func Test_x_arg() |
| 917 | CheckRunVimInTerminal |
| 918 | CheckFeature cryptv |
| 919 | |
| 920 | " Create an encrypted file Xtest_x_arg. |
| 921 | let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0}) |
| 922 | call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))}) |
| 923 | call term_sendkeys(buf, "foo\n") |
| 924 | call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))}) |
| 925 | call term_sendkeys(buf, "foo\n") |
| 926 | call WaitForAssert({-> assert_match(' All$', term_getline(buf, 10))}) |
| 927 | call term_sendkeys(buf, "itest\<Esc>:w\<Enter>") |
| 928 | call WaitForAssert({-> assert_match('"Xtest_x_arg" \[New\]\[blowfish2\] 1L, 5B written', |
| 929 | \ term_getline(buf, 10))}) |
| 930 | call StopVimInTerminal(buf) |
| 931 | |
| 932 | " Read the encrypted file and check that it contains the expected content "test" |
| 933 | let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0}) |
| 934 | call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))}) |
| 935 | call term_sendkeys(buf, "foo\n") |
| 936 | call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))}) |
| 937 | call term_sendkeys(buf, "foo\n") |
| 938 | call WaitForAssert({-> assert_match('^test', term_getline(buf, 1))}) |
| 939 | call StopVimInTerminal(buf) |
| 940 | |
| 941 | call delete('Xtest_x_arg') |
| 942 | endfunc |
| 943 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 944 | " Test for entering the insert mode on startup |
| 945 | func Test_start_insertmode() |
| 946 | let before =<< trim [CODE] |
| 947 | set insertmode |
| 948 | [CODE] |
| 949 | let after =<< trim [CODE] |
| 950 | call writefile(['insertmode=' .. &insertmode], 'Xtestout') |
| 951 | qall |
| 952 | [CODE] |
| 953 | if RunVim(before, after, '') |
| 954 | call assert_equal(['insertmode=1'], readfile('Xtestout')) |
| 955 | call delete('Xtestout') |
| 956 | endif |
| 957 | endfunc |
| 958 | |
| 959 | " Test for enabling the binary mode on startup |
| 960 | func Test_b_arg() |
| 961 | let after =<< trim [CODE] |
| 962 | call writefile(['binary=' .. &binary], 'Xtestout') |
| 963 | qall |
| 964 | [CODE] |
| 965 | if RunVim([], after, '-b') |
| 966 | call assert_equal(['binary=1'], readfile('Xtestout')) |
| 967 | call delete('Xtestout') |
| 968 | endif |
| 969 | endfunc |
| 970 | |
| 971 | " Test for enabling the lisp mode on startup |
| 972 | func Test_l_arg() |
| 973 | let after =<< trim [CODE] |
| 974 | let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch |
| 975 | call writefile([s], 'Xtestout') |
| 976 | qall |
| 977 | [CODE] |
| 978 | if RunVim([], after, '-l') |
| 979 | call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout')) |
| 980 | call delete('Xtestout') |
| 981 | endif |
| 982 | endfunc |
| 983 | |
| 984 | " Test for specifying a non-existing vimrc file using "-u" |
| 985 | func Test_missing_vimrc() |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 986 | CheckRunVimInTerminal |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 987 | let after =<< trim [CODE] |
| 988 | call assert_match('^E282:', v:errmsg) |
| 989 | call writefile(v:errors, 'Xtestout') |
| 990 | [CODE] |
| 991 | call writefile(after, 'Xafter') |
| 992 | |
| 993 | let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter' |
| 994 | let buf = term_start(cmd, {'term_rows' : 10}) |
| 995 | call WaitForAssert({-> assert_equal("running", term_getstatus(buf))}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 996 | call TermWait(buf) |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 997 | call term_sendkeys(buf, "\n:") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 998 | call TermWait(buf) |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 999 | call WaitForAssert({-> assert_match(':', term_getline(buf, 10))}) |
| 1000 | call StopVimInTerminal(buf) |
| 1001 | call assert_equal([], readfile('Xtestout')) |
| 1002 | call delete('Xafter') |
| 1003 | call delete('Xtestout') |
| 1004 | endfunc |
| 1005 | |
| 1006 | " Test for using the $VIMINIT environment variable |
| 1007 | func Test_VIMINIT() |
| 1008 | let after =<< trim [CODE] |
| 1009 | call assert_equal(1, exists('viminit_found')) |
| 1010 | call assert_equal('yes', viminit_found) |
| 1011 | call writefile(v:errors, 'Xtestout') |
| 1012 | qall |
| 1013 | [CODE] |
| 1014 | call writefile(after, 'Xafter') |
| 1015 | let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' |
| 1016 | call setenv('VIMINIT', 'let viminit_found="yes"') |
| 1017 | exe "silent !" . cmd |
| 1018 | call assert_equal([], readfile('Xtestout')) |
| 1019 | call delete('Xtestout') |
| 1020 | call delete('Xafter') |
| 1021 | endfunc |
| 1022 | |
| 1023 | " Test for using the $EXINIT environment variable |
| 1024 | func Test_EXINIT() |
| 1025 | let after =<< trim [CODE] |
| 1026 | call assert_equal(1, exists('exinit_found')) |
| 1027 | call assert_equal('yes', exinit_found) |
| 1028 | call writefile(v:errors, 'Xtestout') |
| 1029 | qall |
| 1030 | [CODE] |
| 1031 | call writefile(after, 'Xafter') |
| 1032 | let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' |
| 1033 | call setenv('EXINIT', 'let exinit_found="yes"') |
| 1034 | exe "silent !" . cmd |
| 1035 | call assert_equal([], readfile('Xtestout')) |
| 1036 | call delete('Xtestout') |
| 1037 | call delete('Xafter') |
| 1038 | endfunc |
| 1039 | |
| 1040 | " Test for using the 'exrc' option |
| 1041 | func Test_exrc() |
| 1042 | let after =<< trim [CODE] |
| 1043 | call assert_equal(1, &exrc) |
| 1044 | call assert_equal(1, &secure) |
| 1045 | call assert_equal(37, exrc_found) |
| 1046 | call writefile(v:errors, 'Xtestout') |
| 1047 | qall |
| 1048 | [CODE] |
| 1049 | call mkdir('Xdir') |
| 1050 | call writefile(['let exrc_found=37'], 'Xdir/.exrc') |
| 1051 | call writefile(after, 'Xdir/Xafter') |
| 1052 | let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xdir" --cmd "set enc=utf8 exrc secure"' |
| 1053 | exe "silent !" . cmd |
| 1054 | call assert_equal([], readfile('Xdir/Xtestout')) |
| 1055 | call delete('Xdir', 'rf') |
| 1056 | endfunc |
| 1057 | |
| 1058 | " Test for starting Vim with a non-terminal as input/output |
| 1059 | func Test_io_not_a_terminal() |
| 1060 | " Can't catch the output of gvim. |
| 1061 | CheckNotGui |
| 1062 | CheckUnix |
| 1063 | CheckEnglish |
| 1064 | let l = systemlist(GetVimProg() .. ' --ttyfail') |
| 1065 | call assert_equal(['Vim: Warning: Output is not to a terminal', |
| 1066 | \ 'Vim: Warning: Input is not from a terminal'], l) |
| 1067 | endfunc |
| 1068 | |
Bram Moolenaar | 7007e31 | 2021-03-27 12:11:33 +0100 | [diff] [blame] | 1069 | " Test for --not-a-term avoiding escape codes. |
| 1070 | func Test_not_a_term() |
| 1071 | CheckUnix |
| 1072 | CheckNotGui |
| 1073 | |
| 1074 | if &shellredir =~ '%s' |
| 1075 | let redir = printf(&shellredir, 'Xvimout') |
| 1076 | else |
| 1077 | let redir = &shellredir .. ' Xvimout' |
| 1078 | endif |
| 1079 | |
| 1080 | " Without --not-a-term there are a few escape sequences. |
| 1081 | " This will take 2 seconds because of the missing --not-a-term |
| 1082 | let cmd = GetVimProg() .. ' --cmd quit ' .. redir |
| 1083 | exe "silent !" . cmd |
| 1084 | call assert_match("\<Esc>", readfile('Xvimout')->join()) |
| 1085 | call delete('Xvimout') |
| 1086 | |
| 1087 | " With --not-a-term there are no escape sequences. |
| 1088 | let cmd = GetVimProg() .. ' --not-a-term --cmd quit ' .. redir |
| 1089 | exe "silent !" . cmd |
| 1090 | call assert_notmatch("\<Esc>", readfile('Xvimout')->join()) |
| 1091 | call delete('Xvimout') |
| 1092 | endfunc |
| 1093 | |
| 1094 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1095 | " Test for the "-w scriptout" argument |
| 1096 | func Test_w_arg() |
| 1097 | " Can't catch the output of gvim. |
| 1098 | CheckNotGui |
Bram Moolenaar | 0a1a6a1 | 2021-03-26 14:14:18 +0100 | [diff] [blame] | 1099 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1100 | call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'b') |
| 1101 | if RunVim([], [], '-s Xscriptin -w Xscriptout') |
| 1102 | call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout')) |
| 1103 | call delete('Xscriptout') |
| 1104 | endif |
| 1105 | call delete('Xscriptin') |
| 1106 | |
| 1107 | " Test for failing to open the script output file. This test works only when |
| 1108 | " the language is English. |
| 1109 | if v:lang == "C" || v:lang =~ '^[Ee]n' |
| 1110 | call mkdir("Xdir") |
| 1111 | let m = system(GetVimCommand() .. " -w Xdir") |
| 1112 | call assert_equal("Cannot open for script output: \"Xdir\"\n", m) |
| 1113 | call delete("Xdir", 'rf') |
| 1114 | endif |
Bram Moolenaar | 0a1a6a1 | 2021-03-26 14:14:18 +0100 | [diff] [blame] | 1115 | |
| 1116 | " A number argument sets the 'window' option |
| 1117 | call writefile(["iwindow \<C-R>=&window\<CR>\<Esc>:wq! Xresult\<CR>"], 'Xscriptin', 'b') |
Bram Moolenaar | a2b3e7d | 2021-03-26 17:24:34 +0100 | [diff] [blame] | 1118 | for w_arg in ['-w 17', '-w17'] |
| 1119 | if RunVim([], [], '-s Xscriptin ' .. w_arg) |
| 1120 | call assert_equal(["window 17"], readfile('Xresult'), w_arg) |
| 1121 | call delete('Xresult') |
| 1122 | endif |
| 1123 | endfor |
Bram Moolenaar | 0a1a6a1 | 2021-03-26 14:14:18 +0100 | [diff] [blame] | 1124 | call delete('Xscriptin') |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1125 | endfunc |
| 1126 | |
| 1127 | " Test for the "-s scriptin" argument |
| 1128 | func Test_s_arg() |
| 1129 | " Can't catch the output of gvim. |
| 1130 | CheckNotGui |
| 1131 | CheckEnglish |
| 1132 | " Test for failing to open the script input file. |
| 1133 | let m = system(GetVimCommand() .. " -s abcxyz") |
| 1134 | call assert_equal("Cannot open for reading: \"abcxyz\"\n", m) |
| 1135 | |
| 1136 | call writefile([], 'Xinput') |
| 1137 | let m = system(GetVimCommand() .. " -s Xinput -s Xinput") |
| 1138 | call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m) |
| 1139 | call delete('Xinput') |
| 1140 | endfunc |
| 1141 | |
| 1142 | " Test for the "-n" (no swap file) argument |
| 1143 | func Test_n_arg() |
| 1144 | let after =<< trim [CODE] |
| 1145 | call assert_equal(0, &updatecount) |
| 1146 | call writefile(v:errors, 'Xtestout') |
| 1147 | qall |
| 1148 | [CODE] |
| 1149 | if RunVim([], after, '-n') |
| 1150 | call assert_equal([], readfile('Xtestout')) |
| 1151 | call delete('Xtestout') |
| 1152 | endif |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1153 | endfunc |
| 1154 | |
| 1155 | " Test for the "-h" (help) argument |
| 1156 | func Test_h_arg() |
| 1157 | " Can't catch the output of gvim. |
| 1158 | CheckNotGui |
| 1159 | let l = systemlist(GetVimProg() .. ' -h') |
| 1160 | call assert_match('^VIM - Vi IMproved', l[0]) |
| 1161 | let l = systemlist(GetVimProg() .. ' -?') |
| 1162 | call assert_match('^VIM - Vi IMproved', l[0]) |
| 1163 | endfunc |
| 1164 | |
| 1165 | " Test for the "-F" (farsi) argument |
| 1166 | func Test_F_arg() |
| 1167 | " Can't catch the output of gvim. |
| 1168 | CheckNotGui |
| 1169 | let l = systemlist(GetVimProg() .. ' -F') |
| 1170 | call assert_match('^E27:', l[0]) |
| 1171 | endfunc |
| 1172 | |
| 1173 | " Test for the "-E" (improved Ex mode) argument |
| 1174 | func Test_E_arg() |
| 1175 | let after =<< trim [CODE] |
| 1176 | call assert_equal('cv', mode(1)) |
| 1177 | call writefile(v:errors, 'Xtestout') |
| 1178 | qall |
| 1179 | [CODE] |
| 1180 | if RunVim([], after, '-E') |
| 1181 | call assert_equal([], readfile('Xtestout')) |
| 1182 | call delete('Xtestout') |
| 1183 | endif |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1184 | endfunc |
| 1185 | |
Bram Moolenaar | c5cf369 | 2021-03-20 22:16:56 +0100 | [diff] [blame] | 1186 | " Test for the "-D" (debugger) argument |
| 1187 | func Test_D_arg() |
| 1188 | CheckRunVimInTerminal |
| 1189 | |
| 1190 | let cmd = GetVimCommandCleanTerm() .. ' -D' |
| 1191 | let buf = term_start(cmd, {'term_rows' : 10}) |
| 1192 | call WaitForAssert({-> assert_equal("running", term_getstatus(buf))}) |
| 1193 | |
| 1194 | call WaitForAssert({-> assert_equal('Entering Debug mode. Type "cont" to continue.', |
| 1195 | \ term_getline(buf, 7))}) |
| 1196 | call WaitForAssert({-> assert_equal('>', term_getline(buf, 10))}) |
| 1197 | |
| 1198 | call StopVimInTerminal(buf) |
| 1199 | endfunc |
| 1200 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1201 | " Test for too many edit argument errors |
| 1202 | func Test_too_many_edit_args() |
| 1203 | " Can't catch the output of gvim. |
| 1204 | CheckNotGui |
| 1205 | CheckEnglish |
| 1206 | let l = systemlist(GetVimProg() .. ' - -') |
| 1207 | call assert_match('^Too many edit arguments: "-"', l[1]) |
| 1208 | endfunc |
| 1209 | |
Bram Moolenaar | df4c9af | 2021-01-11 19:54:42 +0100 | [diff] [blame] | 1210 | " Test starting vim with various names: vim, ex, view, evim, etc. |
| 1211 | func Test_progname() |
| 1212 | CheckUnix |
| 1213 | |
| 1214 | call mkdir('Xprogname', 'p') |
| 1215 | call writefile(['silent !date', |
| 1216 | \ 'call writefile([mode(1), ' |
| 1217 | \ .. '&insertmode, &diff, &readonly, &updatecount, ' |
| 1218 | \ .. 'join(split(execute("message"), "\n")[1:])], "Xprogname_out")', |
| 1219 | \ 'qall'], 'Xprogname_after') |
| 1220 | |
| 1221 | " +---------------------------------------------- progname |
| 1222 | " | +--------------------------------- mode(1) |
| 1223 | " | | +--------------------------- &insertmode |
| 1224 | " | | | +---------------------- &diff |
| 1225 | " | | | | +----------------- &readonly |
| 1226 | " | | | | | +-------- &updatecount |
| 1227 | " | | | | | | +--- :messages |
| 1228 | " | | | | | | | |
| 1229 | let expectations = { |
| 1230 | \ 'vim': ['n', '0', '0', '0', '200', ''], |
| 1231 | \ 'gvim': ['n', '0', '0', '0', '200', ''], |
| 1232 | \ 'ex': ['ce', '0', '0', '0', '200', ''], |
| 1233 | \ 'exim': ['cv', '0', '0', '0', '200', ''], |
| 1234 | \ 'view': ['n', '0', '0', '1', '10000', ''], |
| 1235 | \ 'gview': ['n', '0', '0', '1', '10000', ''], |
| 1236 | \ 'evim': ['n', '1', '0', '0', '200', ''], |
| 1237 | \ 'eview': ['n', '1', '0', '1', '10000', ''], |
| 1238 | \ 'rvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], |
| 1239 | \ 'rgvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], |
| 1240 | \ 'rview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], |
| 1241 | \ 'rgview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], |
| 1242 | \ 'vimdiff': ['n', '0', '1', '0', '200', ''], |
| 1243 | \ 'gvimdiff': ['n', '0', '1', '0', '200', '']} |
| 1244 | |
| 1245 | let prognames = ['vim', 'gvim', 'ex', 'exim', 'view', 'gview', |
| 1246 | \ 'evim', 'eview', 'rvim', 'rgvim', 'rview', 'rgview', |
| 1247 | \ 'vimdiff', 'gvimdiff'] |
| 1248 | |
| 1249 | for progname in prognames |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 1250 | let run_with_gui = (progname =~# 'g') || (has('gui') && (progname ==# 'evim' || progname ==# 'eview')) |
| 1251 | |
| 1252 | if empty($DISPLAY) && run_with_gui |
| 1253 | " Can't run gvim, gview (etc.) if $DISPLAY is not setup. |
| 1254 | continue |
Bram Moolenaar | df4c9af | 2021-01-11 19:54:42 +0100 | [diff] [blame] | 1255 | endif |
| 1256 | |
| 1257 | exe 'silent !ln -s -f ' ..exepath(GetVimProg()) .. ' Xprogname/' .. progname |
| 1258 | |
| 1259 | let stdout_stderr = '' |
| 1260 | if progname =~# 'g' |
| 1261 | let stdout_stderr = system('Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after') |
| 1262 | else |
| 1263 | exe 'sil !Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after' |
| 1264 | endif |
| 1265 | |
| 1266 | if progname =~# 'g' && !has('gui') |
| 1267 | call assert_equal("E25: GUI cannot be used: Not enabled at compile time\n", stdout_stderr, progname) |
| 1268 | else |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 1269 | " GUI motif can output some warnings like this: |
| 1270 | " Warning: |
| 1271 | " Name: subMenu |
| 1272 | " Class: XmCascadeButton |
| 1273 | " Illegal mnemonic character; Could not convert X KEYSYM to a keycode |
| 1274 | " So don't check that stderr is empty with GUI Motif. |
| 1275 | if run_with_gui && !has('gui_motif') |
| 1276 | call assert_equal('', stdout_stderr, progname) |
| 1277 | endif |
Bram Moolenaar | df4c9af | 2021-01-11 19:54:42 +0100 | [diff] [blame] | 1278 | call assert_equal(expectations[progname], readfile('Xprogname_out'), progname) |
| 1279 | endif |
| 1280 | |
| 1281 | call delete('Xprogname/' .. progname) |
| 1282 | call delete('Xprogname_out') |
| 1283 | endfor |
| 1284 | |
| 1285 | call delete('Xprogname_after') |
| 1286 | call delete('Xprogname', 'd') |
| 1287 | endfunc |
| 1288 | |
Yegappan Lakshmanan | 36f96a5 | 2021-05-13 18:33:16 +0200 | [diff] [blame] | 1289 | " Test for doing a write from .vimrc |
| 1290 | func Test_write_in_vimrc() |
| 1291 | call writefile(['silent! write'], 'Xvimrc') |
| 1292 | let after =<< trim [CODE] |
| 1293 | call assert_match('E32: ', v:errmsg) |
| 1294 | call writefile(v:errors, 'Xtestout') |
| 1295 | qall |
| 1296 | [CODE] |
| 1297 | if RunVim([], after, '-u Xvimrc') |
| 1298 | call assert_equal([], readfile('Xtestout')) |
| 1299 | call delete('Xtestout') |
| 1300 | endif |
| 1301 | call delete('Xvimrc') |
| 1302 | endfunc |
| 1303 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1304 | " vim: shiftwidth=2 sts=2 expandtab |