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 | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 444 | CheckAnyOf Feature:gui_gtk Feature:gui_motif |
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 | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 465 | CheckAnyOf Feature:gui_gtk Feature:gui_motif |
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' |
Bram Moolenaar | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 492 | elseif has('gui_motif') |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 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 | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 514 | CheckAnyOf Feature:gui_gtk Feature:gui_motif |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 515 | |
Bram Moolenaar | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 516 | if has('gui_motif') |
| 517 | " FIXME: With GUI Motif the value of getwinposx(), |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 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] |
Bram Moolenaar | fa04eae | 2022-06-21 14:38:40 +0100 | [diff] [blame] | 534 | " Some window managers have a bar at the top that pushes windows down, |
| 535 | " need to use at least 130, let's do 150 |
| 536 | if RunVim([], after, '-f -g -geometry 31x13+41+150') |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 537 | let lines = readfile('Xtest_geometry') |
Bram Moolenaar | b376aa2 | 2021-10-11 16:08:32 +0100 | [diff] [blame] | 538 | " Depending on the GUI library and the windowing system the final size |
| 539 | " might be a bit different, allow for some tolerance. Tuned based on |
| 540 | " actual failures. |
Bram Moolenaar | 3d031a0 | 2021-10-11 22:57:34 +0100 | [diff] [blame] | 541 | call assert_inrange(31, 35, str2nr(lines[0])) |
| 542 | call assert_equal('13', lines[1]) |
| 543 | call assert_equal('41', lines[2]) |
Bram Moolenaar | fa04eae | 2022-06-21 14:38:40 +0100 | [diff] [blame] | 544 | call assert_equal('150', lines[3]) |
| 545 | call assert_equal('[41, 150]', lines[4]) |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 546 | endif |
| 547 | endif |
| 548 | |
| 549 | call delete('Xtest_geometry') |
| 550 | endfunc |
| 551 | |
| 552 | " Test the -iconic argument (for GUI only). |
| 553 | func Test_iconic() |
| 554 | CheckCanRunGui |
Bram Moolenaar | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 555 | CheckAnyOf Feature:gui_gtk Feature:gui_motif |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 556 | |
| 557 | call RunVim([], [], '-f -g -iconic -cq') |
| 558 | |
| 559 | " TODO: currently only start vim iconified, but does not |
| 560 | " check that vim is iconified. How could this be checked? |
| 561 | endfunc |
| 562 | |
| 563 | |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 564 | func Test_invalid_args() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 565 | " must be able to get the output of Vim. |
| 566 | CheckUnix |
| 567 | CheckNotGui |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 568 | |
| 569 | for opt in ['-Y', '--does-not-exist'] |
| 570 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 571 | call assert_equal(1, v:shell_error) |
| 572 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 573 | call assert_equal('Unknown option argument: "' .. opt .. '"', out[1]) |
| 574 | call assert_equal('More info with: "vim -h"', out[2]) |
| 575 | endfor |
| 576 | |
| 577 | for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime'] |
| 578 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 579 | call assert_equal(1, v:shell_error) |
| 580 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 581 | call assert_equal('Argument missing after: "' .. opt .. '"', out[1]) |
| 582 | call assert_equal('More info with: "vim -h"', out[2]) |
| 583 | endfor |
| 584 | |
| 585 | if has('clientserver') |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 586 | for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr', |
| 587 | \ '--remote-tab', '--remote-tab-wait', |
| 588 | \ '--remote-tab-wait-silent', '--remote-tab-silent', |
| 589 | \ '--remote-wait', '--remote-wait-silent', |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 590 | \ '--servername', |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 591 | \ ] |
| 592 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\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: "' .. opt .. '"', out[1]) |
| 596 | call assert_equal('More info with: "vim -h"', out[2]) |
| 597 | endfor |
| 598 | endif |
| 599 | |
Bram Moolenaar | 240f7ab | 2019-05-08 17:58:15 +0200 | [diff] [blame] | 600 | if has('gui_gtk') |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 601 | let out = split(system(GetVimCommand() .. ' --display'), "\n") |
| 602 | call assert_equal(1, v:shell_error) |
| 603 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 604 | call assert_equal('Argument missing after: "--display"', out[1]) |
| 605 | call assert_equal('More info with: "vim -h"', out[2]) |
| 606 | endif |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 607 | |
Bram Moolenaar | 5416b75 | 2019-05-08 18:36:43 +0200 | [diff] [blame] | 608 | if has('xterm_clipboard') |
Bram Moolenaar | 240f7ab | 2019-05-08 17:58:15 +0200 | [diff] [blame] | 609 | let out = split(system(GetVimCommand() .. ' -display'), "\n") |
| 610 | call assert_equal(1, v:shell_error) |
| 611 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 612 | call assert_equal('Argument missing after: "-display"', out[1]) |
| 613 | call assert_equal('More info with: "vim -h"', out[2]) |
| 614 | endif |
| 615 | |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 616 | let out = split(system(GetVimCommand() .. ' -ix'), "\n") |
| 617 | call assert_equal(1, v:shell_error) |
| 618 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 619 | call assert_equal('Garbage after option argument: "-ix"', out[1]) |
| 620 | call assert_equal('More info with: "vim -h"', out[2]) |
| 621 | |
| 622 | let out = split(system(GetVimCommand() .. ' - xxx'), "\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: "xxx"', out[1]) |
| 626 | call assert_equal('More info with: "vim -h"', out[2]) |
| 627 | |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 628 | if has('quickfix') |
Dominique Pelle | d176ca3 | 2021-09-09 20:45:34 +0200 | [diff] [blame] | 629 | " Detect invalid repeated arguments '-t foo -t foo', '-q foo -q foo'. |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 630 | for opt in ['-t', '-q'] |
| 631 | let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n") |
| 632 | call assert_equal(1, v:shell_error) |
| 633 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 634 | call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1]) |
| 635 | call assert_equal('More info with: "vim -h"', out[2]) |
| 636 | endfor |
| 637 | endif |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 638 | |
| 639 | for opt in [' -cq', ' --cmd q', ' +', ' -S foo'] |
| 640 | let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n") |
| 641 | call assert_equal(1, v:shell_error) |
| 642 | " FIXME: The error message given by Vim is not ideal in case of repeated |
| 643 | " -S foo since it does not mention -S. |
| 644 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 645 | call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1]) |
| 646 | call assert_equal('More info with: "vim -h"', out[2]) |
| 647 | endfor |
| 648 | |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 649 | if has('gui_gtk') |
Dominique Pelle | 6d37e8e | 2021-05-06 17:36:55 +0200 | [diff] [blame] | 650 | let out = split(system(GetVimCommand() .. ' --socketid'), "\n") |
| 651 | call assert_equal(1, v:shell_error) |
| 652 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 653 | call assert_equal('Argument missing after: "--socketid"', out[1]) |
| 654 | call assert_equal('More info with: "vim -h"', out[2]) |
| 655 | |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 656 | for opt in ['--socketid x', '--socketid 0xg'] |
| 657 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 658 | call assert_equal(1, v:shell_error) |
| 659 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 660 | call assert_equal('Invalid argument for: "--socketid"', out[1]) |
| 661 | call assert_equal('More info with: "vim -h"', out[2]) |
| 662 | endfor |
Dominique Pelle | 6d37e8e | 2021-05-06 17:36:55 +0200 | [diff] [blame] | 663 | |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 664 | endif |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 665 | endfunc |
| 666 | |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 667 | func Test_file_args() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 668 | let after =<< trim [CODE] |
| 669 | call writefile(argv(), "Xtestout") |
| 670 | qall |
| 671 | [CODE] |
| 672 | |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 673 | if RunVim([], after, '') |
| 674 | let lines = readfile('Xtestout') |
| 675 | call assert_equal(0, len(lines)) |
| 676 | endif |
| 677 | |
| 678 | if RunVim([], after, 'one') |
| 679 | let lines = readfile('Xtestout') |
| 680 | call assert_equal(1, len(lines)) |
| 681 | call assert_equal('one', lines[0]) |
| 682 | endif |
| 683 | |
| 684 | if RunVim([], after, 'one two three') |
| 685 | let lines = readfile('Xtestout') |
| 686 | call assert_equal(3, len(lines)) |
| 687 | call assert_equal('one', lines[0]) |
| 688 | call assert_equal('two', lines[1]) |
| 689 | call assert_equal('three', lines[2]) |
| 690 | endif |
| 691 | |
| 692 | if RunVim([], after, 'one -c echo two') |
| 693 | let lines = readfile('Xtestout') |
| 694 | call assert_equal(2, len(lines)) |
| 695 | call assert_equal('one', lines[0]) |
| 696 | call assert_equal('two', lines[1]) |
| 697 | endif |
| 698 | |
| 699 | if RunVim([], after, 'one -- -c echo two') |
| 700 | let lines = readfile('Xtestout') |
| 701 | call assert_equal(4, len(lines)) |
| 702 | call assert_equal('one', lines[0]) |
| 703 | call assert_equal('-c', lines[1]) |
| 704 | call assert_equal('echo', lines[2]) |
| 705 | call assert_equal('two', lines[3]) |
| 706 | endif |
| 707 | |
| 708 | call delete('Xtestout') |
| 709 | endfunc |
| 710 | |
| 711 | func Test_startuptime() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 712 | CheckFeature startuptime |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 713 | let after = ['qall'] |
| 714 | if RunVim([], after, '--startuptime Xtestout one') |
| 715 | let lines = readfile('Xtestout') |
| 716 | let expected = ['--- VIM STARTING ---', 'parsing arguments', |
| 717 | \ 'shell init', 'inits 3', 'start termcap', 'opening buffers'] |
| 718 | let found = [] |
| 719 | for line in lines |
| 720 | for exp in expected |
| 721 | if line =~ exp |
| 722 | call add(found, exp) |
| 723 | endif |
| 724 | endfor |
| 725 | endfor |
| 726 | call assert_equal(expected, found) |
| 727 | endif |
| 728 | call delete('Xtestout') |
| 729 | endfunc |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 730 | |
Bram Moolenaar | c9a9a0a | 2022-04-12 15:09:23 +0100 | [diff] [blame] | 731 | func Test_log() |
| 732 | CheckFeature channel |
| 733 | |
| 734 | call assert_false(filereadable('Xlogfile')) |
| 735 | let after = ['qall'] |
| 736 | if RunVim([], after, '--log Xlogfile') |
| 737 | call assert_equal(1, readfile('Xlogfile') |
| 738 | \ ->filter({i, l -> l =~ '==== start log session'}) |
| 739 | \ ->len()) |
| 740 | " second time appends to the log |
| 741 | if RunVim([], after, '--log Xlogfile') |
| 742 | call assert_equal(2, readfile('Xlogfile') |
| 743 | \ ->filter({i, l -> l =~ '==== start log session'}) |
| 744 | \ ->len()) |
| 745 | endif |
| 746 | endif |
| 747 | call delete('Xlogfile') |
| 748 | endfunc |
| 749 | |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 750 | func Test_read_stdin() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 751 | let after =<< trim [CODE] |
| 752 | write Xtestout |
| 753 | quit! |
| 754 | [CODE] |
| 755 | |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 756 | if RunVimPiped([], after, '-', 'echo something | ') |
| 757 | let lines = readfile('Xtestout') |
Bram Moolenaar | e4a76ad | 2016-08-07 16:50:10 +0200 | [diff] [blame] | 758 | " MS-Windows adds a space after the word |
| 759 | call assert_equal(['something'], split(lines[0])) |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 760 | endif |
| 761 | call delete('Xtestout') |
| 762 | endfunc |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 763 | |
| 764 | func Test_progpath() |
| 765 | " Tests normally run with "./vim" or "../vim", these must have been expanded |
| 766 | " to a full path. |
| 767 | if has('unix') |
| 768 | call assert_equal('/', v:progpath[0]) |
| 769 | elseif has('win32') |
| 770 | call assert_equal(':', v:progpath[1]) |
| 771 | call assert_match('[/\\]', v:progpath[2]) |
| 772 | endif |
| 773 | |
| 774 | " Only expect "vim" to appear in v:progname. |
| 775 | call assert_match('vim\c', v:progname) |
| 776 | endfunc |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 777 | |
| 778 | func Test_silent_ex_mode() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 779 | " must be able to get the output of Vim. |
| 780 | CheckUnix |
| 781 | CheckNotGui |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 782 | |
| 783 | " This caused an ml_get error. |
| 784 | let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq') |
| 785 | call assert_notmatch('E315:', out) |
| 786 | endfunc |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 787 | |
| 788 | func Test_default_term() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 789 | " must be able to get the output of Vim. |
| 790 | CheckUnix |
| 791 | CheckNotGui |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 792 | |
| 793 | let save_term = $TERM |
Bram Moolenaar | 08f88b1 | 2017-04-02 17:21:16 +0200 | [diff] [blame] | 794 | let $TERM = 'unknownxxx' |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 795 | let out = system(GetVimCommand() . ' -c''set term'' -c cq') |
| 796 | call assert_match("defaulting to 'ansi'", out) |
| 797 | let $TERM = save_term |
| 798 | endfunc |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 799 | |
| 800 | func Test_zzz_startinsert() |
| 801 | " Test :startinsert |
| 802 | call writefile(['123456'], 'Xtestout') |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 803 | let after =<< trim [CODE] |
| 804 | :startinsert |
| 805 | call feedkeys("foobar\<c-o>:wq\<cr>","t") |
| 806 | [CODE] |
| 807 | |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 808 | if RunVim([], after, 'Xtestout') |
| 809 | let lines = readfile('Xtestout') |
| 810 | call assert_equal(['foobar123456'], lines) |
| 811 | endif |
| 812 | " Test :startinsert! |
| 813 | call writefile(['123456'], 'Xtestout') |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 814 | let after =<< trim [CODE] |
| 815 | :startinsert! |
| 816 | call feedkeys("foobar\<c-o>:wq\<cr>","t") |
| 817 | [CODE] |
| 818 | |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 819 | if RunVim([], after, 'Xtestout') |
| 820 | let lines = readfile('Xtestout') |
| 821 | call assert_equal(['123456foobar'], lines) |
| 822 | endif |
| 823 | call delete('Xtestout') |
| 824 | endfunc |
Bram Moolenaar | 97c2c05 | 2019-02-22 13:42:07 +0100 | [diff] [blame] | 825 | |
| 826 | func Test_issue_3969() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 827 | " Can't catch the output of gvim. |
| 828 | CheckNotGui |
| 829 | |
Bram Moolenaar | 97c2c05 | 2019-02-22 13:42:07 +0100 | [diff] [blame] | 830 | " Check that message is not truncated. |
| 831 | let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq') |
| 832 | call assert_equal('hello', out) |
| 833 | endfunc |
Bram Moolenaar | c75e812 | 2019-04-21 15:55:10 +0200 | [diff] [blame] | 834 | |
| 835 | func Test_start_with_tabs() |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 836 | CheckRunVimInTerminal |
Bram Moolenaar | c75e812 | 2019-04-21 15:55:10 +0200 | [diff] [blame] | 837 | |
| 838 | let buf = RunVimInTerminal('-p a b c', {}) |
| 839 | call VerifyScreenDump(buf, 'Test_start_with_tabs', {}) |
| 840 | |
| 841 | " clean up |
| 842 | call StopVimInTerminal(buf) |
| 843 | endfunc |
Bram Moolenaar | 69bf634 | 2019-10-29 04:16:57 +0100 | [diff] [blame] | 844 | |
Bram Moolenaar | d1f34e6 | 2022-01-07 19:24:20 +0000 | [diff] [blame] | 845 | func Test_start_in_minimal_window() |
| 846 | CheckRunVimInTerminal |
| 847 | |
| 848 | let buf = RunVimInTerminal('-c "set nomore"', {'cols': 12, 'rows': 2, 'keep_t_u7': 1}) |
| 849 | call term_sendkeys(buf, "ahello\<Esc>") |
| 850 | call WaitForAssert({-> assert_match('^hello', term_getline(buf, 1))}) |
| 851 | |
| 852 | " clean up |
| 853 | call StopVimInTerminal(buf) |
| 854 | endfunc |
| 855 | |
Bram Moolenaar | 69bf634 | 2019-10-29 04:16:57 +0100 | [diff] [blame] | 856 | func Test_v_argv() |
| 857 | " Can't catch the output of gvim. |
| 858 | CheckNotGui |
| 859 | |
| 860 | let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q') |
| 861 | let list = out->split("', '") |
| 862 | call assert_match('vim', list[0]) |
| 863 | let idx = index(list, 'arg1') |
| 864 | call assert_true(idx > 2) |
| 865 | call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:]) |
| 866 | endfunc |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 867 | |
| 868 | " Test for the "-r" recovery mode option |
| 869 | func Test_r_arg() |
| 870 | " Can't catch the output of gvim. |
| 871 | CheckNotGui |
| 872 | CheckUnix |
| 873 | CheckEnglish |
| 874 | let cmd = GetVimCommand() |
| 875 | " There can be swap files anywhere, only check for the headers. |
| 876 | let expected =<< trim END |
| 877 | Swap files found:.* |
| 878 | In current directory:.* |
| 879 | In directory \~/tmp:.* |
| 880 | In directory /var/tmp:.* |
| 881 | In directory /tmp:.* |
| 882 | END |
| 883 | call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', '')) |
| 884 | endfunc |
| 885 | |
| 886 | " Test for the '-t' option to jump to a tag |
| 887 | func Test_t_arg() |
| 888 | let before =<< trim [CODE] |
| 889 | set tags=Xtags |
| 890 | [CODE] |
| 891 | let after =<< trim [CODE] |
| 892 | let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.') |
| 893 | call writefile([s], "Xtestout") |
| 894 | qall |
| 895 | [CODE] |
| 896 | |
| 897 | call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", |
| 898 | \ "first\tXfile1\t/^ \\zsfirst$/", |
| 899 | \ "second\tXfile1\t/^ \\zssecond$/", |
| 900 | \ "third\tXfile1\t/^ \\zsthird$/"], |
| 901 | \ 'Xtags') |
| 902 | call writefile([' first', ' second', ' third'], 'Xfile1') |
| 903 | |
Bram Moolenaar | a2b3e7d | 2021-03-26 17:24:34 +0100 | [diff] [blame] | 904 | for t_arg in ['-t second', '-tsecond'] |
Dominique Pelle | d176ca3 | 2021-09-09 20:45:34 +0200 | [diff] [blame] | 905 | if RunVim(before, after, t_arg) |
Bram Moolenaar | a2b3e7d | 2021-03-26 17:24:34 +0100 | [diff] [blame] | 906 | call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'), t_arg) |
| 907 | call delete('Xtestout') |
| 908 | endif |
| 909 | endfor |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 910 | |
| 911 | call delete('Xtags') |
| 912 | call delete('Xfile1') |
| 913 | endfunc |
| 914 | |
Bram Moolenaar | 1f33e0a | 2020-12-19 13:32:07 +0100 | [diff] [blame] | 915 | " Test the '-T' argument which sets the 'term' option. |
| 916 | func Test_T_arg() |
| 917 | CheckNotGui |
| 918 | let after =<< trim [CODE] |
| 919 | call writefile([&term], "Xtest_T_arg") |
| 920 | qall |
| 921 | [CODE] |
| 922 | |
| 923 | for t in ['builtin_dumb', 'builtin_ansi'] |
| 924 | if RunVim([], after, '-T ' .. t) |
| 925 | let lines = readfile('Xtest_T_arg') |
| 926 | call assert_equal([t], lines) |
| 927 | endif |
| 928 | endfor |
| 929 | |
| 930 | call delete('Xtest_T_arg') |
| 931 | endfunc |
| 932 | |
| 933 | " Test the '-x' argument to read/write encrypted files. |
| 934 | func Test_x_arg() |
| 935 | CheckRunVimInTerminal |
| 936 | CheckFeature cryptv |
| 937 | |
| 938 | " Create an encrypted file Xtest_x_arg. |
| 939 | let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0}) |
| 940 | call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))}) |
| 941 | call term_sendkeys(buf, "foo\n") |
| 942 | call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))}) |
| 943 | call term_sendkeys(buf, "foo\n") |
| 944 | call WaitForAssert({-> assert_match(' All$', term_getline(buf, 10))}) |
| 945 | call term_sendkeys(buf, "itest\<Esc>:w\<Enter>") |
| 946 | call WaitForAssert({-> assert_match('"Xtest_x_arg" \[New\]\[blowfish2\] 1L, 5B written', |
| 947 | \ term_getline(buf, 10))}) |
| 948 | call StopVimInTerminal(buf) |
| 949 | |
| 950 | " Read the encrypted file and check that it contains the expected content "test" |
| 951 | let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0}) |
| 952 | call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))}) |
| 953 | call term_sendkeys(buf, "foo\n") |
| 954 | call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))}) |
| 955 | call term_sendkeys(buf, "foo\n") |
| 956 | call WaitForAssert({-> assert_match('^test', term_getline(buf, 1))}) |
| 957 | call StopVimInTerminal(buf) |
| 958 | |
| 959 | call delete('Xtest_x_arg') |
| 960 | endfunc |
| 961 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 962 | " Test for entering the insert mode on startup |
| 963 | func Test_start_insertmode() |
| 964 | let before =<< trim [CODE] |
| 965 | set insertmode |
| 966 | [CODE] |
| 967 | let after =<< trim [CODE] |
| 968 | call writefile(['insertmode=' .. &insertmode], 'Xtestout') |
| 969 | qall |
| 970 | [CODE] |
| 971 | if RunVim(before, after, '') |
| 972 | call assert_equal(['insertmode=1'], readfile('Xtestout')) |
| 973 | call delete('Xtestout') |
| 974 | endif |
| 975 | endfunc |
| 976 | |
| 977 | " Test for enabling the binary mode on startup |
| 978 | func Test_b_arg() |
| 979 | let after =<< trim [CODE] |
| 980 | call writefile(['binary=' .. &binary], 'Xtestout') |
| 981 | qall |
| 982 | [CODE] |
| 983 | if RunVim([], after, '-b') |
| 984 | call assert_equal(['binary=1'], readfile('Xtestout')) |
| 985 | call delete('Xtestout') |
| 986 | endif |
| 987 | endfunc |
| 988 | |
| 989 | " Test for enabling the lisp mode on startup |
| 990 | func Test_l_arg() |
| 991 | let after =<< trim [CODE] |
| 992 | let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch |
| 993 | call writefile([s], 'Xtestout') |
| 994 | qall |
| 995 | [CODE] |
| 996 | if RunVim([], after, '-l') |
| 997 | call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout')) |
| 998 | call delete('Xtestout') |
| 999 | endif |
| 1000 | endfunc |
| 1001 | |
| 1002 | " Test for specifying a non-existing vimrc file using "-u" |
| 1003 | func Test_missing_vimrc() |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 1004 | CheckRunVimInTerminal |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1005 | let after =<< trim [CODE] |
| 1006 | call assert_match('^E282:', v:errmsg) |
| 1007 | call writefile(v:errors, 'Xtestout') |
| 1008 | [CODE] |
| 1009 | call writefile(after, 'Xafter') |
| 1010 | |
| 1011 | let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter' |
| 1012 | let buf = term_start(cmd, {'term_rows' : 10}) |
| 1013 | call WaitForAssert({-> assert_equal("running", term_getstatus(buf))}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 1014 | call TermWait(buf) |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1015 | call term_sendkeys(buf, "\n:") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 1016 | call TermWait(buf) |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1017 | call WaitForAssert({-> assert_match(':', term_getline(buf, 10))}) |
| 1018 | call StopVimInTerminal(buf) |
| 1019 | call assert_equal([], readfile('Xtestout')) |
| 1020 | call delete('Xafter') |
| 1021 | call delete('Xtestout') |
| 1022 | endfunc |
| 1023 | |
| 1024 | " Test for using the $VIMINIT environment variable |
| 1025 | func Test_VIMINIT() |
| 1026 | let after =<< trim [CODE] |
| 1027 | call assert_equal(1, exists('viminit_found')) |
| 1028 | call assert_equal('yes', viminit_found) |
| 1029 | call writefile(v:errors, 'Xtestout') |
| 1030 | qall |
| 1031 | [CODE] |
| 1032 | call writefile(after, 'Xafter') |
| 1033 | let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' |
| 1034 | call setenv('VIMINIT', 'let viminit_found="yes"') |
| 1035 | exe "silent !" . cmd |
| 1036 | call assert_equal([], readfile('Xtestout')) |
| 1037 | call delete('Xtestout') |
| 1038 | call delete('Xafter') |
| 1039 | endfunc |
| 1040 | |
| 1041 | " Test for using the $EXINIT environment variable |
| 1042 | func Test_EXINIT() |
| 1043 | let after =<< trim [CODE] |
| 1044 | call assert_equal(1, exists('exinit_found')) |
| 1045 | call assert_equal('yes', exinit_found) |
| 1046 | call writefile(v:errors, 'Xtestout') |
| 1047 | qall |
| 1048 | [CODE] |
| 1049 | call writefile(after, 'Xafter') |
| 1050 | let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' |
| 1051 | call setenv('EXINIT', 'let exinit_found="yes"') |
| 1052 | exe "silent !" . cmd |
| 1053 | call assert_equal([], readfile('Xtestout')) |
| 1054 | call delete('Xtestout') |
| 1055 | call delete('Xafter') |
| 1056 | endfunc |
| 1057 | |
| 1058 | " Test for using the 'exrc' option |
| 1059 | func Test_exrc() |
| 1060 | let after =<< trim [CODE] |
| 1061 | call assert_equal(1, &exrc) |
| 1062 | call assert_equal(1, &secure) |
| 1063 | call assert_equal(37, exrc_found) |
| 1064 | call writefile(v:errors, 'Xtestout') |
| 1065 | qall |
| 1066 | [CODE] |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 1067 | call mkdir('Xrcdir') |
| 1068 | call writefile(['let exrc_found=37'], 'Xrcdir/.exrc') |
| 1069 | call writefile(after, 'Xrcdir/Xafter') |
| 1070 | let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xrcdir" --cmd "set enc=utf8 exrc secure"' |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1071 | exe "silent !" . cmd |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 1072 | call assert_equal([], readfile('Xrcdir/Xtestout')) |
| 1073 | call delete('Xrcdir', 'rf') |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1074 | endfunc |
| 1075 | |
| 1076 | " Test for starting Vim with a non-terminal as input/output |
| 1077 | func Test_io_not_a_terminal() |
| 1078 | " Can't catch the output of gvim. |
| 1079 | CheckNotGui |
| 1080 | CheckUnix |
| 1081 | CheckEnglish |
| 1082 | let l = systemlist(GetVimProg() .. ' --ttyfail') |
| 1083 | call assert_equal(['Vim: Warning: Output is not to a terminal', |
| 1084 | \ 'Vim: Warning: Input is not from a terminal'], l) |
| 1085 | endfunc |
| 1086 | |
Bram Moolenaar | 7007e31 | 2021-03-27 12:11:33 +0100 | [diff] [blame] | 1087 | " Test for --not-a-term avoiding escape codes. |
| 1088 | func Test_not_a_term() |
| 1089 | CheckUnix |
| 1090 | CheckNotGui |
| 1091 | |
| 1092 | if &shellredir =~ '%s' |
| 1093 | let redir = printf(&shellredir, 'Xvimout') |
| 1094 | else |
| 1095 | let redir = &shellredir .. ' Xvimout' |
| 1096 | endif |
| 1097 | |
| 1098 | " Without --not-a-term there are a few escape sequences. |
| 1099 | " This will take 2 seconds because of the missing --not-a-term |
| 1100 | let cmd = GetVimProg() .. ' --cmd quit ' .. redir |
| 1101 | exe "silent !" . cmd |
| 1102 | call assert_match("\<Esc>", readfile('Xvimout')->join()) |
| 1103 | call delete('Xvimout') |
| 1104 | |
| 1105 | " With --not-a-term there are no escape sequences. |
| 1106 | let cmd = GetVimProg() .. ' --not-a-term --cmd quit ' .. redir |
| 1107 | exe "silent !" . cmd |
| 1108 | call assert_notmatch("\<Esc>", readfile('Xvimout')->join()) |
| 1109 | call delete('Xvimout') |
| 1110 | endfunc |
| 1111 | |
| 1112 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1113 | " Test for the "-w scriptout" argument |
| 1114 | func Test_w_arg() |
| 1115 | " Can't catch the output of gvim. |
| 1116 | CheckNotGui |
Bram Moolenaar | 0a1a6a1 | 2021-03-26 14:14:18 +0100 | [diff] [blame] | 1117 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1118 | call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'b') |
| 1119 | if RunVim([], [], '-s Xscriptin -w Xscriptout') |
| 1120 | call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout')) |
| 1121 | call delete('Xscriptout') |
| 1122 | endif |
| 1123 | call delete('Xscriptin') |
| 1124 | |
| 1125 | " Test for failing to open the script output file. This test works only when |
| 1126 | " the language is English. |
| 1127 | if v:lang == "C" || v:lang =~ '^[Ee]n' |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 1128 | call mkdir("Xargdir") |
| 1129 | let m = system(GetVimCommand() .. " -w Xargdir") |
| 1130 | call assert_equal("Cannot open for script output: \"Xargdir\"\n", m) |
| 1131 | call delete("Xargdir", 'rf') |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1132 | endif |
Bram Moolenaar | 0a1a6a1 | 2021-03-26 14:14:18 +0100 | [diff] [blame] | 1133 | |
| 1134 | " A number argument sets the 'window' option |
| 1135 | 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] | 1136 | for w_arg in ['-w 17', '-w17'] |
| 1137 | if RunVim([], [], '-s Xscriptin ' .. w_arg) |
| 1138 | call assert_equal(["window 17"], readfile('Xresult'), w_arg) |
| 1139 | call delete('Xresult') |
| 1140 | endif |
| 1141 | endfor |
Bram Moolenaar | 0a1a6a1 | 2021-03-26 14:14:18 +0100 | [diff] [blame] | 1142 | call delete('Xscriptin') |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1143 | endfunc |
| 1144 | |
| 1145 | " Test for the "-s scriptin" argument |
| 1146 | func Test_s_arg() |
| 1147 | " Can't catch the output of gvim. |
| 1148 | CheckNotGui |
| 1149 | CheckEnglish |
| 1150 | " Test for failing to open the script input file. |
| 1151 | let m = system(GetVimCommand() .. " -s abcxyz") |
| 1152 | call assert_equal("Cannot open for reading: \"abcxyz\"\n", m) |
| 1153 | |
| 1154 | call writefile([], 'Xinput') |
| 1155 | let m = system(GetVimCommand() .. " -s Xinput -s Xinput") |
| 1156 | call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m) |
| 1157 | call delete('Xinput') |
| 1158 | endfunc |
| 1159 | |
| 1160 | " Test for the "-n" (no swap file) argument |
| 1161 | func Test_n_arg() |
| 1162 | let after =<< trim [CODE] |
| 1163 | call assert_equal(0, &updatecount) |
| 1164 | call writefile(v:errors, 'Xtestout') |
| 1165 | qall |
| 1166 | [CODE] |
| 1167 | if RunVim([], after, '-n') |
| 1168 | call assert_equal([], readfile('Xtestout')) |
| 1169 | call delete('Xtestout') |
| 1170 | endif |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1171 | endfunc |
| 1172 | |
| 1173 | " Test for the "-h" (help) argument |
| 1174 | func Test_h_arg() |
| 1175 | " Can't catch the output of gvim. |
| 1176 | CheckNotGui |
| 1177 | let l = systemlist(GetVimProg() .. ' -h') |
| 1178 | call assert_match('^VIM - Vi IMproved', l[0]) |
| 1179 | let l = systemlist(GetVimProg() .. ' -?') |
| 1180 | call assert_match('^VIM - Vi IMproved', l[0]) |
| 1181 | endfunc |
| 1182 | |
| 1183 | " Test for the "-F" (farsi) argument |
| 1184 | func Test_F_arg() |
| 1185 | " Can't catch the output of gvim. |
| 1186 | CheckNotGui |
| 1187 | let l = systemlist(GetVimProg() .. ' -F') |
| 1188 | call assert_match('^E27:', l[0]) |
| 1189 | endfunc |
| 1190 | |
| 1191 | " Test for the "-E" (improved Ex mode) argument |
| 1192 | func Test_E_arg() |
| 1193 | let after =<< trim [CODE] |
| 1194 | call assert_equal('cv', mode(1)) |
| 1195 | call writefile(v:errors, 'Xtestout') |
| 1196 | qall |
| 1197 | [CODE] |
| 1198 | if RunVim([], after, '-E') |
| 1199 | call assert_equal([], readfile('Xtestout')) |
| 1200 | call delete('Xtestout') |
| 1201 | endif |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1202 | endfunc |
| 1203 | |
Bram Moolenaar | c5cf369 | 2021-03-20 22:16:56 +0100 | [diff] [blame] | 1204 | " Test for the "-D" (debugger) argument |
| 1205 | func Test_D_arg() |
| 1206 | CheckRunVimInTerminal |
| 1207 | |
| 1208 | let cmd = GetVimCommandCleanTerm() .. ' -D' |
| 1209 | let buf = term_start(cmd, {'term_rows' : 10}) |
| 1210 | call WaitForAssert({-> assert_equal("running", term_getstatus(buf))}) |
| 1211 | |
| 1212 | call WaitForAssert({-> assert_equal('Entering Debug mode. Type "cont" to continue.', |
| 1213 | \ term_getline(buf, 7))}) |
| 1214 | call WaitForAssert({-> assert_equal('>', term_getline(buf, 10))}) |
| 1215 | |
| 1216 | call StopVimInTerminal(buf) |
| 1217 | endfunc |
| 1218 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1219 | " Test for too many edit argument errors |
| 1220 | func Test_too_many_edit_args() |
| 1221 | " Can't catch the output of gvim. |
| 1222 | CheckNotGui |
| 1223 | CheckEnglish |
| 1224 | let l = systemlist(GetVimProg() .. ' - -') |
| 1225 | call assert_match('^Too many edit arguments: "-"', l[1]) |
| 1226 | endfunc |
| 1227 | |
Bram Moolenaar | df4c9af | 2021-01-11 19:54:42 +0100 | [diff] [blame] | 1228 | " Test starting vim with various names: vim, ex, view, evim, etc. |
| 1229 | func Test_progname() |
| 1230 | CheckUnix |
| 1231 | |
| 1232 | call mkdir('Xprogname', 'p') |
| 1233 | call writefile(['silent !date', |
| 1234 | \ 'call writefile([mode(1), ' |
| 1235 | \ .. '&insertmode, &diff, &readonly, &updatecount, ' |
| 1236 | \ .. 'join(split(execute("message"), "\n")[1:])], "Xprogname_out")', |
| 1237 | \ 'qall'], 'Xprogname_after') |
| 1238 | |
| 1239 | " +---------------------------------------------- progname |
| 1240 | " | +--------------------------------- mode(1) |
| 1241 | " | | +--------------------------- &insertmode |
| 1242 | " | | | +---------------------- &diff |
| 1243 | " | | | | +----------------- &readonly |
| 1244 | " | | | | | +-------- &updatecount |
| 1245 | " | | | | | | +--- :messages |
| 1246 | " | | | | | | | |
| 1247 | let expectations = { |
| 1248 | \ 'vim': ['n', '0', '0', '0', '200', ''], |
| 1249 | \ 'gvim': ['n', '0', '0', '0', '200', ''], |
| 1250 | \ 'ex': ['ce', '0', '0', '0', '200', ''], |
| 1251 | \ 'exim': ['cv', '0', '0', '0', '200', ''], |
| 1252 | \ 'view': ['n', '0', '0', '1', '10000', ''], |
| 1253 | \ 'gview': ['n', '0', '0', '1', '10000', ''], |
| 1254 | \ 'evim': ['n', '1', '0', '0', '200', ''], |
| 1255 | \ 'eview': ['n', '1', '0', '1', '10000', ''], |
| 1256 | \ 'rvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], |
| 1257 | \ 'rgvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], |
| 1258 | \ 'rview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], |
| 1259 | \ 'rgview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], |
| 1260 | \ 'vimdiff': ['n', '0', '1', '0', '200', ''], |
| 1261 | \ 'gvimdiff': ['n', '0', '1', '0', '200', '']} |
| 1262 | |
| 1263 | let prognames = ['vim', 'gvim', 'ex', 'exim', 'view', 'gview', |
| 1264 | \ 'evim', 'eview', 'rvim', 'rgvim', 'rview', 'rgview', |
| 1265 | \ 'vimdiff', 'gvimdiff'] |
| 1266 | |
| 1267 | for progname in prognames |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 1268 | let run_with_gui = (progname =~# 'g') || (has('gui') && (progname ==# 'evim' || progname ==# 'eview')) |
| 1269 | |
| 1270 | if empty($DISPLAY) && run_with_gui |
| 1271 | " Can't run gvim, gview (etc.) if $DISPLAY is not setup. |
| 1272 | continue |
Bram Moolenaar | df4c9af | 2021-01-11 19:54:42 +0100 | [diff] [blame] | 1273 | endif |
| 1274 | |
| 1275 | exe 'silent !ln -s -f ' ..exepath(GetVimProg()) .. ' Xprogname/' .. progname |
| 1276 | |
| 1277 | let stdout_stderr = '' |
| 1278 | if progname =~# 'g' |
| 1279 | let stdout_stderr = system('Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after') |
| 1280 | else |
| 1281 | exe 'sil !Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after' |
| 1282 | endif |
| 1283 | |
| 1284 | if progname =~# 'g' && !has('gui') |
| 1285 | call assert_equal("E25: GUI cannot be used: Not enabled at compile time\n", stdout_stderr, progname) |
| 1286 | else |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 1287 | " GUI motif can output some warnings like this: |
| 1288 | " Warning: |
| 1289 | " Name: subMenu |
| 1290 | " Class: XmCascadeButton |
| 1291 | " Illegal mnemonic character; Could not convert X KEYSYM to a keycode |
| 1292 | " So don't check that stderr is empty with GUI Motif. |
| 1293 | if run_with_gui && !has('gui_motif') |
| 1294 | call assert_equal('', stdout_stderr, progname) |
| 1295 | endif |
Bram Moolenaar | df4c9af | 2021-01-11 19:54:42 +0100 | [diff] [blame] | 1296 | call assert_equal(expectations[progname], readfile('Xprogname_out'), progname) |
| 1297 | endif |
| 1298 | |
| 1299 | call delete('Xprogname/' .. progname) |
| 1300 | call delete('Xprogname_out') |
| 1301 | endfor |
| 1302 | |
| 1303 | call delete('Xprogname_after') |
| 1304 | call delete('Xprogname', 'd') |
| 1305 | endfunc |
| 1306 | |
Yegappan Lakshmanan | 36f96a5 | 2021-05-13 18:33:16 +0200 | [diff] [blame] | 1307 | " Test for doing a write from .vimrc |
| 1308 | func Test_write_in_vimrc() |
| 1309 | call writefile(['silent! write'], 'Xvimrc') |
| 1310 | let after =<< trim [CODE] |
| 1311 | call assert_match('E32: ', v:errmsg) |
| 1312 | call writefile(v:errors, 'Xtestout') |
| 1313 | qall |
| 1314 | [CODE] |
| 1315 | if RunVim([], after, '-u Xvimrc') |
| 1316 | call assert_equal([], readfile('Xtestout')) |
| 1317 | call delete('Xtestout') |
| 1318 | endif |
| 1319 | call delete('Xvimrc') |
| 1320 | endfunc |
| 1321 | |
Bram Moolenaar | a97c363 | 2021-06-15 22:39:11 +0200 | [diff] [blame] | 1322 | func Test_echo_true_in_cmd() |
Bram Moolenaar | b90ac5e | 2021-06-16 10:59:36 +0200 | [diff] [blame] | 1323 | CheckNotGui |
| 1324 | |
Bram Moolenaar | a97c363 | 2021-06-15 22:39:11 +0200 | [diff] [blame] | 1325 | let lines =<< trim END |
| 1326 | echo v:true |
| 1327 | call writefile(['done'], 'Xresult') |
Bram Moolenaar | 55b6b60 | 2021-06-15 23:05:59 +0200 | [diff] [blame] | 1328 | quit |
Bram Moolenaar | a97c363 | 2021-06-15 22:39:11 +0200 | [diff] [blame] | 1329 | END |
| 1330 | call writefile(lines, 'Xscript') |
Bram Moolenaar | 55b6b60 | 2021-06-15 23:05:59 +0200 | [diff] [blame] | 1331 | if RunVim([], [], '--cmd "source Xscript"') |
Bram Moolenaar | a97c363 | 2021-06-15 22:39:11 +0200 | [diff] [blame] | 1332 | call assert_equal(['done'], readfile('Xresult')) |
| 1333 | endif |
| 1334 | call delete('Xscript') |
| 1335 | call delete('Xresult') |
Bram Moolenaar | a97c363 | 2021-06-15 22:39:11 +0200 | [diff] [blame] | 1336 | endfunc |
| 1337 | |
Bram Moolenaar | d3710cf | 2021-10-04 23:13:13 +0100 | [diff] [blame] | 1338 | func Test_rename_buffer_on_startup() |
Bram Moolenaar | 6d19798 | 2021-10-05 01:19:53 +0100 | [diff] [blame] | 1339 | CheckUnix |
| 1340 | |
Bram Moolenaar | d3710cf | 2021-10-04 23:13:13 +0100 | [diff] [blame] | 1341 | let lines =<< trim END |
| 1342 | call writefile(['done'], 'Xresult') |
| 1343 | qa! |
| 1344 | END |
| 1345 | call writefile(lines, 'Xscript') |
| 1346 | if RunVim([], [], "--clean -e -s --cmd 'file x|new|file x' --cmd 'so Xscript'") |
| 1347 | call assert_equal(['done'], readfile('Xresult')) |
| 1348 | endif |
| 1349 | call delete('Xscript') |
| 1350 | call delete('Xresult') |
| 1351 | endfunc |
| 1352 | |
| 1353 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1354 | " vim: shiftwidth=2 sts=2 expandtab |