Skip to content

Commit 5c645a2

Browse files
committed
patch 9.0.0538: manually deleting test temp files
Problem: Manually deleting test temp files. Solution: Add the 'D' flag to writefile().
1 parent 4740394 commit 5c645a2

File tree

9 files changed

+38
-73
lines changed

9 files changed

+38
-73
lines changed

src/testdir/test_eval_stuff.vim

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func Test_nocatch_restore_silent_emsg()
2525
endfunc
2626

2727
func Test_mkdir_p()
28-
call mkdir('Xmkdir/nested', 'p')
28+
call mkdir('Xmkdir/nested', 'pR')
2929
call assert_true(isdirectory('Xmkdir/nested'))
3030
try
3131
" Trying to make existing directories doesn't error
@@ -35,10 +35,9 @@ func Test_mkdir_p()
3535
call assert_report('mkdir(..., "p") failed for an existing directory')
3636
endtry
3737
" 'p' doesn't suppress real errors
38-
call writefile([], 'Xmkdirfile')
38+
call writefile([], 'Xmkdirfile', 'D')
3939
call assert_fails('call mkdir("Xmkdirfile", "p")', 'E739:')
40-
call delete('Xmkdirfile')
41-
call delete('Xmkdir', 'rf')
40+
4241
call assert_equal(0, mkdir(test_null_string()))
4342
call assert_fails('call mkdir([])', 'E730:')
4443
call assert_fails('call mkdir("abc", [], [])', 'E745:')
@@ -160,11 +159,9 @@ func Test_for_invalid_line_count()
160159
111111111111111111111111 for line in ['one']
161160
endfor
162161
END
163-
call writefile(lines, 'XinvalidFor')
162+
call writefile(lines, 'XinvalidFor', 'D')
164163
" only test that this doesn't crash
165164
call RunVim([], [], '-u NONE -e -s -S XinvalidFor -c qa')
166-
167-
call delete('XinvalidFor')
168165
endfunc
169166

170167
func Test_readfile_binary()
@@ -186,10 +183,9 @@ func Test_readfile_binary()
186183
endfunc
187184

188185
func Test_readfile_binary_empty()
189-
call writefile([], 'Xempty-file')
186+
call writefile([], 'Xempty-file', 'D')
190187
" This used to compare uninitialized memory in Vim <= 8.2.4065
191188
call assert_equal([''], readfile('Xempty-file', 'b'))
192-
call delete('Xempty-file')
193189
endfunc
194190

195191
func Test_readfile_bom()
@@ -199,10 +195,9 @@ func Test_readfile_bom()
199195
endfunc
200196

201197
func Test_readfile_max()
202-
call writefile(range(1, 4), 'XReadfile_max')
198+
call writefile(range(1, 4), 'XReadfile_max', 'D')
203199
call assert_equal(['1', '2'], readfile('XReadfile_max', '', 2))
204200
call assert_equal(['3', '4'], readfile('XReadfile_max', '', -2))
205-
call delete('XReadfile_max')
206201
endfunc
207202

208203
func Test_let_errmsg()
@@ -336,9 +331,8 @@ func Test_vvar_scriptversion1()
336331
endfunc
337332

338333
func Test_scriptversion_fail()
339-
call writefile(['scriptversion 9'], 'Xversionscript')
334+
call writefile(['scriptversion 9'], 'Xversionscript', 'D')
340335
call assert_fails('source Xversionscript', 'E999:')
341-
call delete('Xversionscript')
342336
endfunc
343337

344338
func Test_execute_cmd_with_null()

src/testdir/test_ex_mode.vim

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,12 @@ func Test_ex_mode_with_global()
237237
call writefile(['done'], 'Xdidexmode')
238238
qall!
239239
END
240-
call writefile(lines, 'Xexmodescript')
240+
call writefile(lines, 'Xexmodescript', 'D')
241241
call assert_equal(1, RunVim([], [], '-e -s -S Xexmodescript'))
242242
call assert_equal(['done'], readfile('Xdidexmode'))
243243

244244
call delete('logfile')
245245
call delete('Xdidexmode')
246-
call delete('Xexmodescript')
247246
endfunc
248247

249248
func Test_ex_mode_count_overflow()
@@ -257,12 +256,11 @@ func Test_ex_mode_count_overflow()
257256
call writefile(['done'], 'Xdidexmode')
258257
qall!
259258
END
260-
call writefile(lines, 'Xexmodescript')
259+
call writefile(lines, 'Xexmodescript', 'D')
261260
call assert_equal(1, RunVim([], [], '-e -s -S Xexmodescript -c qa'))
262261
call assert_equal(['done'], readfile('Xdidexmode'))
263262

264263
call delete('Xdidexmode')
265-
call delete('Xexmodescript')
266264
endfunc
267265

268266
func Test_ex_mode_large_indent()
@@ -281,11 +279,9 @@ func Test_empty_command_visual_mode()
281279
0norm0V:
282280
:qall!
283281
END
284-
call writefile(lines, 'Xexmodescript')
282+
call writefile(lines, 'Xexmodescript', 'D')
285283
call assert_equal(1, RunVim([], [], '-u NONE -e -s -S Xexmodescript'))
286284

287-
call delete('Xexmodescript')
288-
289285
" This may cause a dialog to be displayed for an empty command, ignore it.
290286
call delete('guidialogfile')
291287
endfunc

src/testdir/test_excmd.vim

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ endfunc
8383

8484
" Test for the :drop command
8585
func Test_drop_cmd()
86-
call writefile(['L1', 'L2'], 'Xdropfile')
86+
call writefile(['L1', 'L2'], 'Xdropfile', 'D')
8787
enew | only
8888
drop Xdropfile
8989
call assert_equal('L2', getline(2))
@@ -99,7 +99,6 @@ func Test_drop_cmd()
9999
" Check for setting the argument list
100100
call assert_equal(['Xdropfile'], argv())
101101
enew | only!
102-
call delete('Xdropfile')
103102
endfunc
104103

105104
" Test for the :append command
@@ -141,14 +140,13 @@ func Test_append_cmd_empty_buf()
141140
endfunc
142141
call timer_start(10, 'Timer')
143142
END
144-
call writefile(lines, 'Xtest_append_cmd_empty_buf')
143+
call writefile(lines, 'Xtest_append_cmd_empty_buf', 'D')
145144
let buf = RunVimInTerminal('-S Xtest_append_cmd_empty_buf', {'rows': 6})
146145
call WaitForAssert({-> assert_equal('bbbbb', term_getline(buf, 2))})
147146
call WaitForAssert({-> assert_equal('aaaaa', term_getline(buf, 1))})
148147

149148
" clean up
150149
call StopVimInTerminal(buf)
151-
call delete('Xtest_append_cmd_empty_buf')
152150
endfunc
153151

154152
" Test for the :insert command
@@ -190,14 +188,13 @@ func Test_insert_cmd_empty_buf()
190188
endfunc
191189
call timer_start(10, 'Timer')
192190
END
193-
call writefile(lines, 'Xtest_insert_cmd_empty_buf')
191+
call writefile(lines, 'Xtest_insert_cmd_empty_buf', 'D')
194192
let buf = RunVimInTerminal('-S Xtest_insert_cmd_empty_buf', {'rows': 6})
195193
call WaitForAssert({-> assert_equal('bbbbb', term_getline(buf, 2))})
196194
call WaitForAssert({-> assert_equal('aaaaa', term_getline(buf, 1))})
197195

198196
" clean up
199197
call StopVimInTerminal(buf)
200-
call delete('Xtest_insert_cmd_empty_buf')
201198
endfunc
202199

203200
" Test for the :change command
@@ -241,8 +238,8 @@ func Test_confirm_cmd()
241238
CheckNotGui
242239
CheckRunVimInTerminal
243240

244-
call writefile(['foo1'], 'Xfoo')
245-
call writefile(['bar1'], 'Xbar')
241+
call writefile(['foo1'], 'Xfoo', 'D')
242+
call writefile(['bar1'], 'Xbar', 'D')
246243

247244
" Test for saving all the modified buffers
248245
let lines =<< trim END
@@ -253,7 +250,7 @@ func Test_confirm_cmd()
253250
call setline(1, 'bar2')
254251
wincmd b
255252
END
256-
call writefile(lines, 'Xscript')
253+
call writefile(lines, 'Xscript', 'D')
257254
let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
258255
call term_sendkeys(buf, ":confirm qall\n")
259256
call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000)
@@ -302,10 +299,6 @@ func Test_confirm_cmd()
302299

303300
call assert_equal(['foo4'], readfile('Xfoo'))
304301
call assert_equal(['bar2'], readfile('Xbar'))
305-
306-
call delete('Xscript')
307-
call delete('Xfoo')
308-
call delete('Xbar')
309302
endfunc
310303

311304
func Test_confirm_cmd_cancel()
@@ -318,7 +311,7 @@ func Test_confirm_cmd_cancel()
318311
new
319312
call setline(1, 'abc')
320313
END
321-
call writefile(lines, 'Xscript')
314+
call writefile(lines, 'Xscript', 'D')
322315
let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
323316
call term_sendkeys(buf, ":confirm close\n")
324317
call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
@@ -332,7 +325,6 @@ func Test_confirm_cmd_cancel()
332325
call WaitForAssert({-> assert_match('^ *0,0-1 All$',
333326
\ term_getline(buf, 20))}, 1000)
334327
call StopVimInTerminal(buf)
335-
call delete('Xscript')
336328
endfunc
337329

338330
" The ":confirm" prompt was sometimes used with the terminal in cooked mode.
@@ -342,14 +334,14 @@ func Test_confirm_q_wq()
342334
CheckNotGui
343335
CheckRunVimInTerminal
344336

345-
call writefile(['foo'], 'Xfoo')
337+
call writefile(['foo'], 'Xfoo', 'D')
346338

347339
let lines =<< trim END
348340
set hidden nomore
349341
call setline(1, 'abc')
350342
edit Xfoo
351343
END
352-
call writefile(lines, 'Xscript')
344+
call writefile(lines, 'Xscript', 'D')
353345
let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
354346
call term_sendkeys(buf, ":confirm q\n")
355347
call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
@@ -365,23 +357,21 @@ func Test_confirm_q_wq()
365357
call term_sendkeys(buf, 'C')
366358
call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$',
367359
\ term_getline(buf, 20))}, 1000)
368-
call StopVimInTerminal(buf)
369360

370-
call delete('Xscript')
371-
call delete('Xfoo')
361+
call StopVimInTerminal(buf)
372362
endfunc
373363

374364
func Test_confirm_write_ro()
375365
CheckNotGui
376366
CheckRunVimInTerminal
377367

378-
call writefile(['foo'], 'Xconfirm_write_ro')
368+
call writefile(['foo'], 'Xconfirm_write_ro', 'D')
379369
let lines =<< trim END
380370
set nobackup ff=unix cmdheight=2
381371
edit Xconfirm_write_ro
382372
norm Abar
383373
END
384-
call writefile(lines, 'Xscript')
374+
call writefile(lines, 'Xscript', 'D')
385375
let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
386376

387377
" Try to write with 'ro' option.
@@ -422,17 +412,15 @@ func Test_confirm_write_ro()
422412
call assert_equal(['foo'], readfile('Xconfirm_write_ro'))
423413

424414
call StopVimInTerminal(buf)
425-
call delete('Xscript')
426-
call delete('Xconfirm_write_ro')
427415
endfunc
428416

429417
func Test_confirm_write_partial_file()
430418
CheckNotGui
431419
CheckRunVimInTerminal
432420

433-
call writefile(['a', 'b', 'c', 'd'], 'Xwrite_partial')
421+
call writefile(['a', 'b', 'c', 'd'], 'Xwrite_partial', 'D')
434422
call writefile(['set nobackup ff=unix cmdheight=2',
435-
\ 'edit Xwrite_partial'], 'Xscript')
423+
\ 'edit Xwrite_partial'], 'Xscript', 'D')
436424
let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
437425

438426
call term_sendkeys(buf, ":confirm 2,3w\n")
@@ -458,8 +446,6 @@ func Test_confirm_write_partial_file()
458446
call assert_equal(['b', 'c'], readfile('Xwrite_partial'))
459447

460448
call StopVimInTerminal(buf)
461-
call delete('Xwrite_partial')
462-
call delete('Xscript')
463449
endfunc
464450

465451
" Test for the :print command
@@ -509,10 +495,9 @@ func Test_redir_cmd_readonly()
509495
CheckNotRoot
510496

511497
" Redirecting to a read-only file
512-
call writefile([], 'Xredirfile')
498+
call writefile([], 'Xredirfile', 'D')
513499
call setfperm('Xredirfile', 'r--r--r--')
514500
call assert_fails('redir! > Xredirfile', 'E190:')
515-
call delete('Xredirfile')
516501
endfunc
517502

518503
" Test for the :filetype command
@@ -532,7 +517,7 @@ endfunc
532517

533518
" Test for the :read command
534519
func Test_read_cmd()
535-
call writefile(['one'], 'Xcmdfile')
520+
call writefile(['one'], 'Xcmdfile', 'D')
536521
new
537522
call assert_fails('read', 'E32:')
538523
edit Xcmdfile
@@ -546,7 +531,6 @@ func Test_read_cmd()
546531
call feedkeys("Qr Xcmdfile\<CR>visual\<CR>", 'xt')
547532
call assert_equal(['one'], getline(1, '$'))
548533
close!
549-
call delete('Xcmdfile')
550534
endfunc
551535

552536
" Test for running Ex commands when text is locked.
@@ -727,7 +711,7 @@ endfunc
727711

728712
" Test :write after changing name with :file and loading it with :edit
729713
func Test_write_after_rename()
730-
call writefile(['text'], 'Xafterfile')
714+
call writefile(['text'], 'Xafterfile', 'D')
731715

732716
enew
733717
file Xafterfile
@@ -737,7 +721,6 @@ func Test_write_after_rename()
737721
edit
738722
write
739723

740-
call delete('Xafterfile')
741724
bwipe!
742725
endfunc
743726

src/testdir/test_execute_func.vim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,12 @@ func Test_win_execute_on_startup()
183183
silent tabedit Xfile3
184184
autocmd VimEnter * win_execute(id, 'close')
185185
END
186-
call writefile(lines, 'XwinExecute')
186+
call writefile(lines, 'XwinExecute', 'D')
187187
let buf = RunVimInTerminal('-p Xfile1 -Nu XwinExecute', {})
188188

189189
" this was crashing on exit with EXITFREE defined
190190
call StopVimInTerminal(buf)
191191

192-
call delete('XwinExecute')
193192
call delete('Xfile1')
194193
endfunc
195194

src/testdir/test_exit.vim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,12 @@ func Test_exit_error_reading_input()
117117
CheckNotAsan
118118
CheckNotValgrind
119119

120-
call writefile([":au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout')", ":tabnew", "q:"], 'Xscript', 'b')
120+
call writefile([":au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout')", ":tabnew", "q:"], 'Xscript', 'bD')
121121

122122
if RunVim([], [], '<Xscript')
123123
call assert_equal(1, v:shell_error)
124124
call assert_equal(['l = 1'], readfile('Xtestout'))
125125
endif
126-
call delete('Xscript')
127126
call delete('Xtestout')
128127
endfun
129128

src/testdir/test_expand.vim

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,13 @@ func Test_source_sfile()
137137
:call writefile(v:errors, 'Xresult')
138138
:qall!
139139
[SCRIPT]
140-
call writefile(lines, 'Xscript')
140+
call writefile(lines, 'Xscript', 'D')
141141
if RunVim([], [], '--clean -s Xscript')
142142
call assert_equal([
143143
\ 'E1274: No script file name to substitute for "<script>"',
144144
\ 'E498: No :source file name to substitute for "<sfile>"'],
145145
\ readfile('Xresult'))
146146
endif
147-
call delete('Xscript')
148147
call delete('Xresult')
149148
endfunc
150149

@@ -197,9 +196,9 @@ func Test_expand_script_source()
197196
au User * call extend(g:au_level, [expand('<script>:t')])
198197
[SCRIPT]
199198

200-
call writefile(lines0, 'Xscript0')
201-
call writefile(lines1, 'Xscript1')
202-
call writefile(lines2, 'Xscript2')
199+
call writefile(lines0, 'Xscript0', 'D')
200+
call writefile(lines1, 'Xscript1', 'D')
201+
call writefile(lines2, 'Xscript2', 'D')
203202

204203
" Check the expansion of <script> at different levels.
205204
let g:script_level = []
@@ -220,10 +219,6 @@ func Test_expand_script_source()
220219
delfunc F0
221220
delfunc F1
222221
delfunc F2
223-
224-
call delete('Xscript0')
225-
call delete('Xscript1')
226-
call delete('Xscript2')
227222
endfunc
228223

229224
" vim: shiftwidth=2 sts=2 expandtab

0 commit comments

Comments
 (0)