Mercurial > vim
annotate src/testdir/test_swap.vim @ 34084:90063f44c99a v9.1.0011
patch 9.1.0011: regexp cannot match combining chars in collection
Commit: https://github.com/vim/vim/commit/d2cc51f9a1a5a30ef5d2e732f49d7f495cae24cf
Author: Christian Brabandt <cb@256bit.org>
Date: Thu Jan 4 22:54:08 2024 +0100
patch 9.1.0011: regexp cannot match combining chars in collection
Problem: regexp cannot match combining chars in collection
Solution: Check for combining characters in regex collections for the
NFA and BT Regex Engine
Also, while at it, make debug mode work again.
fixes #10286
closes: #12871
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 04 Jan 2024 23:00:04 +0100 |
parents | 22d11340ee68 |
children | 1ee567e88a22 |
rev | line source |
---|---|
12750
0b6c09957b43
patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 " Tests for the swap feature |
0b6c09957b43
patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 |
19776
42e4083429a7
patch 8.2.0444: swap file test fails on some systems
Bram Moolenaar <Bram@vim.org>
parents:
19487
diff
changeset
|
3 source check.vim |
18277
f6dcf7eabd26
patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
18017
diff
changeset
|
4 source shared.vim |
19487
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
5 source term_util.vim |
18277
f6dcf7eabd26
patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
18017
diff
changeset
|
6 |
14778
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
7 func s:swapname() |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
8 return trim(execute('swapname')) |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
9 endfunc |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
10 |
12777
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
11 " Tests for 'directory' option. |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
12 func Test_swap_directory() |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21337
diff
changeset
|
13 CheckUnix |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21337
diff
changeset
|
14 |
12777
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
15 let content = ['start of testfile', |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
16 \ 'line 2 Abcdefghij', |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
17 \ 'line 3 Abcdefghij', |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
18 \ 'end of testfile'] |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
19 call writefile(content, 'Xtest1', 'D') |
12777
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
20 |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
21 " '.', swap file in the same directory as file |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
22 set dir=.,~ |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
23 |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
24 " Verify that the swap file doesn't exist in the current directory |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
25 call assert_equal([], glob(".Xtest1*.swp", 1, 1, 1)) |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
26 edit Xtest1 |
14778
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
27 let swfname = s:swapname() |
12777
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
28 call assert_equal([swfname], glob(swfname, 1, 1, 1)) |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
29 |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
30 " './dir', swap file in a directory relative to the file |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
31 set dir=./Xtest2,.,~ |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
32 |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
33 call mkdir("Xtest2", 'R') |
12777
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
34 edit Xtest1 |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
35 call assert_equal([], glob(swfname, 1, 1, 1)) |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
36 let swfname = "Xtest2/Xtest1.swp" |
14778
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
37 call assert_equal(swfname, s:swapname()) |
12777
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
38 call assert_equal([swfname], glob("Xtest2/*", 1, 1, 1)) |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
39 |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
40 " 'dir', swap file in directory relative to the current dir |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
41 set dir=Xtest.je,~ |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
42 |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
43 call mkdir("Xtest.je", 'R') |
12777
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
44 call writefile(content, 'Xtest2/Xtest3') |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
45 edit Xtest2/Xtest3 |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
46 call assert_equal(["Xtest2/Xtest3"], glob("Xtest2/*", 1, 1, 1)) |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
47 let swfname = "Xtest.je/Xtest3.swp" |
14778
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
48 call assert_equal(swfname, s:swapname()) |
12777
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
49 call assert_equal([swfname], glob("Xtest.je/*", 1, 1, 1)) |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
50 |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
51 set dir& |
3272e1cde1eb
patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents:
12775
diff
changeset
|
52 endfunc |
12771
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
53 |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
54 func Test_swap_group() |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21337
diff
changeset
|
55 CheckUnix |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21337
diff
changeset
|
56 |
12771
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
57 let groups = split(system('groups')) |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
58 if len(groups) <= 1 |
12775
bda267b9fc68
patch 8.0.1265: swap test not skipped when there is one group
Christian Brabandt <cb@256bit.org>
parents:
12771
diff
changeset
|
59 throw 'Skipped: need at least two groups, got ' . string(groups) |
12771
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
60 endif |
12750
0b6c09957b43
patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
61 |
12779
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
62 try |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
63 call delete('Xtest') |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
64 split Xtest |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
65 call setline(1, 'just some text') |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
66 wq |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
67 if system('ls -l Xtest') !~ ' ' . groups[0] . ' \d' |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
68 throw 'Skipped: test file does not have the first group' |
12771
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
69 else |
12779
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
70 silent !chmod 640 Xtest |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
71 call system('chgrp ' . groups[1] . ' Xtest') |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
72 if system('ls -l Xtest') !~ ' ' . groups[1] . ' \d' |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
73 throw 'Skipped: cannot set second group on test file' |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
74 else |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
75 split Xtest |
14778
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
76 let swapname = s:swapname() |
12779
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
77 call assert_match('Xtest', swapname) |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
78 " Group of swapfile must now match original file. |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
79 call assert_match(' ' . groups[1] . ' \d', system('ls -l ' . swapname)) |
12750
0b6c09957b43
patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
80 |
12779
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
81 bwipe! |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
82 endif |
12771
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
83 endif |
12779
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
84 finally |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
85 call delete('Xtest') |
73eb8a2d7f04
patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents:
12777
diff
changeset
|
86 endtry |
12750
0b6c09957b43
patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
87 endfunc |
13896
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
88 |
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
89 func Test_missing_dir() |
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
90 call mkdir('Xswapdir') |
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
91 exe 'set directory=' . getcwd() . '/Xswapdir' |
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
92 |
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
93 call assert_equal('', glob('foo')) |
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
94 call assert_equal('', glob('bar')) |
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
95 edit foo/x.txt |
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
96 " This should not give a warning for an existing swap file. |
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
97 split bar/x.txt |
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
98 only |
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
99 |
15645
f315ab10d579
patch 8.1.0830: test leaves directory behind on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
14778
diff
changeset
|
100 " Delete the buffer so that swap file is removed before we try to delete the |
f315ab10d579
patch 8.1.0830: test leaves directory behind on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
14778
diff
changeset
|
101 " directory. That fails on MS-Windows. |
f315ab10d579
patch 8.1.0830: test leaves directory behind on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
14778
diff
changeset
|
102 %bdelete! |
13896
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
103 set directory& |
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
104 call delete('Xswapdir', 'rf') |
4d5a1ada407e
patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents:
12779
diff
changeset
|
105 endfunc |
14599
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
106 |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
107 func Test_swapinfo() |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
108 new Xswapinfo |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
109 call setline(1, ['one', 'two', 'three']) |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
110 w |
14778
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
111 let fname = s:swapname() |
14599
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
112 call assert_match('Xswapinfo', fname) |
31347
56a2af8c0980
patch 9.0.1007: there is no way to get a list of swap file names
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
113 |
31349
22d11340ee68
patch 9.0.1008: test for swapfilelist() fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
31347
diff
changeset
|
114 " Check the tail appears in the list from swapfilelist(). The path depends |
22d11340ee68
patch 9.0.1008: test for swapfilelist() fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
31347
diff
changeset
|
115 " on the system. |
22d11340ee68
patch 9.0.1008: test for swapfilelist() fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
31347
diff
changeset
|
116 let tail = fnamemodify(fname, ":t")->fnameescape() |
31347
56a2af8c0980
patch 9.0.1007: there is no way to get a list of swap file names
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
117 let nr = 0 |
56a2af8c0980
patch 9.0.1007: there is no way to get a list of swap file names
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
118 for name in swapfilelist() |
31349
22d11340ee68
patch 9.0.1008: test for swapfilelist() fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
31347
diff
changeset
|
119 if name =~ tail .. '$' |
31347
56a2af8c0980
patch 9.0.1007: there is no way to get a list of swap file names
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
120 let nr += 1 |
56a2af8c0980
patch 9.0.1007: there is no way to get a list of swap file names
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
121 endif |
56a2af8c0980
patch 9.0.1007: there is no way to get a list of swap file names
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
122 endfor |
31349
22d11340ee68
patch 9.0.1008: test for swapfilelist() fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
31347
diff
changeset
|
123 call assert_equal(1, nr, 'not found in ' .. string(swapfilelist())) |
31347
56a2af8c0980
patch 9.0.1007: there is no way to get a list of swap file names
Bram Moolenaar <Bram@vim.org>
parents:
30769
diff
changeset
|
124 |
18017
988e5a868b60
patch 8.1.2004: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
125 let info = fname->swapinfo() |
14605
0c47880f3d95
patch 8.1.0316: swapinfo() test fails on Travis
Christian Brabandt <cb@256bit.org>
parents:
14601
diff
changeset
|
126 let ver = printf('VIM %d.%d', v:version / 100, v:version % 100) |
0c47880f3d95
patch 8.1.0316: swapinfo() test fails on Travis
Christian Brabandt <cb@256bit.org>
parents:
14601
diff
changeset
|
127 call assert_equal(ver, info.version) |
0c47880f3d95
patch 8.1.0316: swapinfo() test fails on Travis
Christian Brabandt <cb@256bit.org>
parents:
14601
diff
changeset
|
128 |
14599
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
129 call assert_match('\w', info.user) |
14605
0c47880f3d95
patch 8.1.0316: swapinfo() test fails on Travis
Christian Brabandt <cb@256bit.org>
parents:
14601
diff
changeset
|
130 " host name is truncated to 39 bytes in the swap file |
0c47880f3d95
patch 8.1.0316: swapinfo() test fails on Travis
Christian Brabandt <cb@256bit.org>
parents:
14601
diff
changeset
|
131 call assert_equal(hostname()[:38], info.host) |
14599
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
132 call assert_match('Xswapinfo', info.fname) |
14601
d0ff19a55579
patch 8.1.0314: build failure without the +eval feature
Christian Brabandt <cb@256bit.org>
parents:
14599
diff
changeset
|
133 call assert_match(0, info.dirty) |
14599
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
134 call assert_equal(getpid(), info.pid) |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
135 call assert_match('^\d*$', info.mtime) |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
136 if has_key(info, 'inode') |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
137 call assert_match('\d', info.inode) |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
138 endif |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
139 bwipe! |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
140 call delete(fname) |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
141 call delete('Xswapinfo') |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
142 |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
143 let info = swapinfo('doesnotexist') |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
144 call assert_equal('Cannot open file', info.error) |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
145 |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
146 call writefile(['burp'], 'Xnotaswapfile', 'D') |
14599
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
147 let info = swapinfo('Xnotaswapfile') |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
148 call assert_equal('Cannot read file', info.error) |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
149 call delete('Xnotaswapfile') |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
150 |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
151 call writefile([repeat('x', 10000)], 'Xnotaswapfile') |
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
152 let info = swapinfo('Xnotaswapfile') |
14601
d0ff19a55579
patch 8.1.0314: build failure without the +eval feature
Christian Brabandt <cb@256bit.org>
parents:
14599
diff
changeset
|
153 call assert_equal('Not a swap file', info.error) |
14599
72d6f6f7ead7
patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents:
13896
diff
changeset
|
154 endfunc |
14778
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
155 |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
156 func Test_swapname() |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
157 edit Xtest1 |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
158 let expected = s:swapname() |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
159 call assert_equal(expected, swapname('%')) |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
160 |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
161 new Xtest2 |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
162 let buf = bufnr('%') |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
163 let expected = s:swapname() |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
164 wincmd p |
18017
988e5a868b60
patch 8.1.2004: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
165 call assert_equal(expected, buf->swapname()) |
14778
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
166 |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
167 new Xtest3 |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
168 setlocal noswapfile |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
169 call assert_equal('', swapname('%')) |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
170 |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
171 bwipe! |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
172 call delete('Xtest1') |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
173 call delete('Xtest2') |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
174 call delete('Xtest3') |
20653d6f3d95
patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents:
14605
diff
changeset
|
175 endfunc |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
176 |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
177 func Test_swapfile_delete() |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
178 autocmd! SwapExists |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
179 function s:swap_exists() |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
180 let v:swapchoice = s:swap_choice |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
181 let s:swapname = v:swapname |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
182 let s:filename = expand('<afile>') |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
183 endfunc |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
184 augroup test_swapfile_delete |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
185 autocmd! |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
186 autocmd SwapExists * call s:swap_exists() |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
187 augroup END |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
188 |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
189 |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
190 " Create a valid swapfile by editing a file. |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
191 split XswapfileText |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
192 call setline(1, ['one', 'two', 'three']) |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
193 write " file is written, not modified |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
194 " read the swapfile as a Blob |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
195 let swapfile_name = swapname('%') |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
196 let swapfile_bytes = readfile(swapfile_name, 'B') |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
197 |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
198 " Close the file and recreate the swap file. |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
199 " Now editing the file will run into the process still existing |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
200 quit |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
201 call writefile(swapfile_bytes, swapfile_name, 'D') |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
202 let s:swap_choice = 'e' |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
203 let s:swapname = '' |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
204 split XswapfileText |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
205 quit |
16459
4ea761ce795b
patch 8.1.1234: swap file test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
206 call assert_equal(fnamemodify(swapfile_name, ':t'), fnamemodify(s:swapname, ':t')) |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
207 |
18277
f6dcf7eabd26
patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
18017
diff
changeset
|
208 " This test won't work as root because root can successfully run kill(1, 0) |
f6dcf7eabd26
patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
18017
diff
changeset
|
209 if !IsRoot() |
f6dcf7eabd26
patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
18017
diff
changeset
|
210 " Write the swapfile with a modified PID, now it will be automatically |
25010
a4647ee8e163
patch 8.2.3042: swap file test fails
Bram Moolenaar <Bram@vim.org>
parents:
24828
diff
changeset
|
211 " deleted. Process 0x3fffffff most likely does not exist. |
a4647ee8e163
patch 8.2.3042: swap file test fails
Bram Moolenaar <Bram@vim.org>
parents:
24828
diff
changeset
|
212 let swapfile_bytes[24:27] = 0zffffff3f |
18277
f6dcf7eabd26
patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
18017
diff
changeset
|
213 call writefile(swapfile_bytes, swapfile_name) |
f6dcf7eabd26
patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
18017
diff
changeset
|
214 let s:swapname = '' |
f6dcf7eabd26
patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
18017
diff
changeset
|
215 split XswapfileText |
f6dcf7eabd26
patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
18017
diff
changeset
|
216 quit |
f6dcf7eabd26
patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
18017
diff
changeset
|
217 call assert_equal('', s:swapname) |
f6dcf7eabd26
patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
18017
diff
changeset
|
218 endif |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
219 |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
220 " Now set the modified flag, the swap file will not be deleted |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
221 let swapfile_bytes[28 + 80 + 899] = 0x55 |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
222 call writefile(swapfile_bytes, swapfile_name) |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
223 let s:swapname = '' |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
224 split XswapfileText |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
225 quit |
16459
4ea761ce795b
patch 8.1.1234: swap file test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
226 call assert_equal(fnamemodify(swapfile_name, ':t'), fnamemodify(s:swapname, ':t')) |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
227 |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
228 call delete('XswapfileText') |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
229 augroup test_swapfile_delete |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
230 autocmd! |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
231 augroup END |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
232 augroup! test_swapfile_delete |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15645
diff
changeset
|
233 endfunc |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
234 |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
235 func Test_swap_recover() |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
236 autocmd! SwapExists |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
237 augroup test_swap_recover |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
238 autocmd! |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
239 autocmd SwapExists * let v:swapchoice = 'r' |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
240 augroup END |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
241 |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
242 call mkdir('Xswap', 'R') |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
243 let $Xswap = 'foo' " Check for issue #4369. |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
244 set dir=Xswap// |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
245 " Create a valid swapfile by editing a file. |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
246 split Xswap/text |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
247 call setline(1, ['one', 'two', 'three']) |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
248 write " file is written, not modified |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
249 " read the swapfile as a Blob |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
250 let swapfile_name = swapname('%') |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
251 let swapfile_bytes = readfile(swapfile_name, 'B') |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
252 |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
253 " Close the file and recreate the swap file. |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
254 quit |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
255 call writefile(swapfile_bytes, swapfile_name, 'D') |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
256 " Edit the file again. This triggers recovery. |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
257 try |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
258 split Xswap/text |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
259 catch |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
260 " E308 should be caught, not E305. |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
261 call assert_exception('E308:') " Original file may have been changed |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
262 endtry |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
263 " The file should be recovered. |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
264 call assert_equal(['one', 'two', 'three'], getline(1, 3)) |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
265 quit! |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
266 |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
267 unlet $Xswap |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
268 set dir& |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
269 augroup test_swap_recover |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
270 autocmd! |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
271 augroup END |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
272 augroup! test_swap_recover |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
273 endfunc |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
274 |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
275 func Test_swap_recover_ext() |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
276 autocmd! SwapExists |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
277 augroup test_swap_recover_ext |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
278 autocmd! |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
279 autocmd SwapExists * let v:swapchoice = 'r' |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
280 augroup END |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
281 |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
282 " Create a valid swapfile by editing a file with a special extension. |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
283 split Xtest.scr |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
284 call setline(1, ['one', 'two', 'three']) |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
285 write " file is written, not modified |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
286 write " write again to make sure the swapfile is created |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
287 " read the swapfile as a Blob |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
288 let swapfile_name = swapname('%') |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
289 let swapfile_bytes = readfile(swapfile_name, 'B') |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
290 |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
291 " Close and delete the file and recreate the swap file. |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
292 quit |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
293 call delete('Xtest.scr') |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
294 call writefile(swapfile_bytes, swapfile_name, 'D') |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
295 " Edit the file again. This triggers recovery. |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
296 try |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
297 split Xtest.scr |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
298 catch |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
299 " E308 should be caught, not E306. |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
300 call assert_exception('E308:') " Original file may have been changed |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
301 endtry |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
302 " The file should be recovered. |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
303 call assert_equal(['one', 'two', 'three'], getline(1, 3)) |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
304 quit! |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
305 |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
306 call delete('Xtest.scr') |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
307 augroup test_swap_recover_ext |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
308 autocmd! |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
309 augroup END |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
310 augroup! test_swap_recover_ext |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16459
diff
changeset
|
311 endfunc |
19435
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
312 |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
313 " Test for closing a split window automatically when a swap file is detected |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
314 " and 'Q' is selected in the confirmation prompt. |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
315 func Test_swap_split_win() |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
316 autocmd! SwapExists |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
317 augroup test_swap_splitwin |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
318 autocmd! |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
319 autocmd SwapExists * let v:swapchoice = 'q' |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
320 augroup END |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
321 |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
322 " Create a valid swapfile by editing a file with a special extension. |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
323 split Xtest.scr |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
324 call setline(1, ['one', 'two', 'three']) |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
325 write " file is written, not modified |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
326 write " write again to make sure the swapfile is created |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
327 " read the swapfile as a Blob |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
328 let swapfile_name = swapname('%') |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
329 let swapfile_bytes = readfile(swapfile_name, 'B') |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
330 |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
331 " Close and delete the file and recreate the swap file. |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
332 quit |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
333 call delete('Xtest.scr') |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
334 call writefile(swapfile_bytes, swapfile_name, 'D') |
19435
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
335 " Split edit the file again. This should fail to open the window |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
336 try |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
337 split Xtest.scr |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
338 catch |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
339 " E308 should be caught, not E306. |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
340 call assert_exception('E308:') " Original file may have been changed |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
341 endtry |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
342 call assert_equal(1, winnr('$')) |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
343 |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
344 call delete('Xtest.scr') |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
345 |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
346 augroup test_swap_splitwin |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
347 autocmd! |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
348 augroup END |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
349 augroup! test_swap_splitwin |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
350 endfunc |
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
351 |
19487
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
352 " Test for selecting 'q' in the attention prompt |
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
353 func Test_swap_prompt_splitwin() |
19776
42e4083429a7
patch 8.2.0444: swap file test fails on some systems
Bram Moolenaar <Bram@vim.org>
parents:
19487
diff
changeset
|
354 CheckRunVimInTerminal |
42e4083429a7
patch 8.2.0444: swap file test fails on some systems
Bram Moolenaar <Bram@vim.org>
parents:
19487
diff
changeset
|
355 |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
356 call writefile(['foo bar'], 'Xfile1', 'D') |
19487
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
357 edit Xfile1 |
19776
42e4083429a7
patch 8.2.0444: swap file test fails on some systems
Bram Moolenaar <Bram@vim.org>
parents:
19487
diff
changeset
|
358 preserve " should help to make sure the swap file exists |
42e4083429a7
patch 8.2.0444: swap file test fails on some systems
Bram Moolenaar <Bram@vim.org>
parents:
19487
diff
changeset
|
359 |
19487
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
360 let buf = RunVimInTerminal('', {'rows': 20}) |
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
361 call term_sendkeys(buf, ":set nomore\n") |
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
362 call term_sendkeys(buf, ":set noruler\n") |
25120
2d3660601fdb
patch 8.2.3097: crash when using "quit" at recovery prompt
Bram Moolenaar <Bram@vim.org>
parents:
25010
diff
changeset
|
363 |
19487
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
364 call term_sendkeys(buf, ":split Xfile1\n") |
19954
c087099e9163
patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents:
19776
diff
changeset
|
365 call TermWait(buf) |
19487
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
366 call WaitForAssert({-> assert_match('^\[O\]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: $', term_getline(buf, 20))}) |
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
367 call term_sendkeys(buf, "q") |
19954
c087099e9163
patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents:
19776
diff
changeset
|
368 call TermWait(buf) |
19776
42e4083429a7
patch 8.2.0444: swap file test fails on some systems
Bram Moolenaar <Bram@vim.org>
parents:
19487
diff
changeset
|
369 call term_sendkeys(buf, ":\<CR>") |
19487
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
370 call WaitForAssert({-> assert_match('^:$', term_getline(buf, 20))}) |
19776
42e4083429a7
patch 8.2.0444: swap file test fails on some systems
Bram Moolenaar <Bram@vim.org>
parents:
19487
diff
changeset
|
371 call term_sendkeys(buf, ":echomsg winnr('$')\<CR>") |
19954
c087099e9163
patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents:
19776
diff
changeset
|
372 call TermWait(buf) |
19487
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
373 call WaitForAssert({-> assert_match('^1$', term_getline(buf, 20))}) |
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
374 call StopVimInTerminal(buf) |
25120
2d3660601fdb
patch 8.2.3097: crash when using "quit" at recovery prompt
Bram Moolenaar <Bram@vim.org>
parents:
25010
diff
changeset
|
375 |
25131
ba16f025f2e2
patch 8.2.3102: test for crash fix does not fail without the fix
Bram Moolenaar <Bram@vim.org>
parents:
25120
diff
changeset
|
376 " This caused Vim to crash when typing "q" at the swap file prompt. |
ba16f025f2e2
patch 8.2.3102: test for crash fix does not fail without the fix
Bram Moolenaar <Bram@vim.org>
parents:
25120
diff
changeset
|
377 let buf = RunVimInTerminal('-c "au bufadd * let foo_w = wincol()"', {'rows': 18}) |
ba16f025f2e2
patch 8.2.3102: test for crash fix does not fail without the fix
Bram Moolenaar <Bram@vim.org>
parents:
25120
diff
changeset
|
378 call term_sendkeys(buf, ":e Xfile1\<CR>") |
ba16f025f2e2
patch 8.2.3102: test for crash fix does not fail without the fix
Bram Moolenaar <Bram@vim.org>
parents:
25120
diff
changeset
|
379 call WaitForAssert({-> assert_match('More', term_getline(buf, 18))}) |
ba16f025f2e2
patch 8.2.3102: test for crash fix does not fail without the fix
Bram Moolenaar <Bram@vim.org>
parents:
25120
diff
changeset
|
380 call term_sendkeys(buf, " ") |
ba16f025f2e2
patch 8.2.3102: test for crash fix does not fail without the fix
Bram Moolenaar <Bram@vim.org>
parents:
25120
diff
changeset
|
381 call WaitForAssert({-> assert_match('^\[O\]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:', term_getline(buf, 18))}) |
ba16f025f2e2
patch 8.2.3102: test for crash fix does not fail without the fix
Bram Moolenaar <Bram@vim.org>
parents:
25120
diff
changeset
|
382 call term_sendkeys(buf, "q") |
25120
2d3660601fdb
patch 8.2.3097: crash when using "quit" at recovery prompt
Bram Moolenaar <Bram@vim.org>
parents:
25010
diff
changeset
|
383 call TermWait(buf) |
25131
ba16f025f2e2
patch 8.2.3102: test for crash fix does not fail without the fix
Bram Moolenaar <Bram@vim.org>
parents:
25120
diff
changeset
|
384 " check that Vim is still running |
ba16f025f2e2
patch 8.2.3102: test for crash fix does not fail without the fix
Bram Moolenaar <Bram@vim.org>
parents:
25120
diff
changeset
|
385 call term_sendkeys(buf, ":echo 'hello'\<CR>") |
ba16f025f2e2
patch 8.2.3102: test for crash fix does not fail without the fix
Bram Moolenaar <Bram@vim.org>
parents:
25120
diff
changeset
|
386 call WaitForAssert({-> assert_match('^hello', term_getline(buf, 18))}) |
ba16f025f2e2
patch 8.2.3102: test for crash fix does not fail without the fix
Bram Moolenaar <Bram@vim.org>
parents:
25120
diff
changeset
|
387 call term_sendkeys(buf, ":%bwipe!\<CR>") |
ba16f025f2e2
patch 8.2.3102: test for crash fix does not fail without the fix
Bram Moolenaar <Bram@vim.org>
parents:
25120
diff
changeset
|
388 call StopVimInTerminal(buf) |
25120
2d3660601fdb
patch 8.2.3097: crash when using "quit" at recovery prompt
Bram Moolenaar <Bram@vim.org>
parents:
25010
diff
changeset
|
389 |
19487
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
390 %bwipe! |
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
391 endfunc |
0aba9ef12488
patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents:
19435
diff
changeset
|
392 |
21337
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
393 func Test_swap_symlink() |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21337
diff
changeset
|
394 CheckUnix |
21337
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
395 |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
396 call writefile(['text'], 'Xtestfile', 'D') |
21337
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
397 silent !ln -s -f Xtestfile Xtestlink |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
398 |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
399 set dir=. |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
400 |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
401 " Test that swap file uses the name of the file when editing through a |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
402 " symbolic link (so that editing the file twice is detected) |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
403 edit Xtestlink |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
404 call assert_match('Xtestfile\.swp$', s:swapname()) |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
405 bwipe! |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
406 |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
407 call mkdir('Xswapdir', 'R') |
21337
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
408 exe 'set dir=' . getcwd() . '/Xswapdir//' |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
409 |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
410 " Check that this also works when 'directory' ends with '//' |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
411 edit Xtestlink |
26018
c2d4e40a32a6
patch 8.2.3543: swapname has double slash when 'directory' ends in it
Bram Moolenaar <Bram@vim.org>
parents:
25200
diff
changeset
|
412 call assert_match('Xswapdir[/\\]%.*testdir%Xtestfile\.swp$', s:swapname()) |
21337
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
413 bwipe! |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
414 |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
415 set dir& |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
416 call delete('Xtestlink') |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
417 endfunc |
647897e6df9e
patch 8.2.1219: symlink not followed if dirname ends in //
Bram Moolenaar <Bram@vim.org>
parents:
19954
diff
changeset
|
418 |
22995
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
419 func s:get_unused_pid(base) |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
420 if has('job') |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
421 " Execute 'echo' as a temporary job, and return its pid as an unused pid. |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
422 if has('win32') |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
423 let cmd = 'cmd /c echo' |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
424 else |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
425 let cmd = 'echo' |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
426 endif |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
427 let j = job_start(cmd) |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
428 while job_status(j) ==# 'run' |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
429 sleep 10m |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
430 endwhile |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
431 if job_status(j) ==# 'dead' |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
432 return job_info(j).process |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
433 endif |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
434 endif |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
435 " Must add four for MS-Windows to see it as a different one. |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
436 return a:base + 4 |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
437 endfunc |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
438 |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
439 func s:blob_to_pid(b) |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
440 return a:b[3] * 16777216 + a:b[2] * 65536 + a:b[1] * 256 + a:b[0] |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
441 endfunc |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
442 |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
443 func s:pid_to_blob(i) |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
444 let b = 0z |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
445 let b[0] = and(a:i, 0xff) |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
446 let b[1] = and(a:i / 256, 0xff) |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
447 let b[2] = and(a:i / 65536, 0xff) |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
448 let b[3] = and(a:i / 16777216, 0xff) |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
449 return b |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
450 endfunc |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
451 |
22846
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
452 func Test_swap_auto_delete() |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
453 " Create a valid swapfile by editing a file with a special extension. |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
454 split Xtest.scr |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
455 call setline(1, ['one', 'two', 'three']) |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
456 write " file is written, not modified |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
457 write " write again to make sure the swapfile is created |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
458 " read the swapfile as a Blob |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
459 let swapfile_name = swapname('%') |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
460 let swapfile_bytes = readfile(swapfile_name, 'B') |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
461 |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
462 " Forget about the file, recreate the swap file, then edit it again. The |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
463 " swap file should be automatically deleted. |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
464 bwipe! |
22995
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
465 " Change the process ID to avoid the "still running" warning. |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
466 let swapfile_bytes[24:27] = s:pid_to_blob(s:get_unused_pid( |
94656f3ff304
patch 8.2.2044: MS-Windows: swap file test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22944
diff
changeset
|
467 \ s:blob_to_pid(swapfile_bytes[24:27]))) |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
468 call writefile(swapfile_bytes, swapfile_name, 'D') |
22846
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
469 edit Xtest.scr |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
470 " will end up using the same swap file after deleting the existing one |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
471 call assert_equal(swapfile_name, swapname('%')) |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
472 bwipe! |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
473 |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
474 " create the swap file again, but change the host name so that it won't be |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
475 " deleted |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
476 autocmd! SwapExists |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
477 augroup test_swap_recover_ext |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
478 autocmd! |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
479 autocmd SwapExists * let v:swapchoice = 'e' |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
480 augroup END |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
481 |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
482 " change the host name |
22938
760526e5cd29
patch 8.2.2016: swap file test is a little flaky
Bram Moolenaar <Bram@vim.org>
parents:
22846
diff
changeset
|
483 let swapfile_bytes[28 + 40] = swapfile_bytes[28 + 40] + 2 |
22846
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
484 call writefile(swapfile_bytes, swapfile_name) |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
485 edit Xtest.scr |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
486 call assert_equal(1, filereadable(swapfile_name)) |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
487 " will use another same swap file name |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
488 call assert_notequal(swapfile_name, swapname('%')) |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
489 bwipe! |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
490 |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
491 call delete('Xtest.scr') |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
492 augroup test_swap_recover_ext |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
493 autocmd! |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
494 augroup END |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
495 augroup! test_swap_recover_ext |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
496 endfunc |
83c2c489cb1b
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
497 |
24814
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
498 " Test for renaming a buffer when the swap file is deleted out-of-band |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
499 func Test_missing_swap_file() |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
500 CheckUnix |
25133
e0baf334f1ca
patch 8.2.3103: swap test may fail on some systems
Bram Moolenaar <Bram@vim.org>
parents:
25131
diff
changeset
|
501 new Xfile2 |
24828
e0c43439fea6
patch 8.2.2952: recover test fails on big endian systems
Bram Moolenaar <Bram@vim.org>
parents:
24814
diff
changeset
|
502 call delete(swapname('')) |
25133
e0baf334f1ca
patch 8.2.3103: swap test may fail on some systems
Bram Moolenaar <Bram@vim.org>
parents:
25131
diff
changeset
|
503 call assert_fails('file Xfile3', 'E301:') |
e0baf334f1ca
patch 8.2.3103: swap test may fail on some systems
Bram Moolenaar <Bram@vim.org>
parents:
25131
diff
changeset
|
504 call assert_equal('Xfile3', bufname()) |
24814
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
505 call assert_true(bufexists('Xfile2')) |
25133
e0baf334f1ca
patch 8.2.3103: swap test may fail on some systems
Bram Moolenaar <Bram@vim.org>
parents:
25131
diff
changeset
|
506 call assert_true(bufexists('Xfile3')) |
24814
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
507 %bw! |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
508 endfunc |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
509 |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
510 " Test for :preserve command |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
511 func Test_preserve() |
25133
e0baf334f1ca
patch 8.2.3103: swap test may fail on some systems
Bram Moolenaar <Bram@vim.org>
parents:
25131
diff
changeset
|
512 new Xfile4 |
24814
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
513 setlocal noswapfile |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
514 call assert_fails('preserve', 'E313:') |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
515 bw! |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
516 endfunc |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
517 |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
518 " Test for the v:swapchoice variable |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
519 func Test_swapchoice() |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
520 call writefile(['aaa', 'bbb'], 'Xfile5', 'D') |
25133
e0baf334f1ca
patch 8.2.3103: swap test may fail on some systems
Bram Moolenaar <Bram@vim.org>
parents:
25131
diff
changeset
|
521 edit Xfile5 |
24814
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
522 preserve |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
523 let swapfname = swapname('') |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
524 let b = readblob(swapfname) |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
525 bw! |
30769
ae10b91ac6b3
patch 9.0.0719: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
28285
diff
changeset
|
526 call writefile(b, swapfname, 'D') |
24814
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
527 |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
528 autocmd! SwapExists |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
529 |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
530 " Test for v:swapchoice = 'o' (readonly) |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
531 augroup test_swapchoice |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
532 autocmd! |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
533 autocmd SwapExists * let v:swapchoice = 'o' |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
534 augroup END |
25133
e0baf334f1ca
patch 8.2.3103: swap test may fail on some systems
Bram Moolenaar <Bram@vim.org>
parents:
25131
diff
changeset
|
535 edit Xfile5 |
24814
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
536 call assert_true(&readonly) |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
537 call assert_equal(['aaa', 'bbb'], getline(1, '$')) |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
538 %bw! |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
539 call assert_true(filereadable(swapfname)) |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
540 |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
541 " Test for v:swapchoice = 'a' (abort) |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
542 augroup test_swapchoice |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
543 autocmd! |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
544 autocmd SwapExists * let v:swapchoice = 'a' |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
545 augroup END |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
546 try |
25133
e0baf334f1ca
patch 8.2.3103: swap test may fail on some systems
Bram Moolenaar <Bram@vim.org>
parents:
25131
diff
changeset
|
547 edit Xfile5 |
24814
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
548 catch /^Vim:Interrupt$/ |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
549 endtry |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
550 call assert_equal('', @%) |
25133
e0baf334f1ca
patch 8.2.3103: swap test may fail on some systems
Bram Moolenaar <Bram@vim.org>
parents:
25131
diff
changeset
|
551 call assert_true(bufexists('Xfile5')) |
24814
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
552 %bw! |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
553 call assert_true(filereadable(swapfname)) |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
554 |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
555 " Test for v:swapchoice = 'd' (delete) |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
556 augroup test_swapchoice |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
557 autocmd! |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
558 autocmd SwapExists * let v:swapchoice = 'd' |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
559 augroup END |
25133
e0baf334f1ca
patch 8.2.3103: swap test may fail on some systems
Bram Moolenaar <Bram@vim.org>
parents:
25131
diff
changeset
|
560 edit Xfile5 |
e0baf334f1ca
patch 8.2.3103: swap test may fail on some systems
Bram Moolenaar <Bram@vim.org>
parents:
25131
diff
changeset
|
561 call assert_equal('Xfile5', @%) |
24814
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
562 %bw! |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
563 call assert_false(filereadable(swapfname)) |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
564 |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
565 call delete(swapfname) |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
566 augroup test_swapchoice |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
567 autocmd! |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
568 augroup END |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
569 augroup! test_swapchoice |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
570 endfunc |
4c5eec1ef612
patch 8.2.2945: some buffer related code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
22995
diff
changeset
|
571 |
25200
da0e5ff44b14
patch 8.2.3136: no test for E187 and "No swap file"
Bram Moolenaar <Bram@vim.org>
parents:
25133
diff
changeset
|
572 func Test_no_swap_file() |
da0e5ff44b14
patch 8.2.3136: no test for E187 and "No swap file"
Bram Moolenaar <Bram@vim.org>
parents:
25133
diff
changeset
|
573 call assert_equal("\nNo swap file", execute('swapname')) |
da0e5ff44b14
patch 8.2.3136: no test for E187 and "No swap file"
Bram Moolenaar <Bram@vim.org>
parents:
25133
diff
changeset
|
574 endfunc |
da0e5ff44b14
patch 8.2.3136: no test for E187 and "No swap file"
Bram Moolenaar <Bram@vim.org>
parents:
25133
diff
changeset
|
575 |
19435
8f8a5a15d00a
patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
576 " vim: shiftwidth=2 sts=2 expandtab |