]> granicus.if.org Git - vim/commitdiff
patch 8.1.0813: FileChangedShell not sufficiently tested v8.1.0813
authorBram Moolenaar <Bram@vim.org>
Thu, 24 Jan 2019 18:37:40 +0000 (19:37 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 24 Jan 2019 18:37:40 +0000 (19:37 +0100)
Problem:    FileChangedShell not sufficiently tested.
Solution:   Add a more comprehensive test case.

src/testdir/test_autocmd.vim
src/version.c

index 4582d1a9894ac617f5f1d807aed5f2e5c6703133..6f27fe512c584a0340828f8a258e4b6b7b2faea4 100644 (file)
@@ -1385,3 +1385,93 @@ func Test_Changed_FirstTime()
   call delete('Xchanged.txt')
   bwipe!
 endfunc
+
+func Test_FileChangedShell_reload()
+  if !has('unix')
+    return
+  endif
+  augroup testreload
+    au FileChangedShell Xchanged let g:reason = v:fcs_reason | let v:fcs_choice = 'reload'
+  augroup END
+  new Xchanged
+  call setline(1, 'reload this')
+  write
+  " Need to wait until the timestamp would change by at least a second.
+  sleep 2
+  silent !echo 'extra line' >>Xchanged
+  checktime
+  call assert_equal('changed', g:reason)
+  call assert_equal(2, line('$'))
+  call assert_equal('extra line', getline(2))
+
+  " Only triggers once
+  let g:reason = ''
+  checktime
+  call assert_equal('', g:reason)
+
+  " When deleted buffer is not reloaded
+  silent !rm Xchanged
+  let g:reason = ''
+  checktime
+  call assert_equal('deleted', g:reason)
+  call assert_equal(2, line('$'))
+  call assert_equal('extra line', getline(2))
+
+  " When recreated buffer is reloaded
+  call setline(1, 'buffer is changed')
+  silent !echo 'new line' >>Xchanged
+  let g:reason = ''
+  checktime
+  call assert_equal('conflict', g:reason)
+  call assert_equal(1, line('$'))
+  call assert_equal('new line', getline(1))
+
+  " Only mode changed
+  silent !chmod +x Xchanged
+  let g:reason = ''
+  checktime
+  call assert_equal('mode', g:reason)
+  call assert_equal(1, line('$'))
+  call assert_equal('new line', getline(1))
+
+  " Only time changed
+  sleep 2
+  silent !touch Xchanged
+  let g:reason = ''
+  checktime
+  call assert_equal('time', g:reason)
+  call assert_equal(1, line('$'))
+  call assert_equal('new line', getline(1))
+
+  if has('persistent_undo')
+    " With an undo file the reload can be undone and a change before the
+    " reload.
+    set undofile
+    call setline(2, 'before write')
+    write
+    call setline(2, 'after write')
+    sleep 2
+    silent !echo 'different line' >>Xchanged
+    let g:reason = ''
+    checktime
+    call assert_equal('conflict', g:reason)
+    call assert_equal(3, line('$'))
+    call assert_equal('before write', getline(2))
+    call assert_equal('different line', getline(3))
+    " undo the reload
+    undo
+    call assert_equal(2, line('$'))
+    call assert_equal('after write', getline(2))
+    " undo the change before reload
+    undo
+    call assert_equal(2, line('$'))
+    call assert_equal('before write', getline(2))
+
+    set noundofile
+  endif
+
+
+  au! testreload
+  bwipe!
+  call delete('Xchanged')
+endfunc
index 111464169a3b29e78e31a969037987076539ace9..230d2fb9b6f40cb9748160127eea678149179372 100644 (file)
@@ -787,6 +787,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    813,
 /**/
     812,
 /**/