blob: a9934a162490bfd2476578cd8cef92ce9ad17eb2 [file] [log] [blame]
Bram Moolenaarc525e3a2017-02-18 16:59:02 +01001" Test :recover
2
3func Test_recover_root_dir()
4 " This used to access invalid memory.
5 split Xtest
6 set dir=/
7 call assert_fails('recover', 'E305:')
8 close!
9
Bram Moolenaar2a0b06d2017-05-18 16:23:43 +020010 if has('win32') || filewritable('/') == 2
Bram Moolenaar80345202017-02-18 22:43:19 +010011 " can write in / directory on MS-Windows
12 set dir=/notexist/
13 endif
Bram Moolenaarc525e3a2017-02-18 16:59:02 +010014 call assert_fails('split Xtest', 'E303:')
15 set dir&
16endfunc
17
Bram Moolenaar4a6fcf82017-10-12 21:29:22 +020018" Inserts 10000 lines with text to fill the swap file with two levels of pointer
19" blocks. Then recovers from the swap file and checks all text is restored.
20"
21" We need about 10000 lines of 100 characters to get two levels of pointer
22" blocks.
23func Test_swap_file()
Bram Moolenaar67418d92017-10-15 22:07:39 +020024 set fileformat=unix undolevels=-1
Bram Moolenaar4a6fcf82017-10-12 21:29:22 +020025 edit! Xtest
26 let text = "\tabcdefghijklmnoparstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnoparstuvwxyz0123456789"
27 let i = 1
28 let linecount = 10000
29 while i <= linecount
30 call append(i - 1, i . text)
31 let i += 1
32 endwhile
33 $delete
34 preserve
35 " get the name of the swap file
36 let swname = split(execute("swapname"))[0]
37 let swname = substitute(swname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', '')
38 " make a copy of the swap file in Xswap
39 set binary
40 exe 'sp ' . swname
41 w! Xswap
42 set nobinary
43 new
44 only!
45 bwipe! Xtest
46 call rename('Xswap', swname)
47 recover Xtest
48 call delete(swname)
49 let linedollar = line('$')
50 call assert_equal(linecount, linedollar)
51 if linedollar < linecount
52 let linecount = linedollar
53 endif
54 let i = 1
55 while i <= linecount
56 call assert_equal(i . text, getline(i))
57 let i += 1
58 endwhile
59
60 set undolevels&
61 enew! | only
62endfunc