comparison src/testdir/test_autocmd.vim @ 15611:bfcd7ffe9ac2 v8.1.0813

patch 8.1.0813: FileChangedShell not sufficiently tested commit https://github.com/vim/vim/commit/0566e891f73897486de3f0ac194795eeca0097d6 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 24 19:37:40 2019 +0100 patch 8.1.0813: FileChangedShell not sufficiently tested Problem: FileChangedShell not sufficiently tested. Solution: Add a more comprehensive test case.
author Bram Moolenaar <Bram@vim.org>
date Thu, 24 Jan 2019 19:45:07 +0100
parents 63b02fcf1361
children 536fca2cee19
comparison
equal deleted inserted replaced
15610:9225b04920f4 15611:bfcd7ffe9ac2
1383 1383
1384 " clean up 1384 " clean up
1385 call delete('Xchanged.txt') 1385 call delete('Xchanged.txt')
1386 bwipe! 1386 bwipe!
1387 endfunc 1387 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