comparison src/testdir/test_swap.vim @ 16738:b52ea9c5f1db v8.1.1371

patch 8.1.1371: cannot recover from a swap file commit https://github.com/vim/vim/commit/99499b1c05f85f83876b828eea3f6e14f0f407b4 Author: Bram Moolenaar <Bram@vim.org> Date: Thu May 23 21:35:48 2019 +0200 patch 8.1.1371: cannot recover from a swap file Problem: Cannot recover from a swap file. Solution: Do not expand environment variables in the swap file name. Do not check the extension when we already know a file is a swap file. (Ken Takata, closes 4415, closes #4369)
author Bram Moolenaar <Bram@vim.org>
date Thu, 23 May 2019 21:45:07 +0200
parents 4ea761ce795b
children 988e5a868b60
comparison
equal deleted inserted replaced
16737:e56018f01ba7 16738:b52ea9c5f1db
218 augroup test_swapfile_delete 218 augroup test_swapfile_delete
219 autocmd! 219 autocmd!
220 augroup END 220 augroup END
221 augroup! test_swapfile_delete 221 augroup! test_swapfile_delete
222 endfunc 222 endfunc
223
224 func Test_swap_recover()
225 autocmd! SwapExists
226 augroup test_swap_recover
227 autocmd!
228 autocmd SwapExists * let v:swapchoice = 'r'
229 augroup END
230
231
232 call mkdir('Xswap')
233 let $Xswap = 'foo' " Check for issue #4369.
234 set dir=Xswap//
235 " Create a valid swapfile by editing a file.
236 split Xswap/text
237 call setline(1, ['one', 'two', 'three'])
238 write " file is written, not modified
239 " read the swapfile as a Blob
240 let swapfile_name = swapname('%')
241 let swapfile_bytes = readfile(swapfile_name, 'B')
242
243 " Close the file and recreate the swap file.
244 quit
245 call writefile(swapfile_bytes, swapfile_name)
246 " Edit the file again. This triggers recovery.
247 try
248 split Xswap/text
249 catch
250 " E308 should be caught, not E305.
251 call assert_exception('E308:') " Original file may have been changed
252 endtry
253 " The file should be recovered.
254 call assert_equal(['one', 'two', 'three'], getline(1, 3))
255 quit!
256
257 call delete('Xswap/text')
258 call delete(swapfile_name)
259 call delete('Xswap', 'd')
260 unlet $Xswap
261 set dir&
262 augroup test_swap_recover
263 autocmd!
264 augroup END
265 augroup! test_swap_recover
266 endfunc
267
268 func Test_swap_recover_ext()
269 autocmd! SwapExists
270 augroup test_swap_recover_ext
271 autocmd!
272 autocmd SwapExists * let v:swapchoice = 'r'
273 augroup END
274
275
276 " Create a valid swapfile by editing a file with a special extension.
277 split Xtest.scr
278 call setline(1, ['one', 'two', 'three'])
279 write " file is written, not modified
280 write " write again to make sure the swapfile is created
281 " read the swapfile as a Blob
282 let swapfile_name = swapname('%')
283 let swapfile_bytes = readfile(swapfile_name, 'B')
284
285 " Close and delete the file and recreate the swap file.
286 quit
287 call delete('Xtest.scr')
288 call writefile(swapfile_bytes, swapfile_name)
289 " Edit the file again. This triggers recovery.
290 try
291 split Xtest.scr
292 catch
293 " E308 should be caught, not E306.
294 call assert_exception('E308:') " Original file may have been changed
295 endtry
296 " The file should be recovered.
297 call assert_equal(['one', 'two', 'three'], getline(1, 3))
298 quit!
299
300 call delete('Xtest.scr')
301 call delete(swapfile_name)
302 augroup test_swap_recover_ext
303 autocmd!
304 augroup END
305 augroup! test_swap_recover_ext
306 endfunc