comparison src/testdir/test_buffer.vim @ 29950:c8b1a683323c v9.0.0313

patch 9.0.0313: using common name in tests leads to flaky tests Commit: https://github.com/vim/vim/commit/e7cda97b6b578b33a42de0d27ac2876337c641ca Author: Bram Moolenaar <Bram@vim.org> Date: Mon Aug 29 11:02:59 2022 +0100 patch 9.0.0313: using common name in tests leads to flaky tests Problem: Using common name in tests leads to flaky tests. Solution: Rename files and directories to be more specific.
author Bram Moolenaar <Bram@vim.org>
date Mon, 29 Aug 2022 12:15:04 +0200
parents c3570bdc93eb
children 98f5a0618a77
comparison
equal deleted inserted replaced
29949:7553830b0994 29950:c8b1a683323c
74 " commands 74 " commands
75 func Test_buflist_browse() 75 func Test_buflist_browse()
76 %bwipe! 76 %bwipe!
77 call assert_fails('buffer 1000', 'E86:') 77 call assert_fails('buffer 1000', 'E86:')
78 78
79 call writefile(['foo1', 'foo2', 'foo3', 'foo4'], 'Xfile1') 79 call writefile(['foo1', 'foo2', 'foo3', 'foo4'], 'Xbrowse1')
80 call writefile(['bar1', 'bar2', 'bar3', 'bar4'], 'Xfile2') 80 call writefile(['bar1', 'bar2', 'bar3', 'bar4'], 'Xbrowse2')
81 call writefile(['baz1', 'baz2', 'baz3', 'baz4'], 'Xfile3') 81 call writefile(['baz1', 'baz2', 'baz3', 'baz4'], 'Xbrowse3')
82 edit Xfile1 82 edit Xbrowse1
83 let b1 = bufnr() 83 let b1 = bufnr()
84 edit Xfile2 84 edit Xbrowse2
85 let b2 = bufnr() 85 let b2 = bufnr()
86 edit +/baz4 Xfile3 86 edit +/baz4 Xbrowse3
87 let b3 = bufnr() 87 let b3 = bufnr()
88 88
89 call assert_fails('buffer ' .. b1 .. ' abc', 'E488:') 89 call assert_fails('buffer ' .. b1 .. ' abc', 'E488:')
90 call assert_equal(b3, bufnr()) 90 call assert_equal(b3, bufnr())
91 call assert_equal(4, line('.')) 91 call assert_equal(4, line('.'))
125 call assert_fails('bprev', 'E85:') 125 call assert_fails('bprev', 'E85:')
126 set buflisted 126 set buflisted
127 127
128 call assert_fails('sandbox bnext', 'E48:') 128 call assert_fails('sandbox bnext', 'E48:')
129 129
130 call delete('Xfile1') 130 call delete('Xbrowse1')
131 call delete('Xfile2') 131 call delete('Xbrowse2')
132 call delete('Xfile3') 132 call delete('Xbrowse3')
133 %bwipe! 133 %bwipe!
134 endfunc 134 endfunc
135 135
136 " Test for :bdelete 136 " Test for :bdelete
137 func Test_bdelete_cmd() 137 func Test_bdelete_cmd()
198 endfunc 198 endfunc
199 199
200 " Test for quitting the 'swapfile exists' dialog with the split buffer 200 " Test for quitting the 'swapfile exists' dialog with the split buffer
201 " command. 201 " command.
202 func Test_buffer_sbuf_cleanup() 202 func Test_buffer_sbuf_cleanup()
203 call writefile([], 'Xfile') 203 call writefile([], 'XsplitCleanup')
204 " first open the file in a buffer 204 " first open the file in a buffer
205 new Xfile 205 new XsplitCleanup
206 let bnr = bufnr() 206 let bnr = bufnr()
207 close 207 close
208 " create the swap file 208 " create the swap file
209 call writefile([], '.Xfile.swp') 209 call writefile([], '.XsplitCleanup.swp')
210 " Remove the catch-all that runtest.vim adds 210 " Remove the catch-all that runtest.vim adds
211 au! SwapExists 211 au! SwapExists
212 augroup BufTest 212 augroup BufTest
213 au! 213 au!
214 autocmd SwapExists Xfile let v:swapchoice='q' 214 autocmd SwapExists XsplitCleanup let v:swapchoice='q'
215 augroup END 215 augroup END
216 exe 'sbuf ' . bnr 216 exe 'sbuf ' . bnr
217 call assert_equal(1, winnr('$')) 217 call assert_equal(1, winnr('$'))
218 call assert_equal(0, getbufinfo('Xfile')[0].loaded) 218 call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded)
219 219
220 " test for :sball 220 " test for :sball
221 sball 221 sball
222 call assert_equal(1, winnr('$')) 222 call assert_equal(1, winnr('$'))
223 call assert_equal(0, getbufinfo('Xfile')[0].loaded) 223 call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded)
224 224
225 %bw! 225 %bw!
226 set shortmess+=F 226 set shortmess+=F
227 let v:statusmsg = '' 227 let v:statusmsg = ''
228 edit Xfile 228 edit XsplitCleanup
229 call assert_equal('', v:statusmsg) 229 call assert_equal('', v:statusmsg)
230 call assert_equal(1, winnr('$')) 230 call assert_equal(1, winnr('$'))
231 call assert_equal(0, getbufinfo('Xfile')[0].loaded) 231 call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded)
232 set shortmess& 232 set shortmess&
233 233
234 call delete('Xfile') 234 call delete('XsplitCleanup')
235 call delete('.Xfile.swp') 235 call delete('.XsplitCleanup.swp')
236 augroup BufTest 236 augroup BufTest
237 au! 237 au!
238 augroup END 238 augroup END
239 augroup! BufTest 239 augroup! BufTest
240 endfunc 240 endfunc
259 " Test for editing another buffer from a modified buffer with :confirm 259 " Test for editing another buffer from a modified buffer with :confirm
260 func Test_goto_buf_with_confirm() 260 func Test_goto_buf_with_confirm()
261 CheckUnix 261 CheckUnix
262 CheckNotGui 262 CheckNotGui
263 CheckFeature dialog_con 263 CheckFeature dialog_con
264 new Xfile 264 new XgotoConf
265 enew 265 enew
266 call setline(1, 'test') 266 call setline(1, 'test')
267 call assert_fails('b Xfile', 'E37:') 267 call assert_fails('b XgotoConf', 'E37:')
268 call feedkeys('c', 'L') 268 call feedkeys('c', 'L')
269 call assert_fails('confirm b Xfile', 'E37:') 269 call assert_fails('confirm b XgotoConf', 'E37:')
270 call assert_equal(1, &modified) 270 call assert_equal(1, &modified)
271 call assert_equal('', @%) 271 call assert_equal('', @%)
272 call feedkeys('y', 'L') 272 call feedkeys('y', 'L')
273 call assert_fails('confirm b Xfile', ['', 'E37:']) 273 call assert_fails('confirm b XgotoConf', ['', 'E37:'])
274 call assert_equal(1, &modified) 274 call assert_equal(1, &modified)
275 call assert_equal('', @%) 275 call assert_equal('', @%)
276 call feedkeys('n', 'L') 276 call feedkeys('n', 'L')
277 confirm b Xfile 277 confirm b XgotoConf
278 call assert_equal('Xfile', @%) 278 call assert_equal('XgotoConf', @%)
279 close! 279 close!
280 endfunc 280 endfunc
281 281
282 " Test for splitting buffer with 'switchbuf' 282 " Test for splitting buffer with 'switchbuf'
283 func Test_buffer_switchbuf() 283 func Test_buffer_switchbuf()
284 new Xfile 284 new Xswitchbuf
285 wincmd w 285 wincmd w
286 set switchbuf=useopen 286 set switchbuf=useopen
287 sbuf Xfile 287 sbuf Xswitchbuf
288 call assert_equal(1, winnr()) 288 call assert_equal(1, winnr())
289 call assert_equal(2, winnr('$')) 289 call assert_equal(2, winnr('$'))
290 set switchbuf=usetab 290 set switchbuf=usetab
291 tabnew 291 tabnew
292 sbuf Xfile 292 sbuf Xswitchbuf
293 call assert_equal(1, tabpagenr()) 293 call assert_equal(1, tabpagenr())
294 call assert_equal(2, tabpagenr('$')) 294 call assert_equal(2, tabpagenr('$'))
295 set switchbuf& 295 set switchbuf&
296 %bw 296 %bw
297 endfunc 297 endfunc
299 " Test for BufAdd autocommand wiping out the buffer 299 " Test for BufAdd autocommand wiping out the buffer
300 func Test_bufadd_autocmd_bwipe() 300 func Test_bufadd_autocmd_bwipe()
301 %bw! 301 %bw!
302 augroup BufAdd_Wipe 302 augroup BufAdd_Wipe
303 au! 303 au!
304 autocmd BufAdd Xfile %bw! 304 autocmd BufAdd Xbwipe %bw!
305 augroup END 305 augroup END
306 edit Xfile 306 edit Xbwipe
307 call assert_equal('', @%) 307 call assert_equal('', @%)
308 call assert_equal(0, bufexists('Xfile')) 308 call assert_equal(0, bufexists('Xbwipe'))
309 augroup BufAdd_Wipe 309 augroup BufAdd_Wipe
310 au! 310 au!
311 augroup END 311 augroup END
312 augroup! BufAdd_Wipe 312 augroup! BufAdd_Wipe
313 endfunc 313 endfunc
323 endfunc 323 endfunc
324 324
325 " Test for using CTRL-^ to edit the alternative file keeping the cursor 325 " Test for using CTRL-^ to edit the alternative file keeping the cursor
326 " position with 'nostartofline'. Also test using the 'buf' command. 326 " position with 'nostartofline'. Also test using the 'buf' command.
327 func Test_buffer_edit_altfile() 327 func Test_buffer_edit_altfile()
328 call writefile(repeat(['one two'], 50), 'Xfile1') 328 call writefile(repeat(['one two'], 50), 'Xaltfile1')
329 call writefile(repeat(['five six'], 50), 'Xfile2') 329 call writefile(repeat(['five six'], 50), 'Xaltfile2')
330 set nosol 330 set nosol
331 edit Xfile1 331 edit Xaltfile1
332 call cursor(25, 5) 332 call cursor(25, 5)
333 edit Xfile2 333 edit Xaltfile2
334 call cursor(30, 4) 334 call cursor(30, 4)
335 exe "normal \<C-^>" 335 exe "normal \<C-^>"
336 call assert_equal([0, 25, 5, 0], getpos('.')) 336 call assert_equal([0, 25, 5, 0], getpos('.'))
337 exe "normal \<C-^>" 337 exe "normal \<C-^>"
338 call assert_equal([0, 30, 4, 0], getpos('.')) 338 call assert_equal([0, 30, 4, 0], getpos('.'))
339 buf Xfile1 339 buf Xaltfile1
340 call assert_equal([0, 25, 5, 0], getpos('.')) 340 call assert_equal([0, 25, 5, 0], getpos('.'))
341 buf Xfile2 341 buf Xaltfile2
342 call assert_equal([0, 30, 4, 0], getpos('.')) 342 call assert_equal([0, 30, 4, 0], getpos('.'))
343 set sol& 343 set sol&
344 call delete('Xfile1') 344 call delete('Xaltfile1')
345 call delete('Xfile2') 345 call delete('Xaltfile2')
346 endfunc 346 endfunc
347 347
348 " Test for running the :sball command with a maximum window count and a 348 " Test for running the :sball command with a maximum window count and a
349 " modified buffer 349 " modified buffer
350 func Test_sball_with_count() 350 func Test_sball_with_count()
351 %bw! 351 %bw!
352 edit Xfile1 352 edit Xcountfile1
353 call setline(1, ['abc']) 353 call setline(1, ['abc'])
354 new Xfile2 354 new Xcountfile2
355 new Xfile3 355 new Xcountfile3
356 new Xfile4 356 new Xcountfile4
357 2sball 357 2sball
358 call assert_equal(bufnr('Xfile4'), winbufnr(1)) 358 call assert_equal(bufnr('Xcountfile4'), winbufnr(1))
359 call assert_equal(bufnr('Xfile1'), winbufnr(2)) 359 call assert_equal(bufnr('Xcountfile1'), winbufnr(2))
360 call assert_equal(0, getbufinfo('Xfile2')[0].loaded) 360 call assert_equal(0, getbufinfo('Xcountfile2')[0].loaded)
361 call assert_equal(0, getbufinfo('Xfile3')[0].loaded) 361 call assert_equal(0, getbufinfo('Xcountfile3')[0].loaded)
362 %bw! 362 %bw!
363 endfunc 363 endfunc
364 364
365 func Test_badd_options() 365 func Test_badd_options()
366 new SomeNewBuffer 366 new SomeNewBuffer
449 449
450 " Test for buffer allocation failure 450 " Test for buffer allocation failure
451 func Test_buflist_alloc_failure() 451 func Test_buflist_alloc_failure()
452 %bw! 452 %bw!
453 453
454 edit Xfile1 454 edit XallocFail1
455 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) 455 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
456 call assert_fails('edit Xfile2', 'E342:') 456 call assert_fails('edit XallocFail2', 'E342:')
457 457
458 " test for bufadd() 458 " test for bufadd()
459 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) 459 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
460 call assert_fails('call bufadd("Xbuffer")', 'E342:') 460 call assert_fails('call bufadd("Xbuffer")', 'E342:')
461 461
462 " test for setting the arglist 462 " test for setting the arglist
463 edit Xfile2 463 edit XallocFail2
464 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) 464 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
465 call assert_fails('next Xfile3', 'E342:') 465 call assert_fails('next XallocFail3', 'E342:')
466 466
467 " test for setting the alternate buffer name when writing a file 467 " test for setting the alternate buffer name when writing a file
468 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) 468 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
469 call assert_fails('write Xother', 'E342:') 469 call assert_fails('write Xother', 'E342:')
470 call delete('Xother') 470 call delete('Xother')
487 call assert_fails('call term_start(&shell)', 'E342:') 487 call assert_fails('call term_start(&shell)', 'E342:')
488 %bw! 488 %bw!
489 endif 489 endif
490 490
491 " test for loading a new buffer after wiping out all the buffers 491 " test for loading a new buffer after wiping out all the buffers
492 edit Xfile4 492 edit XallocFail4
493 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) 493 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
494 call assert_fails('%bw!', 'E342:') 494 call assert_fails('%bw!', 'E342:')
495 495
496 " test for :checktime loading the buffer 496 " test for :checktime loading the buffer
497 call writefile(['one'], 'Xfile5') 497 call writefile(['one'], 'XallocFail5')
498 if has('unix') 498 if has('unix')
499 edit Xfile5 499 edit XallocFail5
500 " sleep for some time to make sure the timestamp is different 500 " sleep for some time to make sure the timestamp is different
501 sleep 200m 501 sleep 200m
502 call writefile(['two'], 'Xfile5') 502 call writefile(['two'], 'XallocFail5')
503 set autoread 503 set autoread
504 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) 504 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
505 call assert_fails('checktime', 'E342:') 505 call assert_fails('checktime', 'E342:')
506 set autoread& 506 set autoread&
507 bw! 507 bw!
508 endif 508 endif
509 509
510 " test for :vimgrep loading a dummy buffer 510 " test for :vimgrep loading a dummy buffer
511 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) 511 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
512 call assert_fails('vimgrep two Xfile5', 'E342:') 512 call assert_fails('vimgrep two XallocFail5', 'E342:')
513 call delete('Xfile5') 513 call delete('XallocFail5')
514 514
515 " test for quickfix command loading a buffer 515 " test for quickfix command loading a buffer
516 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) 516 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
517 call assert_fails('cexpr "Xfile6:10:Line10"', 'E342:') 517 call assert_fails('cexpr "XallocFail6:10:Line10"', 'E342:')
518 endfunc 518 endfunc
519 519
520 " vim: shiftwidth=2 sts=2 expandtab 520 " vim: shiftwidth=2 sts=2 expandtab