comparison src/testdir/test_excmd.vim @ 30405:ea38db8639eb v9.0.0538

patch 9.0.0538: manually deleting test temp files Commit: https://github.com/vim/vim/commit/5c645a25bb8e6d766db720a44b9ceeff39d1e92b Author: Bram Moolenaar <Bram@vim.org> Date: Wed Sep 21 22:00:03 2022 +0100 patch 9.0.0538: manually deleting test temp files Problem: Manually deleting test temp files. Solution: Add the 'D' flag to writefile().
author Bram Moolenaar <Bram@vim.org>
date Wed, 21 Sep 2022 23:15:03 +0200
parents 13b02c1ea0f7
children 377ed6ab612c
comparison
equal deleted inserted replaced
30404:20bbd0c0761b 30405:ea38db8639eb
81 endif 81 endif
82 endfunc 82 endfunc
83 83
84 " Test for the :drop command 84 " Test for the :drop command
85 func Test_drop_cmd() 85 func Test_drop_cmd()
86 call writefile(['L1', 'L2'], 'Xdropfile') 86 call writefile(['L1', 'L2'], 'Xdropfile', 'D')
87 enew | only 87 enew | only
88 drop Xdropfile 88 drop Xdropfile
89 call assert_equal('L2', getline(2)) 89 call assert_equal('L2', getline(2))
90 " Test for switching to an existing window 90 " Test for switching to an existing window
91 below new 91 below new
97 drop Xdropfile 97 drop Xdropfile
98 call assert_equal(2, winnr('$')) 98 call assert_equal(2, winnr('$'))
99 " Check for setting the argument list 99 " Check for setting the argument list
100 call assert_equal(['Xdropfile'], argv()) 100 call assert_equal(['Xdropfile'], argv())
101 enew | only! 101 enew | only!
102 call delete('Xdropfile')
103 endfunc 102 endfunc
104 103
105 " Test for the :append command 104 " Test for the :append command
106 func Test_append_cmd() 105 func Test_append_cmd()
107 new 106 new
139 bbbbb 138 bbbbb
140 . 139 .
141 endfunc 140 endfunc
142 call timer_start(10, 'Timer') 141 call timer_start(10, 'Timer')
143 END 142 END
144 call writefile(lines, 'Xtest_append_cmd_empty_buf') 143 call writefile(lines, 'Xtest_append_cmd_empty_buf', 'D')
145 let buf = RunVimInTerminal('-S Xtest_append_cmd_empty_buf', {'rows': 6}) 144 let buf = RunVimInTerminal('-S Xtest_append_cmd_empty_buf', {'rows': 6})
146 call WaitForAssert({-> assert_equal('bbbbb', term_getline(buf, 2))}) 145 call WaitForAssert({-> assert_equal('bbbbb', term_getline(buf, 2))})
147 call WaitForAssert({-> assert_equal('aaaaa', term_getline(buf, 1))}) 146 call WaitForAssert({-> assert_equal('aaaaa', term_getline(buf, 1))})
148 147
149 " clean up 148 " clean up
150 call StopVimInTerminal(buf) 149 call StopVimInTerminal(buf)
151 call delete('Xtest_append_cmd_empty_buf')
152 endfunc 150 endfunc
153 151
154 " Test for the :insert command 152 " Test for the :insert command
155 func Test_insert_cmd() 153 func Test_insert_cmd()
156 new 154 new
188 bbbbb 186 bbbbb
189 . 187 .
190 endfunc 188 endfunc
191 call timer_start(10, 'Timer') 189 call timer_start(10, 'Timer')
192 END 190 END
193 call writefile(lines, 'Xtest_insert_cmd_empty_buf') 191 call writefile(lines, 'Xtest_insert_cmd_empty_buf', 'D')
194 let buf = RunVimInTerminal('-S Xtest_insert_cmd_empty_buf', {'rows': 6}) 192 let buf = RunVimInTerminal('-S Xtest_insert_cmd_empty_buf', {'rows': 6})
195 call WaitForAssert({-> assert_equal('bbbbb', term_getline(buf, 2))}) 193 call WaitForAssert({-> assert_equal('bbbbb', term_getline(buf, 2))})
196 call WaitForAssert({-> assert_equal('aaaaa', term_getline(buf, 1))}) 194 call WaitForAssert({-> assert_equal('aaaaa', term_getline(buf, 1))})
197 195
198 " clean up 196 " clean up
199 call StopVimInTerminal(buf) 197 call StopVimInTerminal(buf)
200 call delete('Xtest_insert_cmd_empty_buf')
201 endfunc 198 endfunc
202 199
203 " Test for the :change command 200 " Test for the :change command
204 func Test_change_cmd() 201 func Test_change_cmd()
205 new 202 new
239 " Test for the :confirm command dialog 236 " Test for the :confirm command dialog
240 func Test_confirm_cmd() 237 func Test_confirm_cmd()
241 CheckNotGui 238 CheckNotGui
242 CheckRunVimInTerminal 239 CheckRunVimInTerminal
243 240
244 call writefile(['foo1'], 'Xfoo') 241 call writefile(['foo1'], 'Xfoo', 'D')
245 call writefile(['bar1'], 'Xbar') 242 call writefile(['bar1'], 'Xbar', 'D')
246 243
247 " Test for saving all the modified buffers 244 " Test for saving all the modified buffers
248 let lines =<< trim END 245 let lines =<< trim END
249 set nomore 246 set nomore
250 new Xfoo 247 new Xfoo
251 call setline(1, 'foo2') 248 call setline(1, 'foo2')
252 new Xbar 249 new Xbar
253 call setline(1, 'bar2') 250 call setline(1, 'bar2')
254 wincmd b 251 wincmd b
255 END 252 END
256 call writefile(lines, 'Xscript') 253 call writefile(lines, 'Xscript', 'D')
257 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 254 let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
258 call term_sendkeys(buf, ":confirm qall\n") 255 call term_sendkeys(buf, ":confirm qall\n")
259 call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) 256 call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000)
260 call term_sendkeys(buf, "A") 257 call term_sendkeys(buf, "A")
261 call StopVimInTerminal(buf) 258 call StopVimInTerminal(buf)
300 call term_sendkeys(buf, "Y") 297 call term_sendkeys(buf, "Y")
301 call StopVimInTerminal(buf) 298 call StopVimInTerminal(buf)
302 299
303 call assert_equal(['foo4'], readfile('Xfoo')) 300 call assert_equal(['foo4'], readfile('Xfoo'))
304 call assert_equal(['bar2'], readfile('Xbar')) 301 call assert_equal(['bar2'], readfile('Xbar'))
305
306 call delete('Xscript')
307 call delete('Xfoo')
308 call delete('Xbar')
309 endfunc 302 endfunc
310 303
311 func Test_confirm_cmd_cancel() 304 func Test_confirm_cmd_cancel()
312 CheckNotGui 305 CheckNotGui
313 CheckRunVimInTerminal 306 CheckRunVimInTerminal
316 let lines =<< trim END 309 let lines =<< trim END
317 set nomore 310 set nomore
318 new 311 new
319 call setline(1, 'abc') 312 call setline(1, 'abc')
320 END 313 END
321 call writefile(lines, 'Xscript') 314 call writefile(lines, 'Xscript', 'D')
322 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 315 let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
323 call term_sendkeys(buf, ":confirm close\n") 316 call term_sendkeys(buf, ":confirm close\n")
324 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', 317 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
325 \ term_getline(buf, 20))}, 1000) 318 \ term_getline(buf, 20))}, 1000)
326 call term_sendkeys(buf, "C") 319 call term_sendkeys(buf, "C")
330 \ term_getline(buf, 20))}, 1000) 323 \ term_getline(buf, 20))}, 1000)
331 call term_sendkeys(buf, "N") 324 call term_sendkeys(buf, "N")
332 call WaitForAssert({-> assert_match('^ *0,0-1 All$', 325 call WaitForAssert({-> assert_match('^ *0,0-1 All$',
333 \ term_getline(buf, 20))}, 1000) 326 \ term_getline(buf, 20))}, 1000)
334 call StopVimInTerminal(buf) 327 call StopVimInTerminal(buf)
335 call delete('Xscript')
336 endfunc 328 endfunc
337 329
338 " The ":confirm" prompt was sometimes used with the terminal in cooked mode. 330 " The ":confirm" prompt was sometimes used with the terminal in cooked mode.
339 " This test verifies that a "\<CR>" character is NOT required to respond to a 331 " This test verifies that a "\<CR>" character is NOT required to respond to a
340 " prompt from the ":conf q" and ":conf wq" commands. 332 " prompt from the ":conf q" and ":conf wq" commands.
341 func Test_confirm_q_wq() 333 func Test_confirm_q_wq()
342 CheckNotGui 334 CheckNotGui
343 CheckRunVimInTerminal 335 CheckRunVimInTerminal
344 336
345 call writefile(['foo'], 'Xfoo') 337 call writefile(['foo'], 'Xfoo', 'D')
346 338
347 let lines =<< trim END 339 let lines =<< trim END
348 set hidden nomore 340 set hidden nomore
349 call setline(1, 'abc') 341 call setline(1, 'abc')
350 edit Xfoo 342 edit Xfoo
351 END 343 END
352 call writefile(lines, 'Xscript') 344 call writefile(lines, 'Xscript', 'D')
353 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 345 let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
354 call term_sendkeys(buf, ":confirm q\n") 346 call term_sendkeys(buf, ":confirm q\n")
355 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', 347 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
356 \ term_getline(buf, 20))}, 1000) 348 \ term_getline(buf, 20))}, 1000)
357 call term_sendkeys(buf, 'C') 349 call term_sendkeys(buf, 'C')
363 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', 355 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
364 \ term_getline(buf, 20))}, 1000) 356 \ term_getline(buf, 20))}, 1000)
365 call term_sendkeys(buf, 'C') 357 call term_sendkeys(buf, 'C')
366 call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$', 358 call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$',
367 \ term_getline(buf, 20))}, 1000) 359 \ term_getline(buf, 20))}, 1000)
368 call StopVimInTerminal(buf) 360
369 361 call StopVimInTerminal(buf)
370 call delete('Xscript')
371 call delete('Xfoo')
372 endfunc 362 endfunc
373 363
374 func Test_confirm_write_ro() 364 func Test_confirm_write_ro()
375 CheckNotGui 365 CheckNotGui
376 CheckRunVimInTerminal 366 CheckRunVimInTerminal
377 367
378 call writefile(['foo'], 'Xconfirm_write_ro') 368 call writefile(['foo'], 'Xconfirm_write_ro', 'D')
379 let lines =<< trim END 369 let lines =<< trim END
380 set nobackup ff=unix cmdheight=2 370 set nobackup ff=unix cmdheight=2
381 edit Xconfirm_write_ro 371 edit Xconfirm_write_ro
382 norm Abar 372 norm Abar
383 END 373 END
384 call writefile(lines, 'Xscript') 374 call writefile(lines, 'Xscript', 'D')
385 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 375 let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
386 376
387 " Try to write with 'ro' option. 377 " Try to write with 'ro' option.
388 call term_sendkeys(buf, ":set ro | confirm w\n") 378 call term_sendkeys(buf, ":set ro | confirm w\n")
389 call WaitForAssert({-> assert_match("^'readonly' option is set for \"Xconfirm_write_ro\"\. *$", 379 call WaitForAssert({-> assert_match("^'readonly' option is set for \"Xconfirm_write_ro\"\. *$",
420 call WaitForAssert({-> assert_match('^"Xconfirm_write_ro" 1L, 4B written$', 410 call WaitForAssert({-> assert_match('^"Xconfirm_write_ro" 1L, 4B written$',
421 \ term_getline(buf, 19))}, 1000) 411 \ term_getline(buf, 19))}, 1000)
422 call assert_equal(['foo'], readfile('Xconfirm_write_ro')) 412 call assert_equal(['foo'], readfile('Xconfirm_write_ro'))
423 413
424 call StopVimInTerminal(buf) 414 call StopVimInTerminal(buf)
425 call delete('Xscript')
426 call delete('Xconfirm_write_ro')
427 endfunc 415 endfunc
428 416
429 func Test_confirm_write_partial_file() 417 func Test_confirm_write_partial_file()
430 CheckNotGui 418 CheckNotGui
431 CheckRunVimInTerminal 419 CheckRunVimInTerminal
432 420
433 call writefile(['a', 'b', 'c', 'd'], 'Xwrite_partial') 421 call writefile(['a', 'b', 'c', 'd'], 'Xwrite_partial', 'D')
434 call writefile(['set nobackup ff=unix cmdheight=2', 422 call writefile(['set nobackup ff=unix cmdheight=2',
435 \ 'edit Xwrite_partial'], 'Xscript') 423 \ 'edit Xwrite_partial'], 'Xscript', 'D')
436 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 424 let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
437 425
438 call term_sendkeys(buf, ":confirm 2,3w\n") 426 call term_sendkeys(buf, ":confirm 2,3w\n")
439 call WaitForAssert({-> assert_match('^Write partial file? *$', 427 call WaitForAssert({-> assert_match('^Write partial file? *$',
440 \ term_getline(buf, 19))}, 1000) 428 \ term_getline(buf, 19))}, 1000)
456 call WaitForAssert({-> assert_match('^Press ENTER or type command to continue *$', 444 call WaitForAssert({-> assert_match('^Press ENTER or type command to continue *$',
457 \ term_getline(buf, 20))}, 1000) 445 \ term_getline(buf, 20))}, 1000)
458 call assert_equal(['b', 'c'], readfile('Xwrite_partial')) 446 call assert_equal(['b', 'c'], readfile('Xwrite_partial'))
459 447
460 call StopVimInTerminal(buf) 448 call StopVimInTerminal(buf)
461 call delete('Xwrite_partial')
462 call delete('Xscript')
463 endfunc 449 endfunc
464 450
465 " Test for the :print command 451 " Test for the :print command
466 func Test_print_cmd() 452 func Test_print_cmd()
467 call assert_fails('print', 'E749:') 453 call assert_fails('print', 'E749:')
507 493
508 func Test_redir_cmd_readonly() 494 func Test_redir_cmd_readonly()
509 CheckNotRoot 495 CheckNotRoot
510 496
511 " Redirecting to a read-only file 497 " Redirecting to a read-only file
512 call writefile([], 'Xredirfile') 498 call writefile([], 'Xredirfile', 'D')
513 call setfperm('Xredirfile', 'r--r--r--') 499 call setfperm('Xredirfile', 'r--r--r--')
514 call assert_fails('redir! > Xredirfile', 'E190:') 500 call assert_fails('redir! > Xredirfile', 'E190:')
515 call delete('Xredirfile')
516 endfunc 501 endfunc
517 502
518 " Test for the :filetype command 503 " Test for the :filetype command
519 func Test_filetype_cmd() 504 func Test_filetype_cmd()
520 call assert_fails('filetype abc', 'E475:') 505 call assert_fails('filetype abc', 'E475:')
530 call assert_fails('sleep x', 'E475:') 515 call assert_fails('sleep x', 'E475:')
531 endfunc 516 endfunc
532 517
533 " Test for the :read command 518 " Test for the :read command
534 func Test_read_cmd() 519 func Test_read_cmd()
535 call writefile(['one'], 'Xcmdfile') 520 call writefile(['one'], 'Xcmdfile', 'D')
536 new 521 new
537 call assert_fails('read', 'E32:') 522 call assert_fails('read', 'E32:')
538 edit Xcmdfile 523 edit Xcmdfile
539 read 524 read
540 call assert_equal(['one', 'one'], getline(1, '$')) 525 call assert_equal(['one', 'one'], getline(1, '$'))
544 call assert_equal(['', 'one'], getline(1, '$')) 529 call assert_equal(['', 'one'], getline(1, '$'))
545 call deletebufline('', 1, '$') 530 call deletebufline('', 1, '$')
546 call feedkeys("Qr Xcmdfile\<CR>visual\<CR>", 'xt') 531 call feedkeys("Qr Xcmdfile\<CR>visual\<CR>", 'xt')
547 call assert_equal(['one'], getline(1, '$')) 532 call assert_equal(['one'], getline(1, '$'))
548 close! 533 close!
549 call delete('Xcmdfile')
550 endfunc 534 endfunc
551 535
552 " Test for running Ex commands when text is locked. 536 " Test for running Ex commands when text is locked.
553 " <C-\>e in the command line is used to lock the text 537 " <C-\>e in the command line is used to lock the text
554 func Test_run_excmd_with_text_locked() 538 func Test_run_excmd_with_text_locked()
725 bwipe! 709 bwipe!
726 endfunc 710 endfunc
727 711
728 " Test :write after changing name with :file and loading it with :edit 712 " Test :write after changing name with :file and loading it with :edit
729 func Test_write_after_rename() 713 func Test_write_after_rename()
730 call writefile(['text'], 'Xafterfile') 714 call writefile(['text'], 'Xafterfile', 'D')
731 715
732 enew 716 enew
733 file Xafterfile 717 file Xafterfile
734 call assert_fails('write', 'E13: File exists (add ! to override)') 718 call assert_fails('write', 'E13: File exists (add ! to override)')
735 719
736 " works OK after ":edit" 720 " works OK after ":edit"
737 edit 721 edit
738 write 722 write
739 723
740 call delete('Xafterfile')
741 bwipe! 724 bwipe!
742 endfunc 725 endfunc
743 726
744 727
745 " vim: shiftwidth=2 sts=2 expandtab 728 " vim: shiftwidth=2 sts=2 expandtab