078_swapfile_recover_spec.lua 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. -- Inserts 10000 lines with text to fill the swap file with two levels of
  2. -- pointer blocks. Then recovers from the swap file and checks all text is
  3. -- restored. We need about 10000 lines of 100 characters to get two levels of
  4. -- pointer blocks.
  5. local helpers = require('test.functional.helpers')(after_each)
  6. local clear, expect, source = helpers.clear, helpers.expect, helpers.source
  7. describe('78', function()
  8. setup(clear)
  9. teardown(function()
  10. os.remove(".Xtest.swp")
  11. os.remove(".Xtest.swo")
  12. end)
  13. it('is working', function()
  14. source([=[
  15. set directory=. swapfile fileformat=unix undolevels=-1
  16. e! Xtest
  17. let text = "\tabcdefghijklmnoparstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnoparstuvwxyz0123456789"
  18. let i = 1
  19. let linecount = 10000
  20. while i <= linecount | call append(i - 1, i . text) | let i += 1 | endwhile
  21. preserve
  22. " Get the name of the swap file, and clean up the :redir capture.
  23. redir => g:swapname | swapname | redir END
  24. let g:swapname = substitute(g:swapname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', 'g')
  25. let g:swapname = fnameescape(g:swapname)
  26. " Make a copy of the swap file in Xswap
  27. set bin
  28. exe 'sp ' . g:swapname
  29. w! Xswap
  30. set nobin
  31. new
  32. only!
  33. bwipe! Xtest
  34. call rename('Xswap', g:swapname)
  35. "TODO(jkeyes): without 'silent', this hangs the test " at message:
  36. " 'Recovery completed. You should check if everything is OK.'
  37. silent recover Xtest
  38. call delete(g:swapname)
  39. new
  40. call append(0, 'recovery start')
  41. wincmd w
  42. let g:linedollar = line('$')
  43. if g:linedollar < linecount
  44. wincmd w
  45. call append(line('$'), "expected " . linecount
  46. \ . " lines but found only " . g:linedollar)
  47. wincmd w
  48. let linecount = g:linedollar
  49. endif
  50. let i = 1
  51. while i <= linecount
  52. if getline(i) != i . text
  53. exe 'wincmd w'
  54. call append(line('$'), i . ' differs')
  55. exe 'wincmd w'
  56. endif
  57. let i += 1
  58. endwhile
  59. q!
  60. call append(line('$'), 'recovery end')
  61. ]=])
  62. expect([[
  63. recovery start
  64. recovery end]])
  65. end)
  66. end)