annotate src/testdir/test_swap.vim @ 13896:4d5a1ada407e v8.0.1819

patch 8.0.1819: swap file warning for file with non-existing directory commit https://github.com/vim/vim/commit/8c3169c58eef3e04f643fe9e045a97b81429e0cb Author: Bram Moolenaar <Bram@vim.org> Date: Sat May 12 17:04:12 2018 +0200 patch 8.0.1819: swap file warning for file with non-existing directory Problem: Swap file warning for a file in a non-existing directory, if there is another with the same file name. (Juergen Weigert) Solution: When expanding the file name fails compare the file names.
author Christian Brabandt <cb@256bit.org>
date Sat, 12 May 2018 17:15:05 +0200
parents 73eb8a2d7f04
children 72d6f6f7ead7
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
12777
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
3 " Tests for 'directory' option.
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
4 func Test_swap_directory()
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
5 if !has("unix")
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
6 return
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
7 endif
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
8 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
9 \ 'line 2 Abcdefghij',
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
10 \ 'line 3 Abcdefghij',
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
11 \ 'end of testfile']
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
12 call writefile(content, 'Xtest1')
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
13
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
14 " '.', 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
15 set dir=.,~
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
16
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
17 " 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
18 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
19 edit Xtest1
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
20 let swfname = split(execute("swapname"))[0]
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
21 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
22
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
23 " './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
24 set dir=./Xtest2,.,~
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
25
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
26 call mkdir("Xtest2")
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
27 edit Xtest1
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
28 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
29 let swfname = "Xtest2/Xtest1.swp"
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
30 call assert_equal(swfname, split(execute("swapname"))[0])
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
31 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
32
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
33 " '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
34 set dir=Xtest.je,~
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
35
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
36 call mkdir("Xtest.je")
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
37 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
38 edit Xtest2/Xtest3
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
39 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
40 let swfname = "Xtest.je/Xtest3.swp"
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
41 call assert_equal(swfname, split(execute("swapname"))[0])
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
42 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
43
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
44 set dir&
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
45 call delete("Xtest1")
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
46 call delete("Xtest2", "rf")
3272e1cde1eb patch 8.0.1266: Test_swap_directory was commented out
Christian Brabandt <cb@256bit.org>
parents: 12775
diff changeset
47 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
48 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
49
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
50 func Test_swap_group()
12750
0b6c09957b43 patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 if !has("unix")
0b6c09957b43 patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 return
0b6c09957b43 patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 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
54 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
55 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
56 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
57 endif
12750
0b6c09957b43 patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58
12779
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
59 try
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
60 call delete('Xtest')
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
61 split Xtest
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
62 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
63 wq
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
64 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
65 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
66 else
12779
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
67 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
68 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
69 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
70 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
71 else
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
72 split Xtest
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
73 let swapname = substitute(execute('swapname'), '[[:space:]]', '', 'g')
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
74 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
75 " 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
76 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
77
12779
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
78 bwipe!
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
79 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
80 endif
12779
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
81 finally
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
82 call delete('Xtest')
73eb8a2d7f04 patch 8.0.1267: Test_swap_group may leave file behind
Christian Brabandt <cb@256bit.org>
parents: 12777
diff changeset
83 endtry
12750
0b6c09957b43 patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 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
85
4d5a1ada407e patch 8.0.1819: swap file warning for file with non-existing directory
Christian Brabandt <cb@256bit.org>
parents: 12779
diff changeset
86 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
87 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
88 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
89
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 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
91 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
92 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
93 " 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
94 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
95 only
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 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
98 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
99 endfunc