annotate src/testdir/test_recover.vim @ 31645:fc259e8db5bf v9.0.1155

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