annotate src/testdir/test_recover.vim @ 32669:448aef880252

normalize line endings
author Christian Brabandt <cb@256bit.org>
date Mon, 26 Jun 2023 09:54:34 +0200
parents aa90a1f1a523
children 695b50472e85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
1 " Test :recover
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
3 source check.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
4
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
5 func Test_recover_root_dir()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
6 " This used to access invalid memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
7 split Xtest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
8 set dir=/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
9 call assert_fails('recover', 'E305:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
10 close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
11
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
12 if has('win32') || filewritable('/') == 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
13 " can write in / directory on MS-Windows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
14 set dir=/notexist/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
15 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
16 call assert_fails('split Xtest', 'E303:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
17
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
18 " No error with empty 'directory' setting.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
19 set directory=
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
20 split XtestOK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
21 close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
22
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
23 set dir&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
24 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
25
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
26 " Make a copy of the current swap file to "Xswap".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
27 " Return the name of the swap file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
28 func CopySwapfile()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
29 preserve
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
30 " get the name of the swap file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
31 let swname = split(execute("swapname"))[0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
32 let swname = substitute(swname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
33 " make a copy of the swap file in Xswap
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
34 set binary
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
35 exe 'sp ' . swname
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
36 w! Xswap
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
37 set nobinary
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
38 return swname
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
39 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
40
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
41 " Inserts 10000 lines with text to fill the swap file with two levels of pointer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
42 " blocks. Then recovers from the swap file and checks all text is restored.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
43 "
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
44 " We need about 10000 lines of 100 characters to get two levels of pointer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
45 " blocks.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
46 func Test_swap_file()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
47 set fileformat=unix undolevels=-1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
48 edit! Xtest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
49 let text = "\tabcdefghijklmnoparstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnoparstuvwxyz0123456789"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
50 let i = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
51 let linecount = 10000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
52 while i <= linecount
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
53 call append(i - 1, i . text)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
54 let i += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
55 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
56 $delete
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
57
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
58 let swname = CopySwapfile()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
59
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
60 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
61 only!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
62 bwipe! Xtest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
63 call rename('Xswap', swname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
64 recover Xtest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
65 call delete(swname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
66 let linedollar = line('$')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
67 call assert_equal(linecount, linedollar)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
68 if linedollar < linecount
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
69 let linecount = linedollar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
70 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
71 let i = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
72 while i <= linecount
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
73 call assert_equal(i . text, getline(i))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
74 let i += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
75 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
76
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
77 set undolevels&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
78 enew! | only
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
79 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
80
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
81 func Test_nocatch_process_still_running()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
82 " sysinfo.uptime probably only works on Linux
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
83 if !has('linux')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
84 let g:skipped_reason = 'only works on Linux'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
85 return
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
86 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
87 " the GUI dialog can't be handled
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
88 if has('gui_running')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
89 let g:skipped_reason = 'only works in the terminal'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
90 return
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
91 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
92
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
93 " don't intercept existing swap file here
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
94 au! SwapExists
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
95
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
96 " Edit a file and grab its swapfile.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
97 edit Xswaptest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
98 call setline(1, ['a', 'b', 'c'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
99 let swname = CopySwapfile()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
100
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
101 " Forget we edited this file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
102 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
103 only!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
104 bwipe! Xswaptest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
106 call rename('Xswap', swname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
107 call feedkeys('e', 'tL')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
108 redir => editOutput
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
109 edit Xswaptest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
110 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
111 call assert_match('E325: ATTENTION', editOutput)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
112 call assert_match('file name: .*Xswaptest', editOutput)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
113 call assert_match('process ID: \d* (STILL RUNNING)', editOutput)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
114
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
115 " Forget we edited this file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
116 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
117 only!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
118 bwipe! Xswaptest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
119
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
120 " pretend we rebooted
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
121 call test_override("uptime", 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
122 sleep 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
124 call feedkeys('e', 'tL')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
125 redir => editOutput
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
126 edit Xswaptest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
127 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
128 call assert_match('E325: ATTENTION', editOutput)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
129 call assert_notmatch('(STILL RUNNING)', editOutput)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
130
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
131 call test_override("ALL", 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
132 call delete(swname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
133 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
134
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
135 " Test for :recover with multiple swap files
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
136 func Test_recover_multiple_swap_files()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
137 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
138 new Xfile1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
139 call setline(1, ['a', 'b', 'c'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
140 preserve
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
141 let b = readblob(swapname(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
142 call writefile(b, '.Xfile1.swm', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
143 call writefile(b, '.Xfile1.swn', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
144 call writefile(b, '.Xfile1.swo', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
145 %bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
146 call feedkeys(":recover Xfile1\<CR>3\<CR>q", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
147 call assert_equal(['a', 'b', 'c'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
148 " try using out-of-range number to select a swap file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
149 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
150 call feedkeys(":recover Xfile1\<CR>4\<CR>q", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
151 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
152 call assert_equal([''], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
153 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
154 call feedkeys(":recover Xfile1\<CR>0\<CR>q", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
155 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
156 call assert_equal([''], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
157 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
158 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
159
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
160 " Test for :recover using an empty swap file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
161 func Test_recover_empty_swap_file()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
162 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
163 call writefile([], '.Xfile1.swp', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
164 let msg = execute('recover Xfile1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
165 call assert_match('Unable to read block 0 from .Xfile1.swp', msg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
166 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
167 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
168
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
169 " make sure there are no old swap files laying around
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
170 for f in glob('.sw?', 0, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
171 call delete(f)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
172 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
173
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
174 " :recover from an empty buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
175 call assert_fails('recover', 'E305:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
176 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
177
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
178 " Test for :recover using a corrupted swap file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
179 " Refer to the comments in the memline.c file for the swap file headers
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
180 " definition.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
181 func Test_recover_corrupted_swap_file()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
182 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
183
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
184 " recover using a partial swap file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
185 call writefile(0z1234, '.Xfile1.swp')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
186 call assert_fails('recover Xfile1', 'E295:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
187 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
188
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
189 " recover using invalid content in the swap file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
190 call writefile([repeat('1', 2*1024)], '.Xfile1.swp')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
191 call assert_fails('recover Xfile1', 'E307:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
192 call delete('.Xfile1.swp')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
193
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
194 " :recover using a swap file with a corrupted header
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
195 edit Xfile1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
196 preserve
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
197 let sn = swapname('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
198 let b = readblob(sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
199 let save_b = copy(b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
200 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
201
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
202 " Not all fields are written in a system-independent manner. Detect whether
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
203 " the test is running on a little or big-endian system, so the correct
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
204 " corruption values can be set.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
205 " The B0_MAGIC_LONG field may be 32-bit or 64-bit, depending on the system,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
206 " even though the value stored is only 32-bits. Therefore, need to check
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
207 " both the high and low 32-bits to compute these values.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
208 let little_endian = (b[1008:1011] == 0z33323130) || (b[1012:1015] == 0z33323130)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
209 let system_64bit = little_endian ? (b[1012:1015] == 0z00000000) : (b[1008:1011] == 0z00000000)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
210
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
211 " clear the B0_MAGIC_LONG field
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
212 if system_64bit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
213 let b[1008:1015] = 0z00000000.00000000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
214 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
215 let b[1008:1011] = 0z00000000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
216 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
217 call writefile(b, sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
218 let msg = execute('recover Xfile1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
219 call assert_match('the file has been damaged', msg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
220 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
221 call assert_equal([''], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
222 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
223
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
224 " reduce the page size
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
225 let b = copy(save_b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
226 let b[12:15] = 0z00010000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
227 call writefile(b, sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
228 let msg = execute('recover Xfile1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
229 call assert_match('page size is smaller than minimum value', msg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
230 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
231 call assert_equal([''], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
232 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
233
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
234 " clear the pointer ID
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
235 let b = copy(save_b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
236 let b[4096:4097] = 0z0000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
237 call writefile(b, sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
238 call assert_fails('recover Xfile1', 'E310:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
239 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
240 call assert_equal([''], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
241 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
242
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
243 " set the number of pointers in a pointer block to zero
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
244 let b = copy(save_b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
245 let b[4098:4099] = 0z0000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
246 call writefile(b, sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
247 call assert_fails('recover Xfile1', 'E312:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
248 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
249 call assert_equal(['???EMPTY BLOCK'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
250 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
251
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
252 " set the number of pointers in a pointer block to a large value
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
253 let b = copy(save_b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
254 let b[4098:4099] = 0zFFFF
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
255 call writefile(b, sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
256 call assert_fails('recover Xfile1', 'E1364:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
257 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
258 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
259
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
260 " set the block number in a pointer entry to a negative number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
261 let b = copy(save_b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
262 if system_64bit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
263 let b[4104:4111] = little_endian ? 0z00000000.00000080 : 0z80000000.00000000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
264 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
265 let b[4104:4107] = little_endian ? 0z00000080 : 0z80000000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
266 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
267 call writefile(b, sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
268 call assert_fails('recover Xfile1', 'E312:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
269 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
270 call assert_equal(['???LINES MISSING'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
271 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
272
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
273 " clear the data block ID
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
274 let b = copy(save_b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
275 let b[8192:8193] = 0z0000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
276 call writefile(b, sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
277 call assert_fails('recover Xfile1', 'E312:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
278 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
279 call assert_equal(['???BLOCK MISSING'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
280 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
281
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
282 " set the number of lines in the data block to zero
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
283 let b = copy(save_b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
284 if system_64bit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
285 let b[8208:8215] = 0z00000000.00000000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
286 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
287 let b[8208:8211] = 0z00000000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
288 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
289 call writefile(b, sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
290 call assert_fails('recover Xfile1', 'E312:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
291 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
292 call assert_equal(['??? from here until ???END lines may have been inserted/deleted',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
293 \ '???END'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
294 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
295
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
296 " set the number of lines in the data block to a large value
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
297 let b = copy(save_b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
298 if system_64bit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
299 let b[8208:8215] = 0z00FFFFFF.FFFFFF00
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
300 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
301 let b[8208:8211] = 0z00FFFF00
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
302 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
303 call writefile(b, sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
304 call assert_fails('recover Xfile1', 'E312:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
305 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
306 call assert_equal(['??? from here until ???END lines may have been inserted/deleted',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
307 \ '', '???', '??? lines may be missing',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
308 \ '???END'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
309 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
310
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
311 " use an invalid text start for the lines in a data block
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
312 let b = copy(save_b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
313 if system_64bit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
314 let b[8216:8219] = 0z00000000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
315 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
316 let b[8212:8215] = 0z00000000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
317 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
318 call writefile(b, sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
319 call assert_fails('recover Xfile1', 'E312:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
320 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
321 call assert_equal(['???'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
322 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
323
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
324 " use an incorrect text end (db_txt_end) for the data block
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
325 let b = copy(save_b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
326 let b[8204:8207] = little_endian ? 0z80000000 : 0z00000080
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
327 call writefile(b, sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
328 call assert_fails('recover Xfile1', 'E312:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
329 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
330 call assert_equal(['??? from here until ???END lines may be messed up', '',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
331 \ '???END'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
332 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
333
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
334 " remove the data block
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
335 let b = copy(save_b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
336 call writefile(b[:8191], sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
337 call assert_fails('recover Xfile1', 'E312:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
338 call assert_equal('Xfile1', @%)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
339 call assert_equal(['???MANY LINES MISSING'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
340
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
341 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
342 call delete(sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
343 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
344
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
345 " Test for :recover using an encrypted swap file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
346 func Test_recover_encrypted_swap_file()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
347 CheckFeature cryptv
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
348 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
349
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
350 " Recover an encrypted file from the swap file without the original file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
351 new Xfile1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
352 call feedkeys(":X\<CR>vim\<CR>vim\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
353 call setline(1, ['aaa', 'bbb', 'ccc'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
354 preserve
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
355 let b = readblob('.Xfile1.swp')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
356 call writefile(b, '.Xfile1.swm')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
357 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
358 call feedkeys(":recover Xfile1\<CR>vim\<CR>\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
359 call assert_equal(['aaa', 'bbb', 'ccc'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
360 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
361 call delete('.Xfile1.swm')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
362
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
363 " Recover an encrypted file from the swap file with the original file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
364 new Xfile1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
365 call feedkeys(":X\<CR>vim\<CR>vim\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
366 call setline(1, ['aaa', 'bbb', 'ccc'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
367 update
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
368 call setline(1, ['111', '222', '333'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
369 preserve
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
370 let b = readblob('.Xfile1.swp')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
371 call writefile(b, '.Xfile1.swm')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
372 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
373 call feedkeys(":recover Xfile1\<CR>vim\<CR>\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
374 call assert_equal(['111', '222', '333'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
375 call assert_true(&modified)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
376 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
377 call delete('.Xfile1.swm')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
378 call delete('Xfile1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
379 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
380
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
381 " Test for :recover using a unreadable swap file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
382 func Test_recover_unreadable_swap_file()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
383 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
384 CheckNotRoot
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
385 new Xfile1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
386 let b = readblob('.Xfile1.swp')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
387 call writefile(b, '.Xfile1.swm', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
388 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
389 call setfperm('.Xfile1.swm', '-w-------')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
390 call assert_fails('recover Xfile1', 'E306:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
391 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
392
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
393 " Test for using :recover when the original file and the swap file have the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
394 " same contents.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
395 func Test_recover_unmodified_file()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
396 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
397 call writefile(['aaa', 'bbb', 'ccc'], 'Xfile1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
398 edit Xfile1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
399 preserve
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
400 let b = readblob('.Xfile1.swp')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
401 %bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
402 call writefile(b, '.Xfile1.swz', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
403 let msg = execute('recover Xfile1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
404 call assert_equal(['aaa', 'bbb', 'ccc'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
405 call assert_false(&modified)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
406 call assert_match('Buffer contents equals file contents', msg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
407 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
408 call delete('Xfile1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
409 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
410
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
411 " Test for recovering a file when editing a symbolically linked file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
412 func Test_recover_symbolic_link()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
413 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
414 call writefile(['aaa', 'bbb', 'ccc'], 'Xfile1', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
415 silent !ln -s Xfile1 Xfile2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
416 edit Xfile2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
417 call assert_equal('.Xfile1.swp', fnamemodify(swapname(''), ':t'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
418 preserve
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
419 let b = readblob('.Xfile1.swp')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
420 %bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
421 call writefile([], 'Xfile1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
422 call writefile(b, '.Xfile1.swp')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
423 silent! recover Xfile2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
424 call assert_equal(['aaa', 'bbb', 'ccc'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
425 call assert_true(&modified)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
426 update
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
427 %bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
428 call assert_equal(['aaa', 'bbb', 'ccc'], readfile('Xfile1'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
429 call delete('Xfile2')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
430 call delete('.Xfile1.swp')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
431 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
432
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
433 " Test for recovering a file when an autocmd moves the cursor to an invalid
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
434 " line. This used to result in an internal error (E315) which is fixed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
435 " by 8.2.2966.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
436 func Test_recover_invalid_cursor_pos()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
437 call writefile([], 'Xfile1', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
438 edit Xfile1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
439 preserve
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
440 let b = readblob('.Xfile1.swp')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
441 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
442 augroup Test
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
443 au!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
444 au BufReadPost Xfile1 normal! 3G
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
445 augroup END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
446 call writefile(range(1, 3), 'Xfile1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
447 call writefile(b, '.Xfile1.swp', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
448 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
449 recover Xfile1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
450 catch /E308:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
451 " this test is for the :E315 internal error.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
452 " ignore the 'E308: Original file may have been changed' error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
453 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
454 redraw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
455 augroup Test
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
456 au!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
457 augroup END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
458 augroup! Test
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
459 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
460
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
461 " Test for recovering a buffer without a name
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
462 func Test_noname_buffer()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
463 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
464 call setline(1, ['one', 'two'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
465 preserve
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
466 let sn = swapname('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
467 let b = readblob(sn)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
468 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
469 call writefile(b, sn, 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
470 exe "recover " .. sn
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
471 call assert_equal(['one', 'two'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
472 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
473
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32325
diff changeset
474 " vim: shiftwidth=2 sts=2 expandtab