Skip to content

Commit 0566e89

Browse files
committed
patch 8.1.0813: FileChangedShell not sufficiently tested
Problem: FileChangedShell not sufficiently tested. Solution: Add a more comprehensive test case.
1 parent 9ba6117 commit 0566e89

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

src/testdir/test_autocmd.vim

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,3 +1385,93 @@ func Test_Changed_FirstTime()
13851385
call delete('Xchanged.txt')
13861386
bwipe!
13871387
endfunc
1388+
1389+
func Test_FileChangedShell_reload()
1390+
if !has('unix')
1391+
return
1392+
endif
1393+
augroup testreload
1394+
au FileChangedShell Xchanged let g:reason = v:fcs_reason | let v:fcs_choice = 'reload'
1395+
augroup END
1396+
new Xchanged
1397+
call setline(1, 'reload this')
1398+
write
1399+
" Need to wait until the timestamp would change by at least a second.
1400+
sleep 2
1401+
silent !echo 'extra line' >>Xchanged
1402+
checktime
1403+
call assert_equal('changed', g:reason)
1404+
call assert_equal(2, line('$'))
1405+
call assert_equal('extra line', getline(2))
1406+
1407+
" Only triggers once
1408+
let g:reason = ''
1409+
checktime
1410+
call assert_equal('', g:reason)
1411+
1412+
" When deleted buffer is not reloaded
1413+
silent !rm Xchanged
1414+
let g:reason = ''
1415+
checktime
1416+
call assert_equal('deleted', g:reason)
1417+
call assert_equal(2, line('$'))
1418+
call assert_equal('extra line', getline(2))
1419+
1420+
" When recreated buffer is reloaded
1421+
call setline(1, 'buffer is changed')
1422+
silent !echo 'new line' >>Xchanged
1423+
let g:reason = ''
1424+
checktime
1425+
call assert_equal('conflict', g:reason)
1426+
call assert_equal(1, line('$'))
1427+
call assert_equal('new line', getline(1))
1428+
1429+
" Only mode changed
1430+
silent !chmod +x Xchanged
1431+
let g:reason = ''
1432+
checktime
1433+
call assert_equal('mode', g:reason)
1434+
call assert_equal(1, line('$'))
1435+
call assert_equal('new line', getline(1))
1436+
1437+
" Only time changed
1438+
sleep 2
1439+
silent !touch Xchanged
1440+
let g:reason = ''
1441+
checktime
1442+
call assert_equal('time', g:reason)
1443+
call assert_equal(1, line('$'))
1444+
call assert_equal('new line', getline(1))
1445+
1446+
if has('persistent_undo')
1447+
" With an undo file the reload can be undone and a change before the
1448+
" reload.
1449+
set undofile
1450+
call setline(2, 'before write')
1451+
write
1452+
call setline(2, 'after write')
1453+
sleep 2
1454+
silent !echo 'different line' >>Xchanged
1455+
let g:reason = ''
1456+
checktime
1457+
call assert_equal('conflict', g:reason)
1458+
call assert_equal(3, line('$'))
1459+
call assert_equal('before write', getline(2))
1460+
call assert_equal('different line', getline(3))
1461+
" undo the reload
1462+
undo
1463+
call assert_equal(2, line('$'))
1464+
call assert_equal('after write', getline(2))
1465+
" undo the change before reload
1466+
undo
1467+
call assert_equal(2, line('$'))
1468+
call assert_equal('before write', getline(2))
1469+
1470+
set noundofile
1471+
endif
1472+
1473+
1474+
au! testreload
1475+
bwipe!
1476+
call delete('Xchanged')
1477+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,8 @@ static char *(features[]) =
787787

788788
static int included_patches[] =
789789
{ /* Add new patch number below this line */
790+
/**/
791+
813,
790792
/**/
791793
812,
792794
/**/

0 commit comments

Comments
 (0)