1" Tests for various Ex commands. 2 3source check.vim 4 5func Test_ex_delete() 6 new 7 call setline(1, ['a', 'b', 'c']) 8 2 9 " :dl is :delete with the "l" flag, not :dlist 10 .dl 11 call assert_equal(['a', 'c'], getline(1, 2)) 12endfunc 13 14func Test_range_error() 15 call assert_fails(':.echo 1', 'E481:') 16 call assert_fails(':$echo 1', 'E481:') 17 call assert_fails(':1,2echo 1', 'E481:') 18 call assert_fails(':+1echo 1', 'E481:') 19 call assert_fails(':/1/echo 1', 'E481:') 20 call assert_fails(':\/echo 1', 'E481:') 21 normal vv 22 call assert_fails(":'<,'>echo 1", 'E481:') 23 call assert_fails(":\\xcenter", 'E10:') 24endfunc 25 26func Test_buffers_lastused() 27 call test_settime(localtime() - 2000) " middle 28 edit bufa 29 enew 30 call test_settime(localtime() - 10) " newest 31 edit bufb 32 enew 33 call test_settime(1550010000) " oldest 34 edit bufc 35 enew 36 call test_settime(0) 37 enew 38 39 let ls = split(execute('buffers t', 'silent!'), '\n') 40 let bufs = ls->map({i,v->split(v, '"\s*')[1:2]}) 41 call assert_equal(['bufb', 'bufa', 'bufc'], bufs[1:]->map({i,v->v[0]})) 42 call assert_match('1[0-3] seconds ago', bufs[1][1]) 43 call assert_match('\d\d:\d\d:\d\d', bufs[2][1]) 44 call assert_match('2019/02/1\d \d\d:\d\d:00', bufs[3][1]) 45 46 bwipeout bufa 47 bwipeout bufb 48 bwipeout bufc 49endfunc 50 51" Test for the :copy command 52func Test_copy() 53 new 54 55 call setline(1, ['L1', 'L2', 'L3', 'L4']) 56 " copy lines in a range to inside the range 57 1,3copy 2 58 call assert_equal(['L1', 'L2', 'L1', 'L2', 'L3', 'L3', 'L4'], getline(1, 7)) 59 60 " Specifying a count before using : to run an ex-command 61 exe "normal! gg4:yank\<CR>" 62 call assert_equal("L1\nL2\nL1\nL2\n", @") 63 64 close! 65endfunc 66 67" Test for the :file command 68func Test_file_cmd() 69 call assert_fails('3file', 'E474:') 70 call assert_fails('0,0file', 'E474:') 71 call assert_fails('0file abc', 'E474:') 72 if !has('win32') 73 " Change the name of the buffer to the same name 74 new Xfile1 75 file Xfile1 76 call assert_equal('Xfile1', @%) 77 call assert_equal('Xfile1', @#) 78 bw! 79 endif 80endfunc 81 82" Test for the :drop command 83func Test_drop_cmd() 84 call writefile(['L1', 'L2'], 'Xfile') 85 enew | only 86 drop Xfile 87 call assert_equal('L2', getline(2)) 88 " Test for switching to an existing window 89 below new 90 drop Xfile 91 call assert_equal(1, winnr()) 92 " Test for splitting the current window 93 enew | only 94 set modified 95 drop Xfile 96 call assert_equal(2, winnr('$')) 97 " Check for setting the argument list 98 call assert_equal(['Xfile'], argv()) 99 enew | only! 100 call delete('Xfile') 101endfunc 102 103" Test for the :append command 104func Test_append_cmd() 105 new 106 call setline(1, [' L1']) 107 call feedkeys(":append\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') 108 call assert_equal([' L1', ' L2', ' L3'], getline(1, '$')) 109 %delete _ 110 " append after a specific line 111 call setline(1, [' L1', ' L2', ' L3']) 112 call feedkeys(":2append\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') 113 call assert_equal([' L1', ' L2', ' L4', ' L5', ' L3'], getline(1, '$')) 114 %delete _ 115 " append with toggling 'autoindent' 116 call setline(1, [' L1']) 117 call feedkeys(":append!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') 118 call assert_equal([' L1', ' L2', ' L3'], getline(1, '$')) 119 call assert_false(&autoindent) 120 %delete _ 121 " append with 'autoindent' set and toggling 'autoindent' 122 set autoindent 123 call setline(1, [' L1']) 124 call feedkeys(":append!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') 125 call assert_equal([' L1', ' L2', ' L3'], getline(1, '$')) 126 call assert_true(&autoindent) 127 set autoindent& 128 close! 129endfunc 130 131" Test for the :insert command 132func Test_insert_cmd() 133 new 134 call setline(1, [' L1']) 135 call feedkeys(":insert\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') 136 call assert_equal([' L2', ' L3', ' L1'], getline(1, '$')) 137 %delete _ 138 " insert before a specific line 139 call setline(1, [' L1', ' L2', ' L3']) 140 call feedkeys(":2insert\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') 141 call assert_equal([' L1', ' L4', ' L5', ' L2', ' L3'], getline(1, '$')) 142 %delete _ 143 " insert with toggling 'autoindent' 144 call setline(1, [' L1']) 145 call feedkeys(":insert!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') 146 call assert_equal([' L2', ' L3', ' L1'], getline(1, '$')) 147 call assert_false(&autoindent) 148 %delete _ 149 " insert with 'autoindent' set and toggling 'autoindent' 150 set autoindent 151 call setline(1, [' L1']) 152 call feedkeys(":insert!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') 153 call assert_equal([' L2', ' L3', ' L1'], getline(1, '$')) 154 call assert_true(&autoindent) 155 set autoindent& 156 close! 157endfunc 158 159" Test for the :change command 160func Test_change_cmd() 161 new 162 call setline(1, [' L1', 'L2', 'L3']) 163 call feedkeys(":change\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') 164 call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$')) 165 %delete _ 166 " change a specific line 167 call setline(1, [' L1', ' L2', ' L3']) 168 call feedkeys(":2change\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') 169 call assert_equal([' L1', ' L4', ' L5', ' L3'], getline(1, '$')) 170 %delete _ 171 " change with toggling 'autoindent' 172 call setline(1, [' L1', 'L2', 'L3']) 173 call feedkeys(":change!\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') 174 call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$')) 175 call assert_false(&autoindent) 176 %delete _ 177 " change with 'autoindent' set and toggling 'autoindent' 178 set autoindent 179 call setline(1, [' L1', 'L2', 'L3']) 180 call feedkeys(":change!\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') 181 call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$')) 182 call assert_true(&autoindent) 183 set autoindent& 184 close! 185endfunc 186 187" Test for the :language command 188func Test_language_cmd() 189 CheckFeature multi_lang 190 191 call assert_fails('language ctype non_existing_lang', 'E197:') 192 call assert_fails('language time non_existing_lang', 'E197:') 193endfunc 194 195" Test for the :confirm command dialog 196func Test_confirm_cmd() 197 CheckNotGui 198 CheckRunVimInTerminal 199 200 call writefile(['foo1'], 'Xfoo') 201 call writefile(['bar1'], 'Xbar') 202 203 " Test for saving all the modified buffers 204 let lines =<< trim END 205 set nomore 206 new Xfoo 207 call setline(1, 'foo2') 208 new Xbar 209 call setline(1, 'bar2') 210 wincmd b 211 END 212 call writefile(lines, 'Xscript') 213 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 214 call term_sendkeys(buf, ":confirm qall\n") 215 call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) 216 call term_sendkeys(buf, "A") 217 call StopVimInTerminal(buf) 218 219 call assert_equal(['foo2'], readfile('Xfoo')) 220 call assert_equal(['bar2'], readfile('Xbar')) 221 222 " Test for discarding all the changes to modified buffers 223 let lines =<< trim END 224 set nomore 225 new Xfoo 226 call setline(1, 'foo3') 227 new Xbar 228 call setline(1, 'bar3') 229 wincmd b 230 END 231 call writefile(lines, 'Xscript') 232 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 233 call term_sendkeys(buf, ":confirm qall\n") 234 call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) 235 call term_sendkeys(buf, "D") 236 call StopVimInTerminal(buf) 237 238 call assert_equal(['foo2'], readfile('Xfoo')) 239 call assert_equal(['bar2'], readfile('Xbar')) 240 241 " Test for saving and discarding changes to some buffers 242 let lines =<< trim END 243 set nomore 244 new Xfoo 245 call setline(1, 'foo4') 246 new Xbar 247 call setline(1, 'bar4') 248 wincmd b 249 END 250 call writefile(lines, 'Xscript') 251 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 252 call term_sendkeys(buf, ":confirm qall\n") 253 call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) 254 call term_sendkeys(buf, "N") 255 call WaitForAssert({-> assert_match('\[Y\]es, (N)o, (C)ancel: ', term_getline(buf, 20))}, 1000) 256 call term_sendkeys(buf, "Y") 257 call StopVimInTerminal(buf) 258 259 call assert_equal(['foo4'], readfile('Xfoo')) 260 call assert_equal(['bar2'], readfile('Xbar')) 261 262 call delete('Xscript') 263 call delete('Xfoo') 264 call delete('Xbar') 265endfunc 266 267func Test_confirm_cmd_cancel() 268 CheckNotGui 269 CheckRunVimInTerminal 270 271 " Test for closing a window with a modified buffer 272 let lines =<< trim END 273 set nomore 274 new 275 call setline(1, 'abc') 276 END 277 call writefile(lines, 'Xscript') 278 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 279 call term_sendkeys(buf, ":confirm close\n") 280 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', 281 \ term_getline(buf, 20))}, 1000) 282 call term_sendkeys(buf, "C") 283 call WaitForAssert({-> assert_equal('', term_getline(buf, 20))}, 1000) 284 call term_sendkeys(buf, ":confirm close\n") 285 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', 286 \ term_getline(buf, 20))}, 1000) 287 call term_sendkeys(buf, "N") 288 call WaitForAssert({-> assert_match('^ *0,0-1 All$', 289 \ term_getline(buf, 20))}, 1000) 290 call StopVimInTerminal(buf) 291 call delete('Xscript') 292endfunc 293 294" The ":confirm" prompt was sometimes used with the terminal in cooked mode. 295" This test verifies that a "\<CR>" character is NOT required to respond to a 296" prompt from the ":conf q" and ":conf wq" commands. 297func Test_confirm_q_wq() 298 CheckNotGui 299 CheckRunVimInTerminal 300 301 call writefile(['foo'], 'Xfoo') 302 303 let lines =<< trim END 304 set hidden nomore 305 call setline(1, 'abc') 306 edit Xfoo 307 END 308 call writefile(lines, 'Xscript') 309 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 310 call term_sendkeys(buf, ":confirm q\n") 311 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', 312 \ term_getline(buf, 20))}, 1000) 313 call term_sendkeys(buf, 'C') 314 call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$', 315 \ term_getline(buf, 20))}, 1000) 316 317 call term_sendkeys(buf, ":edit Xfoo\n") 318 call term_sendkeys(buf, ":confirm wq\n") 319 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', 320 \ term_getline(buf, 20))}, 1000) 321 call term_sendkeys(buf, 'C') 322 call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$', 323 \ term_getline(buf, 20))}, 1000) 324 call StopVimInTerminal(buf) 325 326 call delete('Xscript') 327 call delete('Xfoo') 328endfunc 329 330func Test_confirm_write_ro() 331 CheckNotGui 332 CheckRunVimInTerminal 333 334 call writefile(['foo'], 'Xconfirm_write_ro') 335 let lines =<< trim END 336 set nobackup ff=unix cmdheight=2 337 edit Xconfirm_write_ro 338 norm Abar 339 END 340 call writefile(lines, 'Xscript') 341 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 342 343 " Try to write with 'ro' option. 344 call term_sendkeys(buf, ":set ro | confirm w\n") 345 call WaitForAssert({-> assert_match("^'readonly' option is set for \"Xconfirm_write_ro\"\. *$", 346 \ term_getline(buf, 18))}, 1000) 347 call WaitForAssert({-> assert_match('^Do you wish to write anyway? *$', 348 \ term_getline(buf, 19))}, 1000) 349 call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', term_getline(buf, 20))}, 1000) 350 call term_sendkeys(buf, 'N') 351 call WaitForAssert({-> assert_match('^ *$', term_getline(buf, 19))}, 1000) 352 call WaitForAssert({-> assert_match('.* All$', term_getline(buf, 20))}, 1000) 353 call assert_equal(['foo'], readfile('Xconfirm_write_ro')) 354 355 call term_sendkeys(buf, ":confirm w\n") 356 call WaitForAssert({-> assert_match("^'readonly' option is set for \"Xconfirm_write_ro\"\. *$", 357 \ term_getline(buf, 18))}, 1000) 358 call WaitForAssert({-> assert_match('^Do you wish to write anyway? *$', 359 \ term_getline(buf, 19))}, 1000) 360 call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', term_getline(buf, 20))}, 1000) 361 call term_sendkeys(buf, 'Y') 362 call WaitForAssert({-> assert_match('^"Xconfirm_write_ro" 1L, 7B written$', 363 \ term_getline(buf, 19))}, 1000) 364 call assert_equal(['foobar'], readfile('Xconfirm_write_ro')) 365 366 " Try to write with read-only file permissions. 367 call setfperm('Xconfirm_write_ro', 'r--r--r--') 368 call term_sendkeys(buf, ":set noro | undo | confirm w\n") 369 call WaitForAssert({-> assert_match("^File permissions of \"Xconfirm_write_ro\" are read-only\. *$", 370 \ term_getline(buf, 17))}, 1000) 371 call WaitForAssert({-> assert_match('^It may still be possible to write it\. *$', 372 \ term_getline(buf, 18))}, 1000) 373 call WaitForAssert({-> assert_match('^Do you wish to try? *$', term_getline(buf, 19))}, 1000) 374 call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', term_getline(buf, 20))}, 1000) 375 call term_sendkeys(buf, 'Y') 376 call WaitForAssert({-> assert_match('^"Xconfirm_write_ro" 1L, 4B written$', 377 \ term_getline(buf, 19))}, 1000) 378 call assert_equal(['foo'], readfile('Xconfirm_write_ro')) 379 380 call StopVimInTerminal(buf) 381 call delete('Xscript') 382 call delete('Xconfirm_write_ro') 383endfunc 384 385func Test_confirm_write_partial_file() 386 CheckNotGui 387 CheckRunVimInTerminal 388 389 call writefile(['a', 'b', 'c', 'd'], 'Xwrite_partial') 390 call writefile(['set nobackup ff=unix cmdheight=2', 391 \ 'edit Xwrite_partial'], 'Xscript') 392 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 393 394 call term_sendkeys(buf, ":confirm 2,3w\n") 395 call WaitForAssert({-> assert_match('^Write partial file? *$', 396 \ term_getline(buf, 19))}, 1000) 397 call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', 398 \ term_getline(buf, 20))}, 1000) 399 call term_sendkeys(buf, 'N') 400 call WaitForAssert({-> assert_match('.* All$', term_getline(buf, 20))}, 1000) 401 call assert_equal(['a', 'b', 'c', 'd'], readfile('Xwrite_partial')) 402 call delete('Xwrite_partial') 403 404 call term_sendkeys(buf, ":confirm 2,3w\n") 405 call WaitForAssert({-> assert_match('^Write partial file? *$', 406 \ term_getline(buf, 19))}, 1000) 407 call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', 408 \ term_getline(buf, 20))}, 1000) 409 call term_sendkeys(buf, 'Y') 410 call WaitForAssert({-> assert_match('^"Xwrite_partial" \[New\] 2L, 4B written *$', 411 \ term_getline(buf, 19))}, 1000) 412 call WaitForAssert({-> assert_match('^Press ENTER or type command to continue *$', 413 \ term_getline(buf, 20))}, 1000) 414 call assert_equal(['b', 'c'], readfile('Xwrite_partial')) 415 416 call StopVimInTerminal(buf) 417 call delete('Xwrite_partial') 418 call delete('Xscript') 419endfunc 420 421" Test for the :print command 422func Test_print_cmd() 423 call assert_fails('print', 'E749:') 424endfunc 425 426" Test for the :winsize command 427func Test_winsize_cmd() 428 call assert_fails('winsize 1', 'E465:') 429 call assert_fails('winsize 1 x', 'E465:') 430 call assert_fails('win_getid(1)', 'E475: Invalid argument: _getid(1)') 431 " Actually changing the window size would be flaky. 432endfunc 433 434" Test for the :redir command 435" NOTE: if you run tests as root this will fail. Don't run tests as root! 436func Test_redir_cmd() 437 call assert_fails('redir @@', 'E475:') 438 call assert_fails('redir abc', 'E475:') 439 call assert_fails('redir => 1abc', 'E474:') 440 call assert_fails('redir => a b', 'E488:') 441 call assert_fails('redir => abc[1]', 'E121:') 442 let b = 0zFF 443 call assert_fails('redir =>> b', 'E734:') 444 unlet b 445 446 if has('unix') 447 " Redirecting to a directory name 448 call mkdir('Xdir') 449 call assert_fails('redir > Xdir', 'E17:') 450 call delete('Xdir', 'd') 451 endif 452 453 " Test for redirecting to a register 454 redir @q> | echon 'clean ' | redir END 455 redir @q>> | echon 'water' | redir END 456 call assert_equal('clean water', @q) 457 458 " Test for redirecting to a variable 459 redir => color | echon 'blue ' | redir END 460 redir =>> color | echon 'sky' | redir END 461 call assert_equal('blue sky', color) 462endfunc 463 464func Test_redir_cmd_readonly() 465 CheckNotRoot 466 467 " Redirecting to a read-only file 468 call writefile([], 'Xfile') 469 call setfperm('Xfile', 'r--r--r--') 470 call assert_fails('redir! > Xfile', 'E190:') 471 call delete('Xfile') 472endfunc 473 474" Test for the :filetype command 475func Test_filetype_cmd() 476 call assert_fails('filetype abc', 'E475:') 477endfunc 478 479" Test for the :mode command 480func Test_mode_cmd() 481 call assert_fails('mode abc', 'E359:') 482endfunc 483 484" Test for the :sleep command 485func Test_sleep_cmd() 486 call assert_fails('sleep x', 'E475:') 487endfunc 488 489" Test for the :read command 490func Test_read_cmd() 491 call writefile(['one'], 'Xfile') 492 new 493 call assert_fails('read', 'E32:') 494 edit Xfile 495 read 496 call assert_equal(['one', 'one'], getline(1, '$')) 497 close! 498 new 499 read Xfile 500 call assert_equal(['', 'one'], getline(1, '$')) 501 call deletebufline('', 1, '$') 502 call feedkeys("Qr Xfile\<CR>visual\<CR>", 'xt') 503 call assert_equal(['one'], getline(1, '$')) 504 close! 505 call delete('Xfile') 506endfunc 507 508" Test for running Ex commands when text is locked. 509" <C-\>e in the command line is used to lock the text 510func Test_run_excmd_with_text_locked() 511 " :quit 512 let cmd = ":\<C-\>eexecute('quit')\<CR>\<C-C>" 513 call assert_fails("call feedkeys(cmd, 'xt')", 'E565:') 514 515 " :qall 516 let cmd = ":\<C-\>eexecute('qall')\<CR>\<C-C>" 517 call assert_fails("call feedkeys(cmd, 'xt')", 'E565:') 518 519 " :exit 520 let cmd = ":\<C-\>eexecute('exit')\<CR>\<C-C>" 521 call assert_fails("call feedkeys(cmd, 'xt')", 'E565:') 522 523 " :close - should be ignored 524 new 525 let cmd = ":\<C-\>eexecute('close')\<CR>\<C-C>" 526 call assert_equal(2, winnr('$')) 527 close 528 529 call assert_fails("call feedkeys(\":\<C-R>=execute('bnext')\<CR>\", 'xt')", 'E565:') 530 531 " :tabfirst 532 tabnew 533 call assert_fails("call feedkeys(\":\<C-R>=execute('tabfirst')\<CR>\", 'xt')", 'E565:') 534 tabclose 535endfunc 536 537" Test for the :verbose command 538func Test_verbose_cmd() 539 call assert_equal([' verbose=1'], split(execute('verbose set vbs'), "\n")) 540 call assert_equal([' verbose=0'], split(execute('0verbose set vbs'), "\n")) 541 let l = execute("4verbose set verbose | set verbose") 542 call assert_equal([' verbose=4', ' verbose=0'], split(l, "\n")) 543endfunc 544 545" Test for the :delete command and the related abbreviated commands 546func Test_excmd_delete() 547 new 548 call setline(1, ['foo', "\tbar"]) 549 call assert_equal(['^Ibar$'], split(execute('dl'), "\n")) 550 call setline(1, ['foo', "\tbar"]) 551 call assert_equal(['^Ibar$'], split(execute('dell'), "\n")) 552 call setline(1, ['foo', "\tbar"]) 553 call assert_equal(['^Ibar$'], split(execute('delel'), "\n")) 554 call setline(1, ['foo', "\tbar"]) 555 call assert_equal(['^Ibar$'], split(execute('deletl'), "\n")) 556 call setline(1, ['foo', "\tbar"]) 557 call assert_equal(['^Ibar$'], split(execute('deletel'), "\n")) 558 call setline(1, ['foo', "\tbar"]) 559 call assert_equal([' bar'], split(execute('dp'), "\n")) 560 call setline(1, ['foo', "\tbar"]) 561 call assert_equal([' bar'], split(execute('dep'), "\n")) 562 call setline(1, ['foo', "\tbar"]) 563 call assert_equal([' bar'], split(execute('delp'), "\n")) 564 call setline(1, ['foo', "\tbar"]) 565 call assert_equal([' bar'], split(execute('delep'), "\n")) 566 call setline(1, ['foo', "\tbar"]) 567 call assert_equal([' bar'], split(execute('deletp'), "\n")) 568 call setline(1, ['foo', "\tbar"]) 569 call assert_equal([' bar'], split(execute('deletep'), "\n")) 570 close! 571endfunc 572 573" Test for commands that are blocked in a sandbox 574func Sandbox_tests() 575 call assert_fails("call histadd(':', 'ls')", 'E48:') 576 call assert_fails("call mkdir('Xdir')", 'E48:') 577 call assert_fails("call rename('a', 'b')", 'E48:') 578 call assert_fails("call setbufvar(1, 'myvar', 1)", 'E48:') 579 call assert_fails("call settabvar(1, 'myvar', 1)", 'E48:') 580 call assert_fails("call settabwinvar(1, 1, 'myvar', 1)", 'E48:') 581 call assert_fails("call setwinvar(1, 'myvar', 1)", 'E48:') 582 call assert_fails("call timer_start(100, '')", 'E48:') 583 if has('channel') 584 call assert_fails("call prompt_setcallback(1, '')", 'E48:') 585 call assert_fails("call prompt_setinterrupt(1, '')", 'E48:') 586 call assert_fails("call prompt_setprompt(1, '')", 'E48:') 587 endif 588 call assert_fails("let $TESTVAR=1", 'E48:') 589 call assert_fails("call feedkeys('ivim')", 'E48:') 590 call assert_fails("source! Xfile", 'E48:') 591 call assert_fails("call delete('Xfile')", 'E48:') 592 call assert_fails("call writefile([], 'Xfile')", 'E48:') 593 call assert_fails('!ls', 'E48:') 594 call assert_fails('shell', 'E48:') 595 call assert_fails('stop', 'E48:') 596 call assert_fails('exe "normal \<C-Z>"', 'E48:') 597 set insertmode 598 call assert_fails('call feedkeys("\<C-Z>", "xt")', 'E48:') 599 set insertmode& 600 call assert_fails('suspend', 'E48:') 601 call assert_fails('call system("ls")', 'E48:') 602 call assert_fails('call systemlist("ls")', 'E48:') 603 if has('clientserver') 604 call assert_fails('let s=remote_expr("gvim", "2+2")', 'E48:') 605 if !has('win32') 606 " remote_foreground() doesn't thrown an error message on MS-Windows 607 call assert_fails('call remote_foreground("gvim")', 'E48:') 608 endif 609 call assert_fails('let s=remote_peek("gvim")', 'E48:') 610 call assert_fails('let s=remote_read("gvim")', 'E48:') 611 call assert_fails('let s=remote_send("gvim", "abc")', 'E48:') 612 call assert_fails('let s=server2client("gvim", "abc")', 'E48:') 613 endif 614 if has('terminal') 615 call assert_fails('terminal', 'E48:') 616 call assert_fails('call term_start("vim")', 'E48:') 617 call assert_fails('call term_dumpwrite(1, "Xfile")', 'E48:') 618 endif 619 if has('channel') 620 call assert_fails("call ch_logfile('chlog')", 'E48:') 621 call assert_fails("call ch_open('localhost:8765')", 'E48:') 622 endif 623 if has('job') 624 call assert_fails("call job_start('vim')", 'E48:') 625 endif 626 if has('unix') && has('libcall') 627 call assert_fails("echo libcall('libc.so', 'getenv', 'HOME')", 'E48:') 628 endif 629 if has('unix') 630 call assert_fails('cd `pwd`', 'E48:') 631 endif 632 " some options cannot be changed in a sandbox 633 call assert_fails('set exrc', 'E48:') 634 call assert_fails('set cdpath', 'E48:') 635 if has('xim') && has('gui_gtk') 636 call assert_fails('set imstyle', 'E48:') 637 endif 638endfunc 639 640func Test_sandbox() 641 sandbox call Sandbox_tests() 642endfunc 643 644func Test_command_not_implemented_E319() 645 if !has('mzscheme') 646 call assert_fails('mzscheme', 'E319:') 647 endif 648endfunc 649 650func Test_not_break_expression_register() 651 call setreg('=', '1+1') 652 if 0 653 put =1 654 endif 655 call assert_equal('1+1', getreg('=', 1)) 656endfunc 657 658" vim: shiftwidth=2 sts=2 expandtab 659