annotate src/testdir/test_swap.vim @ 19487:0aba9ef12488 v8.2.0301

patch 8.2.0301: insufficient testing for exception handling Commit: https://github.com/vim/vim/commit/b654103ad1e379348616f354272db86804ab4bdb Author: Bram Moolenaar <Bram@vim.org> Date: Sat Feb 22 21:21:27 2020 +0100 patch 8.2.0301: insufficient testing for exception handling Problem: Insufficient testing for exception handling and the "attention" prompt. Solution: Add test cases. (Yegappan Lakshmanan, closes #5681)
author Bram Moolenaar <Bram@vim.org>
date Sat, 22 Feb 2020 21:30:04 +0100
parents 8f8a5a15d00a
children 42e4083429a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
18277
f6dcf7eabd26 patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
3 source shared.vim
19487
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
4 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
5
14778
20653d6f3d95 patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents: 14605
diff changeset
6 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
7 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
8 endfunc
20653d6f3d95 patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents: 14605
diff changeset
9
12777
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
10 " Tests for 'directory' option.
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
11 func Test_swap_directory()
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
12 if !has("unix")
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
13 return
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
14 endif
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']
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
19 call writefile(content, 'Xtest1')
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
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
33 call mkdir("Xtest2")
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
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
43 call mkdir("Xtest.je")
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 call delete("Xtest1")
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
53 call delete("Xtest2", "rf")
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
54 call delete("Xtest.je", "rf")
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
55 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
56
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 func Test_swap_group()
12750
0b6c09957b43 patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 if !has("unix")
0b6c09957b43 patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 return
0b6c09957b43 patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 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
61 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
62 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
63 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
64 endif
12750
0b6c09957b43 patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65
12779
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
66 try
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
67 call delete('Xtest')
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
68 split Xtest
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
69 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
70 wq
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
71 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
72 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
73 else
12779
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
74 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
75 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
76 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
77 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
78 else
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
79 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
80 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
81 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
82 " 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
83 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
84
12779
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
85 bwipe!
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
86 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
87 endif
12779
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
88 finally
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
89 call delete('Xtest')
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
90 endtry
12750
0b6c09957b43 patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 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
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 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
94 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
95 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
96
4d5a1ada407e patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents: 12779
diff changeset
97 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
98 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
99 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
100 " 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
101 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
102 only
4d5a1ada407e patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents: 12779
diff changeset
103
15645
f315ab10d579 patch 8.1.0830: test leaves directory behind on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 14778
diff changeset
104 " 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
105 " 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
106 %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
107 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
108 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
109 endfunc
14599
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
110
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
111 func Test_swapinfo()
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
112 new Xswapinfo
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
113 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
114 w
14778
20653d6f3d95 patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents: 14605
diff changeset
115 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
116 call assert_match('Xswapinfo', fname)
18017
988e5a868b60 patch 8.1.2004: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 16738
diff changeset
117 let info = fname->swapinfo()
14605
0c47880f3d95 patch 8.1.0316: swapinfo() test fails on Travis
Christian Brabandt <cb@256bit.org>
parents: 14601
diff changeset
118
0c47880f3d95 patch 8.1.0316: swapinfo() test fails on Travis
Christian Brabandt <cb@256bit.org>
parents: 14601
diff changeset
119 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
120 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
121
14599
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
122 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
123 " 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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 endif
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
132 bwipe!
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
133 call delete(fname)
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
134 call delete('Xswapinfo')
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
135
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
136 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
137 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
138
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
139 call writefile(['burp'], 'Xnotaswapfile')
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
140 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
141 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
142 call delete('Xnotaswapfile')
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
143
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
144 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
145 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
146 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
147 call delete('Xnotaswapfile')
72d6f6f7ead7 patch 8.1.0313: information about a swap file is unavailable
Christian Brabandt <cb@256bit.org>
parents: 13896
diff changeset
148 endfunc
14778
20653d6f3d95 patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents: 14605
diff changeset
149
20653d6f3d95 patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents: 14605
diff changeset
150 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
151 edit Xtest1
20653d6f3d95 patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents: 14605
diff changeset
152 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
153 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
154
20653d6f3d95 patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents: 14605
diff changeset
155 new Xtest2
20653d6f3d95 patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents: 14605
diff changeset
156 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
157 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
158 wincmd p
18017
988e5a868b60 patch 8.1.2004: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 16738
diff changeset
159 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
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 Xtest3
20653d6f3d95 patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents: 14605
diff changeset
162 setlocal noswapfile
20653d6f3d95 patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents: 14605
diff changeset
163 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
164
20653d6f3d95 patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents: 14605
diff changeset
165 bwipe!
20653d6f3d95 patch 8.1.0401: can't get swap name of another buffer
Christian Brabandt <cb@256bit.org>
parents: 14605
diff changeset
166 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
167 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
168 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
169 endfunc
16453
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
170
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
171 func Test_swapfile_delete()
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
172 autocmd! SwapExists
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
173 function s:swap_exists()
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
174 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
175 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
176 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
177 endfunc
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
178 augroup test_swapfile_delete
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
179 autocmd!
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
180 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
181 augroup END
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
182
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
183
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
184 " 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
185 split XswapfileText
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
186 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
187 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
188 " 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
189 let swapfile_name = swapname('%')
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
190 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
191
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
192 " 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
193 " 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
194 quit
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
195 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
196 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
197 let s:swapname = ''
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
198 split XswapfileText
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
199 quit
16459
4ea761ce795b patch 8.1.1234: swap file test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 16453
diff changeset
200 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
201
18277
f6dcf7eabd26 patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
202 " 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
203 if !IsRoot()
f6dcf7eabd26 patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
204 " Write the swapfile with a modified PID, now it will be automatically
f6dcf7eabd26 patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
205 " deleted. Process one should never be Vim.
f6dcf7eabd26 patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
206 let swapfile_bytes[24:27] = 0z01000000
f6dcf7eabd26 patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
207 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
208 let s:swapname = ''
f6dcf7eabd26 patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
209 split XswapfileText
f6dcf7eabd26 patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
210 quit
f6dcf7eabd26 patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
211 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
212 endif
16453
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
213
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
214 " 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
215 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
216 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
217 let s:swapname = ''
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
218 split XswapfileText
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
219 quit
16459
4ea761ce795b patch 8.1.1234: swap file test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 16453
diff changeset
220 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
221
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
222 call delete('XswapfileText')
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
223 call delete(swapfile_name)
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
224 augroup test_swapfile_delete
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
225 autocmd!
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
226 augroup END
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
227 augroup! test_swapfile_delete
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 15645
diff changeset
228 endfunc
16738
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
229
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
230 func Test_swap_recover()
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
231 autocmd! SwapExists
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
232 augroup test_swap_recover
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
233 autocmd!
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
234 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
235 augroup END
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
236
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
237
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
238 call mkdir('Xswap')
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
239 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
240 set dir=Xswap//
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
241 " 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
242 split Xswap/text
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
243 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
244 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
245 " 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
246 let swapfile_name = swapname('%')
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
247 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
248
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
249 " 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
250 quit
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
251 call writefile(swapfile_bytes, swapfile_name)
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
252 " 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
253 try
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
254 split Xswap/text
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
255 catch
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
256 " 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
257 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
258 endtry
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
259 " 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
260 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
261 quit!
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
262
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
263 call delete('Xswap/text')
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
264 call delete(swapfile_name)
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
265 call delete('Xswap', 'd')
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
266 unlet $Xswap
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
267 set dir&
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
268 augroup test_swap_recover
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
269 autocmd!
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
270 augroup END
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
271 augroup! test_swap_recover
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
272 endfunc
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
273
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
274 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
275 autocmd! SwapExists
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
276 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
277 autocmd!
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
278 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
279 augroup END
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
280
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
281 " 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
282 split Xtest.scr
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
283 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
284 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
285 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
286 " 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
287 let swapfile_name = swapname('%')
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
288 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
289
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
290 " 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
291 quit
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
292 call delete('Xtest.scr')
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
293 call writefile(swapfile_bytes, swapfile_name)
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
294 " 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
295 try
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
296 split Xtest.scr
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
297 catch
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
298 " 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
299 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
300 endtry
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
301 " 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
302 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
303 quit!
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
304
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
305 call delete('Xtest.scr')
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16459
diff changeset
306 call delete(swapfile_name)
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')
8f8a5a15d00a patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18277
diff changeset
334 call writefile(swapfile_bytes, swapfile_name)
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 call delete(swapfile_name)
8f8a5a15d00a patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18277
diff changeset
346
8f8a5a15d00a patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18277
diff changeset
347 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
348 autocmd!
8f8a5a15d00a patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18277
diff changeset
349 augroup END
8f8a5a15d00a patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18277
diff changeset
350 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
351 endfunc
8f8a5a15d00a patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18277
diff changeset
352
19487
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
353 " 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
354 func Test_swap_prompt_splitwin()
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
355 if !CanRunVimInTerminal()
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
356 throw 'Skipped: cannot run vim in terminal'
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
357 endif
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
358 call writefile(['foo bar'], 'Xfile1')
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
359 edit Xfile1
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")
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
363 call term_sendkeys(buf, ":split Xfile1\n")
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
364 call term_wait(buf)
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
365 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
366 call term_sendkeys(buf, "q")
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
367 call term_wait(buf)
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
368 call term_sendkeys(buf, ":")
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
369 call WaitForAssert({-> assert_match('^:$', term_getline(buf, 20))})
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
370 call term_sendkeys(buf, "echomsg winnr('$')\<CR>")
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
371 call term_wait(buf)
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
372 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
373 call StopVimInTerminal(buf)
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
374 %bwipe!
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
375 call delete('Xfile1')
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
376 endfunc
0aba9ef12488 patch 8.2.0301: insufficient testing for exception handling
Bram Moolenaar <Bram@vim.org>
parents: 19435
diff changeset
377
19435
8f8a5a15d00a patch 8.2.0275: some Ex code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18277
diff changeset
378 " vim: shiftwidth=2 sts=2 expandtab