comparison src/testdir/test_swap.vim @ 22995:94656f3ff304 v8.2.2044

patch 8.2.2044: MS-Windows: swap file test sometimes fails Commit: https://github.com/vim/vim/commit/5ee0981fb5259f94900ab25207caddf1fa61010d Author: Bram Moolenaar <Bram@vim.org> Date: Wed Nov 25 12:43:28 2020 +0100 patch 8.2.2044: MS-Windows: swap file test sometimes fails Problem: MS-Windows: swap file test sometimes fails. Solution: Use a more reliable way to change the process ID. When "timeout" fails use "ping" to wait up to ten minutes. (Ken Takata, closes #7365)
author Bram Moolenaar <Bram@vim.org>
date Wed, 25 Nov 2020 12:45:03 +0100
parents 815f3a6b05ca
children 4c5eec1ef612
comparison
equal deleted inserted replaced
22994:1d635e77266d 22995:94656f3ff304
401 call delete('Xtestfile') 401 call delete('Xtestfile')
402 call delete('Xtestlink') 402 call delete('Xtestlink')
403 call delete('Xswapdir', 'rf') 403 call delete('Xswapdir', 'rf')
404 endfunc 404 endfunc
405 405
406 func s:get_unused_pid(base)
407 if has('job')
408 " Execute 'echo' as a temporary job, and return its pid as an unused pid.
409 if has('win32')
410 let cmd = 'cmd /c echo'
411 else
412 let cmd = 'echo'
413 endif
414 let j = job_start(cmd)
415 while job_status(j) ==# 'run'
416 sleep 10m
417 endwhile
418 if job_status(j) ==# 'dead'
419 return job_info(j).process
420 endif
421 endif
422 " Must add four for MS-Windows to see it as a different one.
423 return a:base + 4
424 endfunc
425
426 func s:blob_to_pid(b)
427 return a:b[3] * 16777216 + a:b[2] * 65536 + a:b[1] * 256 + a:b[0]
428 endfunc
429
430 func s:pid_to_blob(i)
431 let b = 0z
432 let b[0] = and(a:i, 0xff)
433 let b[1] = and(a:i / 256, 0xff)
434 let b[2] = and(a:i / 65536, 0xff)
435 let b[3] = and(a:i / 16777216, 0xff)
436 return b
437 endfunc
438
406 func Test_swap_auto_delete() 439 func Test_swap_auto_delete()
407 " Create a valid swapfile by editing a file with a special extension. 440 " Create a valid swapfile by editing a file with a special extension.
408 split Xtest.scr 441 split Xtest.scr
409 call setline(1, ['one', 'two', 'three']) 442 call setline(1, ['one', 'two', 'three'])
410 write " file is written, not modified 443 write " file is written, not modified
414 let swapfile_bytes = readfile(swapfile_name, 'B') 447 let swapfile_bytes = readfile(swapfile_name, 'B')
415 448
416 " Forget about the file, recreate the swap file, then edit it again. The 449 " Forget about the file, recreate the swap file, then edit it again. The
417 " swap file should be automatically deleted. 450 " swap file should be automatically deleted.
418 bwipe! 451 bwipe!
419 " Change the process ID to avoid the "still running" warning. Must add four 452 " Change the process ID to avoid the "still running" warning.
420 " for MS-Windows to see it as a different one. 453 let swapfile_bytes[24:27] = s:pid_to_blob(s:get_unused_pid(
421 let swapfile_bytes[24] = swapfile_bytes[24] + 4 454 \ s:blob_to_pid(swapfile_bytes[24:27])))
422 call writefile(swapfile_bytes, swapfile_name) 455 call writefile(swapfile_bytes, swapfile_name)
423 edit Xtest.scr 456 edit Xtest.scr
424 " will end up using the same swap file after deleting the existing one 457 " will end up using the same swap file after deleting the existing one
425 call assert_equal(swapfile_name, swapname('%')) 458 call assert_equal(swapfile_name, swapname('%'))
426 bwipe! 459 bwipe!