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 | |
Christian Brabandt | eb380b9 | 2025-07-07 20:53:55 +0200 | [diff] [blame] | 3 | source util/screendump.vim |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 4 | |
| 5 | " Check that loading startup.vim works. |
Bram Moolenaar | b9a46fe | 2016-07-29 18:13:42 +0200 | [diff] [blame] | 6 | func Test_startup_script() |
| 7 | set compatible |
| 8 | source $VIMRUNTIME/defaults.vim |
| 9 | |
| 10 | call assert_equal(0, &compatible) |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 11 | " Restore some options, so that the following tests doesn't break |
| 12 | set nomore |
| 13 | set noshowmode |
Bram Moolenaar | b9a46fe | 2016-07-29 18:13:42 +0200 | [diff] [blame] | 14 | endfunc |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 15 | |
| 16 | " Verify the order in which plugins are loaded: |
| 17 | " 1. plugins in non-after directories |
| 18 | " 2. packages |
| 19 | " 3. plugins in after directories |
| 20 | func Test_after_comes_later() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 21 | CheckFeature packages |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 22 | let before =<< trim [CODE] |
| 23 | set nocp viminfo+=nviminfo |
| 24 | set guioptions+=M |
| 25 | let $HOME = "/does/not/exist" |
| 26 | set loadplugins |
| 27 | set rtp=Xhere,Xafter,Xanother |
| 28 | set packpath=Xhere,Xafter |
| 29 | set nomore |
| 30 | let g:sequence = "" |
| 31 | [CODE] |
| 32 | |
| 33 | let after =<< trim [CODE] |
| 34 | redir! > Xtestout |
| 35 | scriptnames |
| 36 | redir END |
| 37 | redir! > Xsequence |
| 38 | echo g:sequence |
| 39 | redir END |
| 40 | quit |
| 41 | [CODE] |
| 42 | |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 43 | call mkdir('Xhere/plugin', 'pR') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 44 | call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim') |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 45 | call mkdir('Xanother/plugin', 'pR') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 46 | call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 47 | call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 48 | 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] | 49 | |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 50 | call mkdir('Xafter/plugin', 'pR') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 51 | call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 52 | |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 53 | if RunVim(before, after, '') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 54 | |
Bram Moolenaar | 83b3c3d | 2016-08-06 19:16:43 +0200 | [diff] [blame] | 55 | let lines = readfile('Xtestout') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 56 | 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] | 57 | let found = [] |
| 58 | for line in lines |
| 59 | for one in expected |
| 60 | if line =~ one |
| 61 | call add(found, one) |
| 62 | endif |
| 63 | endfor |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 64 | endfor |
Bram Moolenaar | 83b3c3d | 2016-08-06 19:16:43 +0200 | [diff] [blame] | 65 | call assert_equal(expected, found) |
| 66 | endif |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 67 | |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 68 | call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', '')) |
| 69 | |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 70 | call delete('Xtestout') |
Bram Moolenaar | 07ecfa6 | 2017-06-27 14:43:55 +0200 | [diff] [blame] | 71 | call delete('Xsequence') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 72 | endfunc |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 73 | |
Bram Moolenaar | ce876aa | 2017-06-04 17:47:42 +0200 | [diff] [blame] | 74 | func Test_pack_in_rtp_when_plugins_run() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 75 | CheckFeature packages |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 76 | let before =<< trim [CODE] |
| 77 | set nocp viminfo+=nviminfo |
| 78 | set guioptions+=M |
| 79 | let $HOME = "/does/not/exist" |
| 80 | set loadplugins |
| 81 | set rtp=Xhere |
| 82 | set packpath=Xhere |
| 83 | set nomore |
| 84 | [CODE] |
| 85 | |
Bram Moolenaar | ce876aa | 2017-06-04 17:47:42 +0200 | [diff] [blame] | 86 | let after = [ |
| 87 | \ 'quit', |
| 88 | \ ] |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 89 | call mkdir('Xhere/plugin', 'pR') |
Bram Moolenaar | ce876aa | 2017-06-04 17:47:42 +0200 | [diff] [blame] | 90 | call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim') |
| 91 | call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p') |
| 92 | call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim') |
| 93 | |
| 94 | if RunVim(before, after, '') |
| 95 | |
| 96 | let lines = filter(readfile('Xtestout'), '!empty(v:val)') |
| 97 | call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0)) |
| 98 | call assert_match('autoloaded foo', get(lines, 1)) |
| 99 | endif |
| 100 | |
| 101 | call delete('Xtestout') |
Bram Moolenaar | ce876aa | 2017-06-04 17:47:42 +0200 | [diff] [blame] | 102 | endfunc |
| 103 | |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 104 | func Test_help_arg() |
Bram Moolenaar | f8c52e8 | 2021-03-17 12:27:23 +0100 | [diff] [blame] | 105 | " This does not work with a GUI-only binary, such as on MS-Windows. |
| 106 | CheckAnyOf Unix NotGui |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 107 | |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 108 | if RunVim([], [], '--help >Xtestout') |
| 109 | let lines = readfile('Xtestout') |
| 110 | call assert_true(len(lines) > 20) |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 111 | call assert_match('Vi IMproved', lines[0]) |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 112 | |
| 113 | " check if couple of lines are there |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 114 | let found = [] |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 115 | for line in lines |
| 116 | if line =~ '-R.*Readonly mode' |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 117 | call add(found, 'Readonly mode') |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 118 | endif |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 119 | " Watch out for a second --version line in the Gnome version. |
| 120 | if line =~ '--version.*Print version information and exit' |
| 121 | call add(found, "--version") |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 122 | endif |
| 123 | endfor |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 124 | call assert_equal(['Readonly mode', '--version'], found) |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 125 | endif |
| 126 | call delete('Xtestout') |
| 127 | endfunc |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 128 | |
| 129 | func Test_compatible_args() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 130 | let after =<< trim [CODE] |
| 131 | call writefile([string(&compatible)], "Xtestout") |
| 132 | set viminfo+=nviminfo |
| 133 | quit |
| 134 | [CODE] |
| 135 | |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 136 | if RunVim([], after, '-C') |
| 137 | let lines = readfile('Xtestout') |
| 138 | call assert_equal('1', lines[0]) |
| 139 | endif |
| 140 | |
| 141 | if RunVim([], after, '-N') |
| 142 | let lines = readfile('Xtestout') |
| 143 | call assert_equal('0', lines[0]) |
| 144 | endif |
| 145 | |
| 146 | call delete('Xtestout') |
| 147 | endfunc |
| 148 | |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 149 | " Test the -o[N] and -O[N] arguments to open N windows split |
| 150 | " horizontally or vertically. |
| 151 | func Test_o_arg() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 152 | let after =<< trim [CODE] |
Bram Moolenaar | e96a249 | 2019-06-25 04:12:16 +0200 | [diff] [blame] | 153 | set cpo&vim |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 154 | call writefile([winnr("$"), |
| 155 | \ winheight(1), winheight(2), &lines, |
| 156 | \ winwidth(1), winwidth(2), &columns, |
| 157 | \ bufname(winbufnr(1)), bufname(winbufnr(2))], |
| 158 | \ "Xtestout") |
| 159 | qall |
| 160 | [CODE] |
| 161 | |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 162 | if RunVim([], after, '-o2') |
| 163 | " Open 2 windows split horizontally. Expect: |
| 164 | " - 2 windows |
| 165 | " - both windows should have the same or almost the same height |
| 166 | " - sum of both windows height (+ 3 for both statusline and Ex command) |
| 167 | " should be equal to the number of lines |
| 168 | " - both windows should have the same width which should be equal to the |
| 169 | " number of columns |
| 170 | " - buffer of both windows should have no name |
| 171 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 172 | call assert_equal('2', wn) |
| 173 | call assert_inrange(0, 1, wh1 - wh2) |
| 174 | call assert_equal(string(wh1 + wh2 + 3), ln) |
| 175 | call assert_equal(ww1, ww2) |
| 176 | call assert_equal(ww1, cn) |
| 177 | call assert_equal('', bn1) |
| 178 | call assert_equal('', bn2) |
| 179 | endif |
| 180 | |
| 181 | if RunVim([], after, '-o foo bar') |
| 182 | " Same expectations as for -o2 but buffer names should be foo and bar |
| 183 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 184 | call assert_equal('2', wn) |
| 185 | call assert_inrange(0, 1, wh1 - wh2) |
| 186 | call assert_equal(string(wh1 + wh2 + 3), ln) |
| 187 | call assert_equal(ww1, ww2) |
| 188 | call assert_equal(ww1, cn) |
| 189 | call assert_equal('foo', bn1) |
| 190 | call assert_equal('bar', bn2) |
| 191 | endif |
| 192 | |
| 193 | if RunVim([], after, '-O2') |
| 194 | " Open 2 windows split vertically. Expect: |
| 195 | " - 2 windows |
| 196 | " - both windows should have the same or almost the same width |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 197 | " - sum of both windows width (+ 1 for the separator) should be equal to |
| 198 | " the number of columns |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 199 | " - both windows should have the same height |
| 200 | " - window height (+ 2 for the statusline and Ex command) should be equal |
| 201 | " to the number of lines |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 202 | " - buffer of both windows should have no name |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 203 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 204 | call assert_equal('2', wn) |
| 205 | call assert_inrange(0, 1, ww1 - ww2) |
| 206 | call assert_equal(string(ww1 + ww2 + 1), cn) |
| 207 | call assert_equal(wh1, wh2) |
| 208 | call assert_equal(string(wh1 + 2), ln) |
| 209 | call assert_equal('', bn1) |
| 210 | call assert_equal('', bn2) |
| 211 | endif |
| 212 | |
| 213 | if RunVim([], after, '-O foo bar') |
| 214 | " Same expectations as for -O2 but buffer names should be foo and bar |
| 215 | let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') |
| 216 | call assert_equal('2', wn) |
| 217 | call assert_inrange(0, 1, ww1 - ww2) |
| 218 | call assert_equal(string(ww1 + ww2 + 1), cn) |
| 219 | call assert_equal(wh1, wh2) |
| 220 | call assert_equal(string(wh1 + 2), ln) |
| 221 | call assert_equal('foo', bn1) |
| 222 | call assert_equal('bar', bn2) |
| 223 | endif |
Bram Moolenaar | 8f4499b | 2018-09-16 16:28:11 +0200 | [diff] [blame] | 224 | call delete('Xtestout') |
| 225 | endfunc |
| 226 | |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 227 | " Test the -p[N] argument to open N tabpages. |
| 228 | func Test_p_arg() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 229 | let after =<< trim [CODE] |
| 230 | call writefile(split(execute("tabs"), "\n"), "Xtestout") |
| 231 | qall |
| 232 | [CODE] |
| 233 | |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 234 | if RunVim([], after, '-p2') |
| 235 | let lines = readfile('Xtestout') |
| 236 | call assert_equal(4, len(lines)) |
| 237 | call assert_equal('Tab page 1', lines[0]) |
| 238 | call assert_equal('> [No Name]', lines[1]) |
| 239 | call assert_equal('Tab page 2', lines[2]) |
| 240 | call assert_equal(' [No Name]', lines[3]) |
| 241 | endif |
| 242 | |
| 243 | if RunVim([], after, '-p foo bar') |
| 244 | let lines = readfile('Xtestout') |
| 245 | call assert_equal(4, len(lines)) |
| 246 | call assert_equal('Tab page 1', lines[0]) |
| 247 | call assert_equal('> foo', lines[1]) |
| 248 | call assert_equal('Tab page 2', lines[2]) |
| 249 | call assert_equal(' bar', lines[3]) |
| 250 | endif |
| 251 | |
| 252 | call delete('Xtestout') |
| 253 | endfunc |
| 254 | |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 255 | " Test the -V[N] argument to set the 'verbose' option to [N] |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 256 | func Test_V_arg() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 257 | " Can't catch the output of gvim. |
| 258 | CheckNotGui |
| 259 | |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 260 | let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq') |
| 261 | call assert_equal(" verbose=0\n", out) |
| 262 | |
| 263 | let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq') |
Bram Moolenaar | 4515bcd | 2020-05-03 18:21:04 +0200 | [diff] [blame] | 264 | 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] | 265 | call assert_match(" verbose=2\n", out) |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 266 | |
| 267 | let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq') |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 268 | 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] | 269 | endfunc |
| 270 | |
Christian Brabandt | 1d3a14e | 2021-05-29 19:53:50 +0200 | [diff] [blame] | 271 | " 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] | 272 | func Test_defaults_error() |
| 273 | " Can't catch the output of gvim. |
| 274 | CheckNotGui |
| 275 | CheckNotMSWindows |
| 276 | " For unknown reasons freeing all memory does not work here, even though |
| 277 | " EXITFREE is defined. |
| 278 | CheckNotAsan |
| 279 | |
| 280 | let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' --clean -cq') |
| 281 | call assert_match("E1187: Failed to source defaults.vim", out) |
| 282 | |
| 283 | let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' -u DEFAULTS -cq') |
| 284 | call assert_match("E1187: Failed to source defaults.vim", out) |
| 285 | endfunc |
Christian Brabandt | 1d3a14e | 2021-05-29 19:53:50 +0200 | [diff] [blame] | 286 | |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 287 | " Test the '-q [errorfile]' argument. |
| 288 | func Test_q_arg() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 289 | CheckFeature quickfix |
| 290 | |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 291 | let lines =<< trim END |
| 292 | /* some file with an error */ |
| 293 | main() { |
| 294 | functionCall(arg; arg, arg); |
| 295 | return 666 |
| 296 | } |
| 297 | END |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 298 | call writefile(lines, 'Xbadfile.c', 'D') |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 299 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 300 | let after =<< trim [CODE] |
Bram Moolenaar | be9fc5b | 2022-09-09 17:09:35 +0100 | [diff] [blame] | 301 | call writefile([&errorfile, string(getpos("."))], "XtestoutQarg") |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 302 | copen |
Bram Moolenaar | be9fc5b | 2022-09-09 17:09:35 +0100 | [diff] [blame] | 303 | w >> XtestoutQarg |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 304 | qall |
| 305 | [CODE] |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 306 | |
| 307 | " Test with default argument '-q'. |
| 308 | call assert_equal('errors.err', &errorfile) |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 309 | call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'errors.err', 'D') |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 310 | if RunVim([], after, '-q') |
Bram Moolenaar | be9fc5b | 2022-09-09 17:09:35 +0100 | [diff] [blame] | 311 | let lines = readfile('XtestoutQarg') |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 312 | call assert_equal(['errors.err', |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 313 | \ '[0, 4, 12, 0]', |
| 314 | \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"], |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 315 | \ lines) |
| 316 | endif |
Bram Moolenaar | be9fc5b | 2022-09-09 17:09:35 +0100 | [diff] [blame] | 317 | call delete('XtestoutQarg') |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 318 | |
Bram Moolenaar | be9fc5b | 2022-09-09 17:09:35 +0100 | [diff] [blame] | 319 | " Test with explicit argument '-q XerrorsQarg' (with space). |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 320 | call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'XerrorsQarg', 'D') |
Bram Moolenaar | be9fc5b | 2022-09-09 17:09:35 +0100 | [diff] [blame] | 321 | if RunVim([], after, '-q XerrorsQarg') |
| 322 | let lines = readfile('XtestoutQarg') |
| 323 | call assert_equal(['XerrorsQarg', |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 324 | \ '[0, 4, 12, 0]', |
| 325 | \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"], |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 326 | \ lines) |
| 327 | endif |
Bram Moolenaar | be9fc5b | 2022-09-09 17:09:35 +0100 | [diff] [blame] | 328 | call delete('XtestoutQarg') |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 329 | |
Bram Moolenaar | be9fc5b | 2022-09-09 17:09:35 +0100 | [diff] [blame] | 330 | " Test with explicit argument '-qXerrorsQarg' (without space). |
| 331 | if RunVim([], after, '-qXerrorsQarg') |
| 332 | let lines = readfile('XtestoutQarg') |
| 333 | call assert_equal(['XerrorsQarg', |
Bram Moolenaar | 1e1f612 | 2020-07-15 11:19:11 +0200 | [diff] [blame] | 334 | \ '[0, 4, 12, 0]', |
| 335 | \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"], |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 336 | \ lines) |
| 337 | endif |
| 338 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 339 | " Test with a non-existing error file (exits with value 3) |
| 340 | let out = system(GetVimCommand() .. ' -q xyz.err') |
| 341 | call assert_equal(3, v:shell_error) |
| 342 | |
Bram Moolenaar | be9fc5b | 2022-09-09 17:09:35 +0100 | [diff] [blame] | 343 | call delete('XtestoutQarg') |
Bram Moolenaar | 5494818 | 2018-12-28 18:32:56 +0100 | [diff] [blame] | 344 | endfunc |
| 345 | |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 346 | " Test the -V[N]{filename} argument to set the 'verbose' option to N |
| 347 | " and set 'verbosefile' to filename. |
| 348 | func Test_V_file_arg() |
Bram Moolenaar | 4841a7c | 2018-09-22 14:08:49 +0200 | [diff] [blame] | 349 | if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq') |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 350 | let out = join(readfile('Xverbosefile'), "\n") |
| 351 | call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out) |
| 352 | call assert_match("\n verbose=2\n", out) |
| 353 | call assert_match("\n verbosefile=Xverbosefile", out) |
| 354 | endif |
| 355 | |
| 356 | call delete('Xverbosefile') |
| 357 | endfunc |
| 358 | |
| 359 | " Test the -m, -M and -R arguments: |
| 360 | " -m resets 'write' |
| 361 | " -M resets 'modifiable' and 'write' |
| 362 | " -R sets 'readonly' |
| 363 | func Test_m_M_R() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 364 | let after =<< trim [CODE] |
| 365 | call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout") |
| 366 | qall |
| 367 | [CODE] |
| 368 | |
Bram Moolenaar | 036b09c | 2018-09-21 12:54:06 +0200 | [diff] [blame] | 369 | if RunVim([], after, '') |
| 370 | let lines = readfile('Xtestout') |
| 371 | call assert_equal(['1', '1', '0', '200'], lines) |
| 372 | endif |
| 373 | if RunVim([], after, '-m') |
| 374 | let lines = readfile('Xtestout') |
| 375 | call assert_equal(['0', '1', '0', '200'], lines) |
| 376 | endif |
| 377 | if RunVim([], after, '-M') |
| 378 | let lines = readfile('Xtestout') |
| 379 | call assert_equal(['0', '0', '0', '200'], lines) |
| 380 | endif |
| 381 | if RunVim([], after, '-R') |
| 382 | let lines = readfile('Xtestout') |
| 383 | call assert_equal(['1', '1', '1', '10000'], lines) |
| 384 | endif |
| 385 | |
| 386 | call delete('Xtestout') |
| 387 | endfunc |
| 388 | |
zeertzjq | f0300fc | 2023-02-28 16:02:35 +0000 | [diff] [blame] | 389 | " Test the -A and -H arguments (Arabic and Hebrew modes). |
| 390 | func Test_A_H_arg() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 391 | let after =<< trim [CODE] |
Bram Moolenaar | 9ce7915 | 2022-10-12 11:54:34 +0100 | [diff] [blame] | 392 | call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout") |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 393 | qall |
| 394 | [CODE] |
| 395 | |
Bram Moolenaar | 4b1c9a9 | 2018-09-19 21:06:31 +0200 | [diff] [blame] | 396 | " Use silent Ex mode to avoid the hit-Enter prompt for the warning that |
| 397 | " 'encoding' is not utf-8. |
| 398 | if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A') |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 399 | let lines = readfile('Xtestout') |
| 400 | call assert_equal(['1', '1', '0', '0'], lines) |
| 401 | endif |
| 402 | |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 403 | if has('rightleft') && RunVim([], after, '-H') |
| 404 | let lines = readfile('Xtestout') |
| 405 | call assert_equal(['1', '0', '0', '1'], lines) |
| 406 | endif |
Bram Moolenaar | 9ce7915 | 2022-10-12 11:54:34 +0100 | [diff] [blame] | 407 | |
| 408 | call delete('Xtestout') |
Bram Moolenaar | 9e81db9 | 2018-09-18 22:37:31 +0200 | [diff] [blame] | 409 | endfunc |
| 410 | |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 411 | " Test the --echo-wid argument (for GTK GUI only). |
| 412 | func Test_echo_wid() |
| 413 | CheckCanRunGui |
| 414 | CheckFeature gui_gtk |
| 415 | |
| 416 | if RunVim([], [], '-g --echo-wid -cq >Xtest_echo_wid') |
| 417 | let lines = readfile('Xtest_echo_wid') |
| 418 | call assert_equal(1, len(lines)) |
| 419 | call assert_match('^WID: \d\+$', lines[0]) |
| 420 | endif |
| 421 | |
| 422 | call delete('Xtest_echo_wid') |
| 423 | endfunction |
| 424 | |
| 425 | " Test the -reverse and +reverse arguments (for GUI only). |
| 426 | func Test_reverse() |
| 427 | CheckCanRunGui |
Bram Moolenaar | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 428 | CheckAnyOf Feature:gui_gtk Feature:gui_motif |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 429 | |
| 430 | let after =<< trim [CODE] |
| 431 | call writefile([&background], "Xtest_reverse") |
| 432 | qall |
| 433 | [CODE] |
| 434 | if RunVim([], after, '-f -g -reverse') |
| 435 | let lines = readfile('Xtest_reverse') |
| 436 | call assert_equal(['dark'], lines) |
| 437 | endif |
| 438 | if RunVim([], after, '-f -g +reverse') |
| 439 | let lines = readfile('Xtest_reverse') |
| 440 | call assert_equal(['light'], lines) |
| 441 | endif |
| 442 | |
| 443 | call delete('Xtest_reverse') |
| 444 | endfunc |
| 445 | |
| 446 | " Test the -background and -foreground arguments (for GUI only). |
| 447 | func Test_background_foreground() |
| 448 | CheckCanRunGui |
Bram Moolenaar | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 449 | CheckAnyOf Feature:gui_gtk Feature:gui_motif |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 450 | |
| 451 | " Is there a better way to check the effect of -background & -foreground |
| 452 | " other than merely looking at &background (dark or light)? |
| 453 | let after =<< trim [CODE] |
| 454 | call writefile([&background], "Xtest_fg_bg") |
| 455 | qall |
| 456 | [CODE] |
| 457 | if RunVim([], after, '-f -g -background darkred -foreground yellow') |
| 458 | let lines = readfile('Xtest_fg_bg') |
| 459 | call assert_equal(['dark'], lines) |
| 460 | endif |
| 461 | if RunVim([], after, '-f -g -background ivory -foreground darkgreen') |
| 462 | let lines = readfile('Xtest_fg_bg') |
| 463 | call assert_equal(['light'], lines) |
| 464 | endif |
| 465 | |
| 466 | call delete('Xtest_fg_bg') |
| 467 | endfunc |
| 468 | |
| 469 | " Test the -font argument (for GUI only). |
| 470 | func Test_font() |
| 471 | CheckCanRunGui |
| 472 | CheckNotMSWindows |
| 473 | |
| 474 | if has('gui_gtk') |
| 475 | let font = 'Courier 14' |
Bram Moolenaar | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 476 | elseif has('gui_motif') |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 477 | let font = '-misc-fixed-bold-*' |
| 478 | else |
| 479 | throw 'Skipped: test does not set a valid font for this GUI' |
| 480 | endif |
| 481 | |
| 482 | let after =<< trim [CODE] |
| 483 | call writefile([&guifont], "Xtest_font") |
| 484 | qall |
| 485 | [CODE] |
| 486 | |
| 487 | if RunVim([], after, '--nofork -g -font "' .. font .. '"') |
| 488 | let lines = readfile('Xtest_font') |
| 489 | call assert_equal([font], lines) |
| 490 | endif |
| 491 | |
| 492 | call delete('Xtest_font') |
| 493 | endfunc |
| 494 | |
| 495 | " Test the -geometry argument (for GUI only). |
| 496 | func Test_geometry() |
| 497 | CheckCanRunGui |
Bram Moolenaar | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 498 | CheckAnyOf Feature:gui_gtk Feature:gui_motif |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 499 | |
Bram Moolenaar | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 500 | if has('gui_motif') |
| 501 | " FIXME: With GUI Motif the value of getwinposx(), |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 502 | " getwinposy() and getwinpos() do not match exactly the |
| 503 | " value given in -geometry. Why? |
| 504 | " So only check &columns and &lines for those GUIs. |
| 505 | let after =<< trim [CODE] |
| 506 | call writefile([&columns, &lines], "Xtest_geometry") |
| 507 | qall |
| 508 | [CODE] |
| 509 | if RunVim([], after, '-f -g -geometry 31x13+41+43') |
| 510 | let lines = readfile('Xtest_geometry') |
| 511 | call assert_equal(['31', '13'], lines) |
| 512 | endif |
| 513 | else |
| 514 | let after =<< trim [CODE] |
| 515 | call writefile([&columns, &lines, getwinposx(), getwinposy(), string(getwinpos())], "Xtest_geometry") |
| 516 | qall |
| 517 | [CODE] |
lilydjwg | 6e0a18f | 2024-01-29 20:54:28 +0100 | [diff] [blame] | 518 | " Hide menu because gtk insists to make the window wide enough to show it completely |
Bram Moolenaar | fa04eae | 2022-06-21 14:38:40 +0100 | [diff] [blame] | 519 | " Some window managers have a bar at the top that pushes windows down, |
| 520 | " need to use at least 130, let's do 150 |
lilydjwg | 6e0a18f | 2024-01-29 20:54:28 +0100 | [diff] [blame] | 521 | if RunVim(['set guioptions-=m'], after, '-f -g -geometry 31x13+41+150') |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 522 | let lines = readfile('Xtest_geometry') |
Bram Moolenaar | b376aa2 | 2021-10-11 16:08:32 +0100 | [diff] [blame] | 523 | " Depending on the GUI library and the windowing system the final size |
| 524 | " might be a bit different, allow for some tolerance. Tuned based on |
| 525 | " actual failures. |
Christian Brabandt | e965b7a | 2025-06-10 21:29:43 +0200 | [diff] [blame] | 526 | call assert_inrange(30, 35, str2nr(lines[0])) |
lilydjwg | 94ff09a | 2024-01-29 20:14:01 +0100 | [diff] [blame] | 527 | " for some reason, the window may contain fewer lines than requested |
| 528 | " for GTK, so allow some tolerance |
| 529 | call assert_inrange(8, 13, str2nr(lines[1])) |
lilydjwg | 6e0a18f | 2024-01-29 20:54:28 +0100 | [diff] [blame] | 530 | " on Wayland there is no way to set or retrieve window positions |
| 531 | if empty($WAYLAND_DISPLAY) |
| 532 | call assert_equal('41', lines[2]) |
| 533 | call assert_equal('150', lines[3]) |
| 534 | call assert_equal('[41, 150]', lines[4]) |
| 535 | endif |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 536 | endif |
| 537 | endif |
| 538 | |
| 539 | call delete('Xtest_geometry') |
| 540 | endfunc |
| 541 | |
| 542 | " Test the -iconic argument (for GUI only). |
| 543 | func Test_iconic() |
| 544 | CheckCanRunGui |
Bram Moolenaar | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 545 | CheckAnyOf Feature:gui_gtk Feature:gui_motif |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 546 | |
| 547 | call RunVim([], [], '-f -g -iconic -cq') |
| 548 | |
| 549 | " TODO: currently only start vim iconified, but does not |
| 550 | " check that vim is iconified. How could this be checked? |
| 551 | endfunc |
| 552 | |
| 553 | |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 554 | func Test_invalid_args() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 555 | " must be able to get the output of Vim. |
| 556 | CheckUnix |
| 557 | CheckNotGui |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 558 | |
Foxe Chen | b90c239 | 2025-06-27 21:10:35 +0200 | [diff] [blame] | 559 | for opt in ['-K', '--does-not-exist'] |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 560 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 561 | call assert_equal(1, v:shell_error) |
| 562 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 563 | call assert_equal('Unknown option argument: "' .. opt .. '"', out[1]) |
| 564 | call assert_equal('More info with: "vim -h"', out[2]) |
| 565 | endfor |
| 566 | |
| 567 | for opt in ['-c', '-i', '-s', '-t', '-T', '-u', '-U', '-w', '-W', '--cmd', '--startuptime'] |
| 568 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 569 | call assert_equal(1, v:shell_error) |
| 570 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 571 | call assert_equal('Argument missing after: "' .. opt .. '"', out[1]) |
| 572 | call assert_equal('More info with: "vim -h"', out[2]) |
| 573 | endfor |
| 574 | |
| 575 | if has('clientserver') |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 576 | for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr', |
| 577 | \ '--remote-tab', '--remote-tab-wait', |
| 578 | \ '--remote-tab-wait-silent', '--remote-tab-silent', |
| 579 | \ '--remote-wait', '--remote-wait-silent', |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 580 | \ '--servername', |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 581 | \ ] |
| 582 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 583 | call assert_equal(1, v:shell_error) |
| 584 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 585 | call assert_equal('Argument missing after: "' .. opt .. '"', out[1]) |
| 586 | call assert_equal('More info with: "vim -h"', out[2]) |
| 587 | endfor |
| 588 | endif |
| 589 | |
Bram Moolenaar | 240f7ab | 2019-05-08 17:58:15 +0200 | [diff] [blame] | 590 | if has('gui_gtk') |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 591 | let out = split(system(GetVimCommand() .. ' --display'), "\n") |
| 592 | call assert_equal(1, v:shell_error) |
| 593 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 594 | call assert_equal('Argument missing after: "--display"', out[1]) |
| 595 | call assert_equal('More info with: "vim -h"', out[2]) |
| 596 | endif |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 597 | |
Bram Moolenaar | 5416b75 | 2019-05-08 18:36:43 +0200 | [diff] [blame] | 598 | if has('xterm_clipboard') |
Bram Moolenaar | 240f7ab | 2019-05-08 17:58:15 +0200 | [diff] [blame] | 599 | let out = split(system(GetVimCommand() .. ' -display'), "\n") |
| 600 | call assert_equal(1, v:shell_error) |
| 601 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 602 | call assert_equal('Argument missing after: "-display"', out[1]) |
| 603 | call assert_equal('More info with: "vim -h"', out[2]) |
| 604 | endif |
| 605 | |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 606 | let out = split(system(GetVimCommand() .. ' -ix'), "\n") |
| 607 | call assert_equal(1, v:shell_error) |
| 608 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 609 | call assert_equal('Garbage after option argument: "-ix"', out[1]) |
| 610 | call assert_equal('More info with: "vim -h"', out[2]) |
| 611 | |
| 612 | let out = split(system(GetVimCommand() .. ' - xxx'), "\n") |
| 613 | call assert_equal(1, v:shell_error) |
| 614 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 615 | call assert_equal('Too many edit arguments: "xxx"', out[1]) |
| 616 | call assert_equal('More info with: "vim -h"', out[2]) |
| 617 | |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 618 | if has('quickfix') |
Dominique Pelle | d176ca3 | 2021-09-09 20:45:34 +0200 | [diff] [blame] | 619 | " Detect invalid repeated arguments '-t foo -t foo', '-q foo -q foo'. |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 620 | for opt in ['-t', '-q'] |
| 621 | let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n") |
| 622 | call assert_equal(1, v:shell_error) |
| 623 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 624 | call assert_equal('Too many edit arguments: "' .. opt .. '"', out[1]) |
| 625 | call assert_equal('More info with: "vim -h"', out[2]) |
| 626 | endfor |
| 627 | endif |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 628 | |
| 629 | for opt in [' -cq', ' --cmd q', ' +', ' -S foo'] |
| 630 | let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n") |
| 631 | call assert_equal(1, v:shell_error) |
| 632 | " FIXME: The error message given by Vim is not ideal in case of repeated |
| 633 | " -S foo since it does not mention -S. |
| 634 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 635 | call assert_equal('Too many "+command", "-c command" or "--cmd command" arguments', out[1]) |
| 636 | call assert_equal('More info with: "vim -h"', out[2]) |
| 637 | endfor |
| 638 | |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 639 | if has('gui_gtk') |
Dominique Pelle | 6d37e8e | 2021-05-06 17:36:55 +0200 | [diff] [blame] | 640 | let out = split(system(GetVimCommand() .. ' --socketid'), "\n") |
| 641 | call assert_equal(1, v:shell_error) |
| 642 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 643 | call assert_equal('Argument missing after: "--socketid"', out[1]) |
| 644 | call assert_equal('More info with: "vim -h"', out[2]) |
| 645 | |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 646 | for opt in ['--socketid x', '--socketid 0xg'] |
| 647 | let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") |
| 648 | call assert_equal(1, v:shell_error) |
| 649 | call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) |
| 650 | call assert_equal('Invalid argument for: "--socketid"', out[1]) |
| 651 | call assert_equal('More info with: "vim -h"', out[2]) |
| 652 | endfor |
Dominique Pelle | 6d37e8e | 2021-05-06 17:36:55 +0200 | [diff] [blame] | 653 | |
Bram Moolenaar | 2782126 | 2019-05-08 16:41:09 +0200 | [diff] [blame] | 654 | endif |
Bram Moolenaar | ba9ea91 | 2019-05-07 22:10:50 +0200 | [diff] [blame] | 655 | endfunc |
| 656 | |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 657 | func Test_file_args() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 658 | let after =<< trim [CODE] |
| 659 | call writefile(argv(), "Xtestout") |
| 660 | qall |
| 661 | [CODE] |
| 662 | |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 663 | if RunVim([], after, '') |
| 664 | let lines = readfile('Xtestout') |
| 665 | call assert_equal(0, len(lines)) |
| 666 | endif |
| 667 | |
| 668 | if RunVim([], after, 'one') |
| 669 | let lines = readfile('Xtestout') |
| 670 | call assert_equal(1, len(lines)) |
| 671 | call assert_equal('one', lines[0]) |
| 672 | endif |
| 673 | |
| 674 | if RunVim([], after, 'one two three') |
| 675 | let lines = readfile('Xtestout') |
| 676 | call assert_equal(3, len(lines)) |
| 677 | call assert_equal('one', lines[0]) |
| 678 | call assert_equal('two', lines[1]) |
| 679 | call assert_equal('three', lines[2]) |
| 680 | endif |
| 681 | |
| 682 | if RunVim([], after, 'one -c echo two') |
| 683 | let lines = readfile('Xtestout') |
| 684 | call assert_equal(2, len(lines)) |
| 685 | call assert_equal('one', lines[0]) |
| 686 | call assert_equal('two', lines[1]) |
| 687 | endif |
| 688 | |
| 689 | if RunVim([], after, 'one -- -c echo two') |
| 690 | let lines = readfile('Xtestout') |
| 691 | call assert_equal(4, len(lines)) |
| 692 | call assert_equal('one', lines[0]) |
| 693 | call assert_equal('-c', lines[1]) |
| 694 | call assert_equal('echo', lines[2]) |
| 695 | call assert_equal('two', lines[3]) |
| 696 | endif |
| 697 | |
| 698 | call delete('Xtestout') |
| 699 | endfunc |
| 700 | |
| 701 | func Test_startuptime() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 702 | CheckFeature startuptime |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame] | 703 | let after = ['qall'] |
| 704 | if RunVim([], after, '--startuptime Xtestout one') |
| 705 | let lines = readfile('Xtestout') |
| 706 | let expected = ['--- VIM STARTING ---', 'parsing arguments', |
| 707 | \ 'shell init', 'inits 3', 'start termcap', 'opening buffers'] |
| 708 | let found = [] |
| 709 | for line in lines |
| 710 | for exp in expected |
| 711 | if line =~ exp |
| 712 | call add(found, exp) |
| 713 | endif |
| 714 | endfor |
| 715 | endfor |
| 716 | call assert_equal(expected, found) |
| 717 | endif |
| 718 | call delete('Xtestout') |
| 719 | endfunc |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 720 | |
Bram Moolenaar | c9a9a0a | 2022-04-12 15:09:23 +0100 | [diff] [blame] | 721 | func Test_log() |
| 722 | CheckFeature channel |
| 723 | |
| 724 | call assert_false(filereadable('Xlogfile')) |
| 725 | let after = ['qall'] |
| 726 | if RunVim([], after, '--log Xlogfile') |
| 727 | call assert_equal(1, readfile('Xlogfile') |
| 728 | \ ->filter({i, l -> l =~ '==== start log session'}) |
| 729 | \ ->len()) |
| 730 | " second time appends to the log |
| 731 | if RunVim([], after, '--log Xlogfile') |
| 732 | call assert_equal(2, readfile('Xlogfile') |
| 733 | \ ->filter({i, l -> l =~ '==== start log session'}) |
| 734 | \ ->len()) |
| 735 | endif |
| 736 | endif |
| 737 | call delete('Xlogfile') |
| 738 | endfunc |
| 739 | |
Hirohito Higashi | c5654b8 | 2025-02-10 20:55:17 +0100 | [diff] [blame] | 740 | func Test_log_nonexistent() |
| 741 | " this used to crash Vim |
Christian Brabandt | 88ce0c5 | 2025-02-11 22:58:20 +0100 | [diff] [blame] | 742 | CheckRunVimInTerminal |
Christian Brabandt | 35e02af | 2025-02-10 22:13:43 +0100 | [diff] [blame] | 743 | CheckUnix |
Christian Brabandt | 88ce0c5 | 2025-02-11 22:58:20 +0100 | [diff] [blame] | 744 | let args = ' -u NONE -i NONE -U NONE --log /X/Xlogfile -X -c qa!' |
| 745 | let options = {'term_finish': 'open', 'cmd': |
| 746 | \ 'sh -c "' .. GetVimCommand() .. args .. '"'} |
| 747 | let buf = RunVimInTerminal('', options) |
| 748 | call WaitForAssert({-> assert_match('E484: Can''t open file.*Xlogfile', term_getline(buf, 1))}) |
| 749 | " terminal job has already finished, so just close the buffer |
| 750 | exe buf .. "bw!" |
Hirohito Higashi | c5654b8 | 2025-02-10 20:55:17 +0100 | [diff] [blame] | 751 | endfunc |
| 752 | |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 753 | func Test_read_stdin() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 754 | let after =<< trim [CODE] |
| 755 | write Xtestout |
| 756 | quit! |
| 757 | [CODE] |
| 758 | |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 759 | if RunVimPiped([], after, '-', 'echo something | ') |
| 760 | let lines = readfile('Xtestout') |
Bram Moolenaar | e4a76ad | 2016-08-07 16:50:10 +0200 | [diff] [blame] | 761 | " MS-Windows adds a space after the word |
| 762 | call assert_equal(['something'], split(lines[0])) |
Bram Moolenaar | 3a93838 | 2016-08-07 16:36:40 +0200 | [diff] [blame] | 763 | endif |
| 764 | call delete('Xtestout') |
| 765 | endfunc |
Bram Moolenaar | 08cab96 | 2017-03-04 14:37:18 +0100 | [diff] [blame] | 766 | |
| 767 | func Test_progpath() |
| 768 | " Tests normally run with "./vim" or "../vim", these must have been expanded |
| 769 | " to a full path. |
| 770 | if has('unix') |
| 771 | call assert_equal('/', v:progpath[0]) |
| 772 | elseif has('win32') |
| 773 | call assert_equal(':', v:progpath[1]) |
| 774 | call assert_match('[/\\]', v:progpath[2]) |
| 775 | endif |
| 776 | |
| 777 | " Only expect "vim" to appear in v:progname. |
| 778 | call assert_match('vim\c', v:progname) |
| 779 | endfunc |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 780 | |
Abhijit Barik | 221927b | 2025-04-06 16:12:06 +0200 | [diff] [blame] | 781 | func Test_stdin_no_newline() |
| 782 | CheckScreendump |
| 783 | CheckUnix |
| 784 | CheckExecutable bash |
| 785 | |
| 786 | let $PS1 = 'TEST_PROMPT> ' |
| 787 | let buf = RunVimInTerminal('', #{rows: 20, cmd: 'bash --noprofile --norc'}) |
| 788 | call TermWait(buf, 100) |
| 789 | |
| 790 | " Write input to temp file |
| 791 | call term_sendkeys(buf, "echo hello > temp.txt\<CR>") |
| 792 | call TermWait(buf, 200) |
| 793 | |
| 794 | call term_sendkeys(buf, "bash -c '../vim --not-a-term -u NONE -c \":q!\" -' < temp.txt\<CR>") |
| 795 | call TermWait(buf, 200) |
| 796 | |
| 797 | " Capture terminal output |
| 798 | let lines = [] |
| 799 | for i in range(1, term_getsize(buf)[0]) |
| 800 | call add(lines, term_getline(buf, i)) |
| 801 | endfor |
| 802 | |
| 803 | " Find the command line in output |
| 804 | let cmd_line = -1 |
| 805 | for i in range(len(lines)) |
| 806 | if lines[i] =~ '.*vim.*--not-a-term.*' |
| 807 | let cmd_line = i |
| 808 | break |
| 809 | endif |
| 810 | endfor |
| 811 | |
| 812 | if cmd_line == -1 |
| 813 | call assert_report('Command line not found in terminal output') |
| 814 | else |
| 815 | let next_line = -1 |
| 816 | for i in range(cmd_line + 1, len(lines)) |
| 817 | if lines[i] =~ '\S' |
| 818 | let next_line = i |
| 819 | break |
| 820 | endif |
| 821 | endfor |
| 822 | |
| 823 | if next_line == -1 |
| 824 | call assert_report('No prompt found after command execution') |
| 825 | else |
| 826 | call assert_equal(cmd_line + 1, next_line, 'Prompt should be on the immediate next line') |
| 827 | call assert_match('.*TEST_PROMPT>.*', lines[next_line], 'Line should contain the prompt PS1') |
| 828 | endif |
| 829 | endif |
| 830 | |
| 831 | " Clean up temp file and exit shell |
| 832 | call term_sendkeys(buf, "rm -f temp.txt\<CR>") |
| 833 | call term_sendkeys(buf, "exit\<CR>") |
| 834 | call TermWait(buf, 200) |
| 835 | |
| 836 | if job_status(term_getjob(buf)) ==# 'run' |
| 837 | call StopVimInTerminal(buf) |
| 838 | endif |
| 839 | |
| 840 | unlet $PS1 |
| 841 | endfunc |
| 842 | |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 843 | func Test_silent_ex_mode() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 844 | " must be able to get the output of Vim. |
| 845 | CheckUnix |
| 846 | CheckNotGui |
Bram Moolenaar | d5d3753 | 2017-03-27 23:02:07 +0200 | [diff] [blame] | 847 | |
| 848 | " This caused an ml_get error. |
| 849 | let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq') |
| 850 | call assert_notmatch('E315:', out) |
| 851 | endfunc |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 852 | |
| 853 | func Test_default_term() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 854 | " must be able to get the output of Vim. |
| 855 | CheckUnix |
| 856 | CheckNotGui |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 857 | |
| 858 | let save_term = $TERM |
Bram Moolenaar | 08f88b1 | 2017-04-02 17:21:16 +0200 | [diff] [blame] | 859 | let $TERM = 'unknownxxx' |
Bram Moolenaar | 85045a7 | 2017-04-02 16:54:09 +0200 | [diff] [blame] | 860 | let out = system(GetVimCommand() . ' -c''set term'' -c cq') |
| 861 | call assert_match("defaulting to 'ansi'", out) |
| 862 | let $TERM = save_term |
| 863 | endfunc |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 864 | |
| 865 | func Test_zzz_startinsert() |
| 866 | " Test :startinsert |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 867 | call writefile(['123456'], 'Xtestout', 'D') |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 868 | let after =<< trim [CODE] |
| 869 | :startinsert |
| 870 | call feedkeys("foobar\<c-o>:wq\<cr>","t") |
| 871 | [CODE] |
| 872 | |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 873 | if RunVim([], after, 'Xtestout') |
| 874 | let lines = readfile('Xtestout') |
| 875 | call assert_equal(['foobar123456'], lines) |
| 876 | endif |
| 877 | " Test :startinsert! |
| 878 | call writefile(['123456'], 'Xtestout') |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 879 | let after =<< trim [CODE] |
| 880 | :startinsert! |
| 881 | call feedkeys("foobar\<c-o>:wq\<cr>","t") |
| 882 | [CODE] |
| 883 | |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 884 | if RunVim([], after, 'Xtestout') |
| 885 | let lines = readfile('Xtestout') |
| 886 | call assert_equal(['123456foobar'], lines) |
| 887 | endif |
Bram Moolenaar | 09ca932 | 2017-09-26 17:40:45 +0200 | [diff] [blame] | 888 | endfunc |
Bram Moolenaar | 97c2c05 | 2019-02-22 13:42:07 +0100 | [diff] [blame] | 889 | |
| 890 | func Test_issue_3969() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 891 | " Can't catch the output of gvim. |
| 892 | CheckNotGui |
| 893 | |
Bram Moolenaar | 97c2c05 | 2019-02-22 13:42:07 +0100 | [diff] [blame] | 894 | " Check that message is not truncated. |
| 895 | let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq') |
| 896 | call assert_equal('hello', out) |
| 897 | endfunc |
Bram Moolenaar | c75e812 | 2019-04-21 15:55:10 +0200 | [diff] [blame] | 898 | |
| 899 | func Test_start_with_tabs() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 900 | CheckScreendump |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 901 | CheckRunVimInTerminal |
Bram Moolenaar | c75e812 | 2019-04-21 15:55:10 +0200 | [diff] [blame] | 902 | |
| 903 | let buf = RunVimInTerminal('-p a b c', {}) |
| 904 | call VerifyScreenDump(buf, 'Test_start_with_tabs', {}) |
| 905 | |
| 906 | " clean up |
| 907 | call StopVimInTerminal(buf) |
| 908 | endfunc |
Bram Moolenaar | 69bf634 | 2019-10-29 04:16:57 +0100 | [diff] [blame] | 909 | |
Bram Moolenaar | d1f34e6 | 2022-01-07 19:24:20 +0000 | [diff] [blame] | 910 | func Test_start_in_minimal_window() |
| 911 | CheckRunVimInTerminal |
| 912 | |
| 913 | let buf = RunVimInTerminal('-c "set nomore"', {'cols': 12, 'rows': 2, 'keep_t_u7': 1}) |
| 914 | call term_sendkeys(buf, "ahello\<Esc>") |
| 915 | call WaitForAssert({-> assert_match('^hello', term_getline(buf, 1))}) |
| 916 | |
| 917 | " clean up |
| 918 | call StopVimInTerminal(buf) |
| 919 | endfunc |
| 920 | |
Bram Moolenaar | 69bf634 | 2019-10-29 04:16:57 +0100 | [diff] [blame] | 921 | func Test_v_argv() |
| 922 | " Can't catch the output of gvim. |
| 923 | CheckNotGui |
| 924 | |
| 925 | let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q') |
| 926 | let list = out->split("', '") |
| 927 | call assert_match('vim', list[0]) |
| 928 | let idx = index(list, 'arg1') |
| 929 | call assert_true(idx > 2) |
| 930 | call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:]) |
| 931 | endfunc |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 932 | |
| 933 | " Test for the "-r" recovery mode option |
| 934 | func Test_r_arg() |
| 935 | " Can't catch the output of gvim. |
| 936 | CheckNotGui |
| 937 | CheckUnix |
| 938 | CheckEnglish |
| 939 | let cmd = GetVimCommand() |
| 940 | " There can be swap files anywhere, only check for the headers. |
| 941 | let expected =<< trim END |
| 942 | Swap files found:.* |
| 943 | In current directory:.* |
| 944 | In directory \~/tmp:.* |
| 945 | In directory /var/tmp:.* |
| 946 | In directory /tmp:.* |
| 947 | END |
| 948 | call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', '')) |
| 949 | endfunc |
| 950 | |
| 951 | " Test for the '-t' option to jump to a tag |
| 952 | func Test_t_arg() |
| 953 | let before =<< trim [CODE] |
| 954 | set tags=Xtags |
| 955 | [CODE] |
| 956 | let after =<< trim [CODE] |
| 957 | let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.') |
| 958 | call writefile([s], "Xtestout") |
| 959 | qall |
| 960 | [CODE] |
| 961 | |
| 962 | call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", |
| 963 | \ "first\tXfile1\t/^ \\zsfirst$/", |
| 964 | \ "second\tXfile1\t/^ \\zssecond$/", |
| 965 | \ "third\tXfile1\t/^ \\zsthird$/"], |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 966 | \ 'Xtags', 'D') |
| 967 | call writefile([' first', ' second', ' third'], 'Xfile1', 'D') |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 968 | |
Bram Moolenaar | a2b3e7d | 2021-03-26 17:24:34 +0100 | [diff] [blame] | 969 | for t_arg in ['-t second', '-tsecond'] |
Dominique Pelle | d176ca3 | 2021-09-09 20:45:34 +0200 | [diff] [blame] | 970 | if RunVim(before, after, t_arg) |
Bram Moolenaar | a2b3e7d | 2021-03-26 17:24:34 +0100 | [diff] [blame] | 971 | call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'), t_arg) |
| 972 | call delete('Xtestout') |
| 973 | endif |
| 974 | endfor |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 975 | endfunc |
| 976 | |
Bram Moolenaar | 1f33e0a | 2020-12-19 13:32:07 +0100 | [diff] [blame] | 977 | " Test the '-T' argument which sets the 'term' option. |
| 978 | func Test_T_arg() |
| 979 | CheckNotGui |
| 980 | let after =<< trim [CODE] |
| 981 | call writefile([&term], "Xtest_T_arg") |
| 982 | qall |
| 983 | [CODE] |
| 984 | |
| 985 | for t in ['builtin_dumb', 'builtin_ansi'] |
| 986 | if RunVim([], after, '-T ' .. t) |
| 987 | let lines = readfile('Xtest_T_arg') |
| 988 | call assert_equal([t], lines) |
| 989 | endif |
| 990 | endfor |
| 991 | |
| 992 | call delete('Xtest_T_arg') |
| 993 | endfunc |
| 994 | |
| 995 | " Test the '-x' argument to read/write encrypted files. |
| 996 | func Test_x_arg() |
| 997 | CheckRunVimInTerminal |
| 998 | CheckFeature cryptv |
| 999 | |
| 1000 | " Create an encrypted file Xtest_x_arg. |
| 1001 | let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0}) |
| 1002 | call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))}) |
| 1003 | call term_sendkeys(buf, "foo\n") |
| 1004 | call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))}) |
| 1005 | call term_sendkeys(buf, "foo\n") |
| 1006 | call WaitForAssert({-> assert_match(' All$', term_getline(buf, 10))}) |
| 1007 | call term_sendkeys(buf, "itest\<Esc>:w\<Enter>") |
| 1008 | call WaitForAssert({-> assert_match('"Xtest_x_arg" \[New\]\[blowfish2\] 1L, 5B written', |
| 1009 | \ term_getline(buf, 10))}) |
| 1010 | call StopVimInTerminal(buf) |
| 1011 | |
| 1012 | " Read the encrypted file and check that it contains the expected content "test" |
| 1013 | let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0}) |
| 1014 | call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))}) |
| 1015 | call term_sendkeys(buf, "foo\n") |
| 1016 | call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))}) |
| 1017 | call term_sendkeys(buf, "foo\n") |
| 1018 | call WaitForAssert({-> assert_match('^test', term_getline(buf, 1))}) |
| 1019 | call StopVimInTerminal(buf) |
| 1020 | |
| 1021 | call delete('Xtest_x_arg') |
| 1022 | endfunc |
| 1023 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1024 | " Test for entering the insert mode on startup |
| 1025 | func Test_start_insertmode() |
| 1026 | let before =<< trim [CODE] |
| 1027 | set insertmode |
| 1028 | [CODE] |
| 1029 | let after =<< trim [CODE] |
| 1030 | call writefile(['insertmode=' .. &insertmode], 'Xtestout') |
| 1031 | qall |
| 1032 | [CODE] |
| 1033 | if RunVim(before, after, '') |
| 1034 | call assert_equal(['insertmode=1'], readfile('Xtestout')) |
| 1035 | call delete('Xtestout') |
| 1036 | endif |
| 1037 | endfunc |
| 1038 | |
| 1039 | " Test for enabling the binary mode on startup |
| 1040 | func Test_b_arg() |
| 1041 | let after =<< trim [CODE] |
| 1042 | call writefile(['binary=' .. &binary], 'Xtestout') |
| 1043 | qall |
| 1044 | [CODE] |
| 1045 | if RunVim([], after, '-b') |
| 1046 | call assert_equal(['binary=1'], readfile('Xtestout')) |
| 1047 | call delete('Xtestout') |
| 1048 | endif |
| 1049 | endfunc |
| 1050 | |
| 1051 | " Test for enabling the lisp mode on startup |
| 1052 | func Test_l_arg() |
| 1053 | let after =<< trim [CODE] |
| 1054 | let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch |
| 1055 | call writefile([s], 'Xtestout') |
| 1056 | qall |
| 1057 | [CODE] |
| 1058 | if RunVim([], after, '-l') |
| 1059 | call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout')) |
| 1060 | call delete('Xtestout') |
| 1061 | endif |
| 1062 | endfunc |
| 1063 | |
| 1064 | " Test for specifying a non-existing vimrc file using "-u" |
| 1065 | func Test_missing_vimrc() |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 1066 | CheckRunVimInTerminal |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1067 | let after =<< trim [CODE] |
| 1068 | call assert_match('^E282:', v:errmsg) |
| 1069 | call writefile(v:errors, 'Xtestout') |
| 1070 | [CODE] |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1071 | call writefile(after, 'Xafter', 'D') |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1072 | |
| 1073 | let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter' |
| 1074 | let buf = term_start(cmd, {'term_rows' : 10}) |
| 1075 | call WaitForAssert({-> assert_equal("running", term_getstatus(buf))}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 1076 | call TermWait(buf) |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1077 | call term_sendkeys(buf, "\n:") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 1078 | call TermWait(buf) |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1079 | call WaitForAssert({-> assert_match(':', term_getline(buf, 10))}) |
| 1080 | call StopVimInTerminal(buf) |
| 1081 | call assert_equal([], readfile('Xtestout')) |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1082 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1083 | call delete('Xtestout') |
| 1084 | endfunc |
| 1085 | |
| 1086 | " Test for using the $VIMINIT environment variable |
| 1087 | func Test_VIMINIT() |
| 1088 | let after =<< trim [CODE] |
| 1089 | call assert_equal(1, exists('viminit_found')) |
| 1090 | call assert_equal('yes', viminit_found) |
| 1091 | call writefile(v:errors, 'Xtestout') |
| 1092 | qall |
| 1093 | [CODE] |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1094 | call writefile(after, 'Xafter', 'D') |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1095 | let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' |
| 1096 | call setenv('VIMINIT', 'let viminit_found="yes"') |
| 1097 | exe "silent !" . cmd |
| 1098 | call assert_equal([], readfile('Xtestout')) |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1099 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1100 | call delete('Xtestout') |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1101 | endfunc |
| 1102 | |
| 1103 | " Test for using the $EXINIT environment variable |
| 1104 | func Test_EXINIT() |
| 1105 | let after =<< trim [CODE] |
| 1106 | call assert_equal(1, exists('exinit_found')) |
| 1107 | call assert_equal('yes', exinit_found) |
| 1108 | call writefile(v:errors, 'Xtestout') |
| 1109 | qall |
| 1110 | [CODE] |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1111 | call writefile(after, 'Xafter', 'D') |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1112 | let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' |
Christian Brabandt | 28155d0 | 2025-02-23 19:55:09 +0100 | [diff] [blame] | 1113 | call setenv('HOME', '/non-existing') |
| 1114 | call setenv('XDG_CONFIG_HOME', '/non-existing') |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1115 | call setenv('EXINIT', 'let exinit_found="yes"') |
| 1116 | exe "silent !" . cmd |
| 1117 | call assert_equal([], readfile('Xtestout')) |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1118 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1119 | call delete('Xtestout') |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1120 | endfunc |
| 1121 | |
| 1122 | " Test for using the 'exrc' option |
| 1123 | func Test_exrc() |
| 1124 | let after =<< trim [CODE] |
| 1125 | call assert_equal(1, &exrc) |
| 1126 | call assert_equal(1, &secure) |
| 1127 | call assert_equal(37, exrc_found) |
| 1128 | call writefile(v:errors, 'Xtestout') |
| 1129 | qall |
| 1130 | [CODE] |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1131 | call mkdir('Xrcdir', 'R') |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 1132 | call writefile(['let exrc_found=37'], 'Xrcdir/.exrc') |
| 1133 | call writefile(after, 'Xrcdir/Xafter') |
| 1134 | 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] | 1135 | exe "silent !" . cmd |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 1136 | call assert_equal([], readfile('Xrcdir/Xtestout')) |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1137 | endfunc |
| 1138 | |
| 1139 | " Test for starting Vim with a non-terminal as input/output |
| 1140 | func Test_io_not_a_terminal() |
| 1141 | " Can't catch the output of gvim. |
| 1142 | CheckNotGui |
| 1143 | CheckUnix |
| 1144 | CheckEnglish |
| 1145 | let l = systemlist(GetVimProg() .. ' --ttyfail') |
| 1146 | call assert_equal(['Vim: Warning: Output is not to a terminal', |
| 1147 | \ 'Vim: Warning: Input is not from a terminal'], l) |
| 1148 | endfunc |
| 1149 | |
Bram Moolenaar | 7007e31 | 2021-03-27 12:11:33 +0100 | [diff] [blame] | 1150 | " Test for --not-a-term avoiding escape codes. |
| 1151 | func Test_not_a_term() |
| 1152 | CheckUnix |
| 1153 | CheckNotGui |
| 1154 | |
| 1155 | if &shellredir =~ '%s' |
| 1156 | let redir = printf(&shellredir, 'Xvimout') |
| 1157 | else |
| 1158 | let redir = &shellredir .. ' Xvimout' |
| 1159 | endif |
| 1160 | |
| 1161 | " Without --not-a-term there are a few escape sequences. |
| 1162 | " This will take 2 seconds because of the missing --not-a-term |
| 1163 | let cmd = GetVimProg() .. ' --cmd quit ' .. redir |
| 1164 | exe "silent !" . cmd |
| 1165 | call assert_match("\<Esc>", readfile('Xvimout')->join()) |
| 1166 | call delete('Xvimout') |
| 1167 | |
| 1168 | " With --not-a-term there are no escape sequences. |
| 1169 | let cmd = GetVimProg() .. ' --not-a-term --cmd quit ' .. redir |
| 1170 | exe "silent !" . cmd |
| 1171 | call assert_notmatch("\<Esc>", readfile('Xvimout')->join()) |
| 1172 | call delete('Xvimout') |
| 1173 | endfunc |
| 1174 | |
Bram Moolenaar | 5939c35 | 2022-09-24 12:50:45 +0100 | [diff] [blame] | 1175 | " Test quitting with CTRL-C when output is redirected. |
| 1176 | func Test_redirect_Ctrl_C() |
| 1177 | CheckUnix |
| 1178 | CheckNotGui |
| 1179 | CheckRunVimInTerminal |
| 1180 | |
| 1181 | let buf = Run_shell_in_terminal({}) |
| 1182 | " Wait for the shell to display a prompt |
| 1183 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
| 1184 | |
| 1185 | call term_sendkeys(buf, GetVimProg() .. " | grep word\<CR>") |
| 1186 | call WaitForAssert({-> assert_match("Output is not to a terminal", getline(1, 4)->join())}) |
| 1187 | " wait for the hard coded delay, otherwise the CTRL-C interrupts startup |
| 1188 | sleep 2 |
| 1189 | call term_sendkeys(buf, "\<C-C>") |
| 1190 | sleep 100m |
| 1191 | call term_sendkeys(buf, "exit\<CR>") |
| 1192 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
| 1193 | |
| 1194 | exe buf . 'bwipe!' |
| 1195 | unlet g:job |
| 1196 | endfunc |
| 1197 | |
Bram Moolenaar | 7007e31 | 2021-03-27 12:11:33 +0100 | [diff] [blame] | 1198 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1199 | " Test for the "-w scriptout" argument |
| 1200 | func Test_w_arg() |
| 1201 | " Can't catch the output of gvim. |
| 1202 | CheckNotGui |
Bram Moolenaar | 0a1a6a1 | 2021-03-26 14:14:18 +0100 | [diff] [blame] | 1203 | |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1204 | call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'bD') |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1205 | if RunVim([], [], '-s Xscriptin -w Xscriptout') |
| 1206 | call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout')) |
| 1207 | call delete('Xscriptout') |
| 1208 | endif |
| 1209 | call delete('Xscriptin') |
| 1210 | |
| 1211 | " Test for failing to open the script output file. This test works only when |
| 1212 | " the language is English. |
| 1213 | if v:lang == "C" || v:lang =~ '^[Ee]n' |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 1214 | call mkdir("Xargdir") |
| 1215 | let m = system(GetVimCommand() .. " -w Xargdir") |
| 1216 | call assert_equal("Cannot open for script output: \"Xargdir\"\n", m) |
| 1217 | call delete("Xargdir", 'rf') |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1218 | endif |
Bram Moolenaar | 0a1a6a1 | 2021-03-26 14:14:18 +0100 | [diff] [blame] | 1219 | |
| 1220 | " A number argument sets the 'window' option |
| 1221 | 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] | 1222 | for w_arg in ['-w 17', '-w17'] |
| 1223 | if RunVim([], [], '-s Xscriptin ' .. w_arg) |
| 1224 | call assert_equal(["window 17"], readfile('Xresult'), w_arg) |
| 1225 | call delete('Xresult') |
| 1226 | endif |
| 1227 | endfor |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1228 | endfunc |
| 1229 | |
| 1230 | " Test for the "-s scriptin" argument |
| 1231 | func Test_s_arg() |
| 1232 | " Can't catch the output of gvim. |
| 1233 | CheckNotGui |
| 1234 | CheckEnglish |
| 1235 | " Test for failing to open the script input file. |
| 1236 | let m = system(GetVimCommand() .. " -s abcxyz") |
| 1237 | call assert_equal("Cannot open for reading: \"abcxyz\"\n", m) |
| 1238 | |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1239 | call writefile([], 'Xinput', 'D') |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1240 | let m = system(GetVimCommand() .. " -s Xinput -s Xinput") |
| 1241 | call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m) |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1242 | endfunc |
| 1243 | |
| 1244 | " Test for the "-n" (no swap file) argument |
| 1245 | func Test_n_arg() |
| 1246 | let after =<< trim [CODE] |
| 1247 | call assert_equal(0, &updatecount) |
| 1248 | call writefile(v:errors, 'Xtestout') |
| 1249 | qall |
| 1250 | [CODE] |
| 1251 | if RunVim([], after, '-n') |
| 1252 | call assert_equal([], readfile('Xtestout')) |
| 1253 | call delete('Xtestout') |
| 1254 | endif |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1255 | endfunc |
| 1256 | |
| 1257 | " Test for the "-h" (help) argument |
| 1258 | func Test_h_arg() |
| 1259 | " Can't catch the output of gvim. |
| 1260 | CheckNotGui |
| 1261 | let l = systemlist(GetVimProg() .. ' -h') |
| 1262 | call assert_match('^VIM - Vi IMproved', l[0]) |
| 1263 | let l = systemlist(GetVimProg() .. ' -?') |
| 1264 | call assert_match('^VIM - Vi IMproved', l[0]) |
| 1265 | endfunc |
| 1266 | |
| 1267 | " Test for the "-F" (farsi) argument |
| 1268 | func Test_F_arg() |
| 1269 | " Can't catch the output of gvim. |
| 1270 | CheckNotGui |
| 1271 | let l = systemlist(GetVimProg() .. ' -F') |
| 1272 | call assert_match('^E27:', l[0]) |
| 1273 | endfunc |
| 1274 | |
| 1275 | " Test for the "-E" (improved Ex mode) argument |
| 1276 | func Test_E_arg() |
| 1277 | let after =<< trim [CODE] |
| 1278 | call assert_equal('cv', mode(1)) |
| 1279 | call writefile(v:errors, 'Xtestout') |
| 1280 | qall |
| 1281 | [CODE] |
| 1282 | if RunVim([], after, '-E') |
| 1283 | call assert_equal([], readfile('Xtestout')) |
| 1284 | call delete('Xtestout') |
| 1285 | endif |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1286 | endfunc |
| 1287 | |
Bram Moolenaar | c5cf369 | 2021-03-20 22:16:56 +0100 | [diff] [blame] | 1288 | " Test for the "-D" (debugger) argument |
| 1289 | func Test_D_arg() |
| 1290 | CheckRunVimInTerminal |
| 1291 | |
| 1292 | let cmd = GetVimCommandCleanTerm() .. ' -D' |
| 1293 | let buf = term_start(cmd, {'term_rows' : 10}) |
| 1294 | call WaitForAssert({-> assert_equal("running", term_getstatus(buf))}) |
| 1295 | |
| 1296 | call WaitForAssert({-> assert_equal('Entering Debug mode. Type "cont" to continue.', |
| 1297 | \ term_getline(buf, 7))}) |
| 1298 | call WaitForAssert({-> assert_equal('>', term_getline(buf, 10))}) |
| 1299 | |
| 1300 | call StopVimInTerminal(buf) |
| 1301 | endfunc |
| 1302 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1303 | " Test for too many edit argument errors |
| 1304 | func Test_too_many_edit_args() |
| 1305 | " Can't catch the output of gvim. |
| 1306 | CheckNotGui |
| 1307 | CheckEnglish |
| 1308 | let l = systemlist(GetVimProg() .. ' - -') |
| 1309 | call assert_match('^Too many edit arguments: "-"', l[1]) |
| 1310 | endfunc |
| 1311 | |
Bram Moolenaar | df4c9af | 2021-01-11 19:54:42 +0100 | [diff] [blame] | 1312 | " Test starting vim with various names: vim, ex, view, evim, etc. |
| 1313 | func Test_progname() |
| 1314 | CheckUnix |
| 1315 | |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1316 | call mkdir('Xprogname', 'pD') |
Bram Moolenaar | df4c9af | 2021-01-11 19:54:42 +0100 | [diff] [blame] | 1317 | call writefile(['silent !date', |
| 1318 | \ 'call writefile([mode(1), ' |
| 1319 | \ .. '&insertmode, &diff, &readonly, &updatecount, ' |
| 1320 | \ .. 'join(split(execute("message"), "\n")[1:])], "Xprogname_out")', |
| 1321 | \ 'qall'], 'Xprogname_after') |
| 1322 | |
| 1323 | " +---------------------------------------------- progname |
| 1324 | " | +--------------------------------- mode(1) |
| 1325 | " | | +--------------------------- &insertmode |
| 1326 | " | | | +---------------------- &diff |
| 1327 | " | | | | +----------------- &readonly |
| 1328 | " | | | | | +-------- &updatecount |
| 1329 | " | | | | | | +--- :messages |
| 1330 | " | | | | | | | |
| 1331 | let expectations = { |
| 1332 | \ 'vim': ['n', '0', '0', '0', '200', ''], |
| 1333 | \ 'gvim': ['n', '0', '0', '0', '200', ''], |
| 1334 | \ 'ex': ['ce', '0', '0', '0', '200', ''], |
| 1335 | \ 'exim': ['cv', '0', '0', '0', '200', ''], |
| 1336 | \ 'view': ['n', '0', '0', '1', '10000', ''], |
| 1337 | \ 'gview': ['n', '0', '0', '1', '10000', ''], |
| 1338 | \ 'evim': ['n', '1', '0', '0', '200', ''], |
| 1339 | \ 'eview': ['n', '1', '0', '1', '10000', ''], |
| 1340 | \ 'rvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], |
| 1341 | \ 'rgvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], |
| 1342 | \ 'rview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], |
| 1343 | \ 'rgview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'], |
| 1344 | \ 'vimdiff': ['n', '0', '1', '0', '200', ''], |
| 1345 | \ 'gvimdiff': ['n', '0', '1', '0', '200', '']} |
| 1346 | |
| 1347 | let prognames = ['vim', 'gvim', 'ex', 'exim', 'view', 'gview', |
| 1348 | \ 'evim', 'eview', 'rvim', 'rgvim', 'rview', 'rgview', |
| 1349 | \ 'vimdiff', 'gvimdiff'] |
| 1350 | |
| 1351 | for progname in prognames |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 1352 | let run_with_gui = (progname =~# 'g') || (has('gui') && (progname ==# 'evim' || progname ==# 'eview')) |
| 1353 | |
| 1354 | if empty($DISPLAY) && run_with_gui |
| 1355 | " Can't run gvim, gview (etc.) if $DISPLAY is not setup. |
| 1356 | continue |
Bram Moolenaar | df4c9af | 2021-01-11 19:54:42 +0100 | [diff] [blame] | 1357 | endif |
| 1358 | |
| 1359 | exe 'silent !ln -s -f ' ..exepath(GetVimProg()) .. ' Xprogname/' .. progname |
| 1360 | |
| 1361 | let stdout_stderr = '' |
| 1362 | if progname =~# 'g' |
| 1363 | let stdout_stderr = system('Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after') |
| 1364 | else |
| 1365 | exe 'sil !Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after' |
| 1366 | endif |
| 1367 | |
| 1368 | if progname =~# 'g' && !has('gui') |
| 1369 | call assert_equal("E25: GUI cannot be used: Not enabled at compile time\n", stdout_stderr, progname) |
| 1370 | else |
Bram Moolenaar | 240309c | 2021-03-14 16:20:37 +0100 | [diff] [blame] | 1371 | " GUI motif can output some warnings like this: |
| 1372 | " Warning: |
| 1373 | " Name: subMenu |
| 1374 | " Class: XmCascadeButton |
| 1375 | " Illegal mnemonic character; Could not convert X KEYSYM to a keycode |
| 1376 | " So don't check that stderr is empty with GUI Motif. |
| 1377 | if run_with_gui && !has('gui_motif') |
| 1378 | call assert_equal('', stdout_stderr, progname) |
| 1379 | endif |
Bram Moolenaar | df4c9af | 2021-01-11 19:54:42 +0100 | [diff] [blame] | 1380 | call assert_equal(expectations[progname], readfile('Xprogname_out'), progname) |
| 1381 | endif |
| 1382 | |
| 1383 | call delete('Xprogname/' .. progname) |
| 1384 | call delete('Xprogname_out') |
| 1385 | endfor |
| 1386 | |
| 1387 | call delete('Xprogname_after') |
Bram Moolenaar | df4c9af | 2021-01-11 19:54:42 +0100 | [diff] [blame] | 1388 | endfunc |
| 1389 | |
Yegappan Lakshmanan | 36f96a5 | 2021-05-13 18:33:16 +0200 | [diff] [blame] | 1390 | " Test for doing a write from .vimrc |
| 1391 | func Test_write_in_vimrc() |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1392 | call writefile(['silent! write'], 'Xvimrc', 'D') |
Yegappan Lakshmanan | 36f96a5 | 2021-05-13 18:33:16 +0200 | [diff] [blame] | 1393 | let after =<< trim [CODE] |
| 1394 | call assert_match('E32: ', v:errmsg) |
| 1395 | call writefile(v:errors, 'Xtestout') |
| 1396 | qall |
| 1397 | [CODE] |
| 1398 | if RunVim([], after, '-u Xvimrc') |
| 1399 | call assert_equal([], readfile('Xtestout')) |
| 1400 | call delete('Xtestout') |
| 1401 | endif |
Yegappan Lakshmanan | 36f96a5 | 2021-05-13 18:33:16 +0200 | [diff] [blame] | 1402 | endfunc |
| 1403 | |
Bram Moolenaar | a97c363 | 2021-06-15 22:39:11 +0200 | [diff] [blame] | 1404 | func Test_echo_true_in_cmd() |
Bram Moolenaar | b90ac5e | 2021-06-16 10:59:36 +0200 | [diff] [blame] | 1405 | CheckNotGui |
| 1406 | |
Bram Moolenaar | a97c363 | 2021-06-15 22:39:11 +0200 | [diff] [blame] | 1407 | let lines =<< trim END |
| 1408 | echo v:true |
| 1409 | call writefile(['done'], 'Xresult') |
Bram Moolenaar | 55b6b60 | 2021-06-15 23:05:59 +0200 | [diff] [blame] | 1410 | quit |
Bram Moolenaar | a97c363 | 2021-06-15 22:39:11 +0200 | [diff] [blame] | 1411 | END |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1412 | call writefile(lines, 'Xscript', 'D') |
Bram Moolenaar | 55b6b60 | 2021-06-15 23:05:59 +0200 | [diff] [blame] | 1413 | if RunVim([], [], '--cmd "source Xscript"') |
Bram Moolenaar | a97c363 | 2021-06-15 22:39:11 +0200 | [diff] [blame] | 1414 | call assert_equal(['done'], readfile('Xresult')) |
| 1415 | endif |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1416 | |
Bram Moolenaar | a97c363 | 2021-06-15 22:39:11 +0200 | [diff] [blame] | 1417 | call delete('Xresult') |
Bram Moolenaar | a97c363 | 2021-06-15 22:39:11 +0200 | [diff] [blame] | 1418 | endfunc |
| 1419 | |
Bram Moolenaar | d3710cf | 2021-10-04 23:13:13 +0100 | [diff] [blame] | 1420 | func Test_rename_buffer_on_startup() |
Bram Moolenaar | 6d19798 | 2021-10-05 01:19:53 +0100 | [diff] [blame] | 1421 | CheckUnix |
| 1422 | |
Bram Moolenaar | d3710cf | 2021-10-04 23:13:13 +0100 | [diff] [blame] | 1423 | let lines =<< trim END |
| 1424 | call writefile(['done'], 'Xresult') |
| 1425 | qa! |
| 1426 | END |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1427 | call writefile(lines, 'Xscript', 'D') |
Bram Moolenaar | d3710cf | 2021-10-04 23:13:13 +0100 | [diff] [blame] | 1428 | if RunVim([], [], "--clean -e -s --cmd 'file x|new|file x' --cmd 'so Xscript'") |
| 1429 | call assert_equal(['done'], readfile('Xresult')) |
| 1430 | endif |
Bram Moolenaar | 5656496 | 2022-10-10 22:39:42 +0100 | [diff] [blame] | 1431 | |
Bram Moolenaar | d3710cf | 2021-10-04 23:13:13 +0100 | [diff] [blame] | 1432 | call delete('Xresult') |
| 1433 | endfunc |
| 1434 | |
Christian Brabandt | ba9aed4 | 2023-10-14 11:38:12 +0200 | [diff] [blame] | 1435 | " Test that -cq works as expected |
| 1436 | func Test_cq_zero_exmode() |
Christian Brabandt | c290009 | 2023-10-17 18:10:13 +0200 | [diff] [blame] | 1437 | CheckFeature channel |
| 1438 | |
Christian Brabandt | ba9aed4 | 2023-10-14 11:38:12 +0200 | [diff] [blame] | 1439 | let logfile = 'Xcq_log.txt' |
| 1440 | let out = system(GetVimCommand() .. ' --clean --log ' .. logfile .. ' -es -X -c "argdelete foobar" -c"7cq"') |
| 1441 | call assert_equal(8, v:shell_error) |
zeertzjq | 67fe77d | 2025-04-20 10:21:18 +0200 | [diff] [blame] | 1442 | let log = filter(readfile(logfile), {idx, val -> val =~ "E480:"}) |
Christian Brabandt | ba9aed4 | 2023-10-14 11:38:12 +0200 | [diff] [blame] | 1443 | call assert_match('E480: No match: foobar', log[0]) |
| 1444 | call delete(logfile) |
| 1445 | |
| 1446 | " wrap-around on Unix |
| 1447 | let out = system(GetVimCommand() .. ' --clean --log ' .. logfile .. ' -es -X -c "argdelete foobar" -c"255cq"') |
| 1448 | if !has('win32') |
| 1449 | call assert_equal(0, v:shell_error) |
| 1450 | else |
| 1451 | call assert_equal(256, v:shell_error) |
| 1452 | endif |
zeertzjq | 67fe77d | 2025-04-20 10:21:18 +0200 | [diff] [blame] | 1453 | let log = filter(readfile(logfile), {idx, val -> val =~ "E480:"}) |
Christian Brabandt | ba9aed4 | 2023-10-14 11:38:12 +0200 | [diff] [blame] | 1454 | call assert_match('E480: No match: foobar', log[0]) |
| 1455 | call delete('Xcq_log.txt') |
| 1456 | endfunc |
Bram Moolenaar | d3710cf | 2021-10-04 23:13:13 +0100 | [diff] [blame] | 1457 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1458 | " vim: shiftwidth=2 sts=2 expandtab |