blob: 8408ff369386c232241c9123377436f750c65cd9 [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:')
Bram Moolenaar00e192b2019-10-19 17:01:28 +020015
16 " No error with empty 'directory' setting.
17 set directory=
18 split XtestOK
19 close!
20
Bram Moolenaarc525e3a2017-02-18 16:59:02 +010021 set dir&
22endfunc
23
Bram Moolenaar4a6fcf82017-10-12 21:29:22 +020024" Inserts 10000 lines with text to fill the swap file with two levels of pointer
25" blocks. Then recovers from the swap file and checks all text is restored.
26"
27" We need about 10000 lines of 100 characters to get two levels of pointer
28" blocks.
29func Test_swap_file()
Bram Moolenaar67418d92017-10-15 22:07:39 +020030 set fileformat=unix undolevels=-1
Bram Moolenaar4a6fcf82017-10-12 21:29:22 +020031 edit! Xtest
32 let text = "\tabcdefghijklmnoparstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnoparstuvwxyz0123456789"
33 let i = 1
34 let linecount = 10000
35 while i <= linecount
36 call append(i - 1, i . text)
37 let i += 1
38 endwhile
39 $delete
40 preserve
41 " get the name of the swap file
42 let swname = split(execute("swapname"))[0]
43 let swname = substitute(swname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', '')
44 " make a copy of the swap file in Xswap
45 set binary
46 exe 'sp ' . swname
47 w! Xswap
48 set nobinary
49 new
50 only!
51 bwipe! Xtest
52 call rename('Xswap', swname)
53 recover Xtest
54 call delete(swname)
55 let linedollar = line('$')
56 call assert_equal(linecount, linedollar)
57 if linedollar < linecount
58 let linecount = linedollar
59 endif
60 let i = 1
61 while i <= linecount
62 call assert_equal(i . text, getline(i))
63 let i += 1
64 endwhile
65
66 set undolevels&
67 enew! | only
68endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020069
70" vim: shiftwidth=2 sts=2 expandtab