annotate src/testdir/test_delete.vim @ 7641:b44fc33ef92a v7.4.1120

commit https://github.com/vim/vim/commit/336bd622c31e1805495c034e1a8cfadcc0bbabc7 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 17 18:23:58 2016 +0100 patch 7.4.1120 Problem: delete(x, 'rf') fails if a directory is empty. (Lcd) Solution: Ignore not finding matches in an empty directory.
author Christian Brabandt <cb@256bit.org>
date Sun, 17 Jan 2016 18:30:05 +0100
parents befbed72da87
children 7f355d8cd634
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7615
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for delete().
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 func Test_file_delete()
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 split Xfile
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 call setline(1, ['a', 'b'])
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 wq
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 call assert_equal(['a', 'b'], readfile('Xfile'))
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 call assert_equal(0, delete('Xfile'))
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 call assert_fails('call readfile("Xfile")', 'E484:')
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 call assert_equal(-1, delete('Xfile'))
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 endfunc
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 func Test_dir_delete()
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 call mkdir('Xdir1')
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call assert_true(isdirectory('Xdir1'))
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 call assert_equal(0, delete('Xdir1', 'd'))
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 call assert_false(isdirectory('Xdir1'))
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 call assert_equal(-1, delete('Xdir1', 'd'))
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 endfunc
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 func Test_recursive_delete()
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 call mkdir('Xdir1')
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 call mkdir('Xdir1/subdir')
7641
b44fc33ef92a commit https://github.com/vim/vim/commit/336bd622c31e1805495c034e1a8cfadcc0bbabc7
Christian Brabandt <cb@256bit.org>
parents: 7629
diff changeset
24 call mkdir('Xdir1/empty')
7615
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 split Xdir1/Xfile
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 call setline(1, ['a', 'b'])
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 w
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 w Xdir1/subdir/Xfile
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 close
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 call assert_true(isdirectory('Xdir1'))
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 call assert_equal(['a', 'b'], readfile('Xdir1/Xfile'))
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 call assert_true(isdirectory('Xdir1/subdir'))
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 call assert_equal(['a', 'b'], readfile('Xdir1/subdir/Xfile'))
7641
b44fc33ef92a commit https://github.com/vim/vim/commit/336bd622c31e1805495c034e1a8cfadcc0bbabc7
Christian Brabandt <cb@256bit.org>
parents: 7629
diff changeset
34 call assert_true(isdirectory('Xdir1/empty'))
7615
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 call assert_equal(0, delete('Xdir1', 'rf'))
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 call assert_false(isdirectory('Xdir1'))
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 call assert_equal(-1, delete('Xdir1', 'd'))
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 endfunc
7629
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
39
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
40 func Test_symlink_delete()
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
41 if !has('unix')
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
42 return
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
43 endif
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
44 split Xfile
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
45 call setline(1, ['a', 'b'])
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
46 wq
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
47 silent !ln -s Xfile Xlink
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
48 " Delete the link, not the file
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
49 call assert_equal(0, delete('Xlink'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
50 call assert_equal(-1, delete('Xlink'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
51 call assert_equal(0, delete('Xfile'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
52 endfunc
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
53
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
54 func Test_symlink_dir_delete()
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
55 if !has('unix')
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
56 return
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
57 endif
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
58 call mkdir('Xdir1')
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
59 silent !ln -s Xdir1 Xlink
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
60 call assert_true(isdirectory('Xdir1'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
61 call assert_true(isdirectory('Xlink'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
62 " Delete the link, not the directory
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
63 call assert_equal(0, delete('Xlink'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
64 call assert_equal(-1, delete('Xlink'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
65 call assert_equal(0, delete('Xdir1', 'd'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
66 endfunc
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
67
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
68 func Test_symlink_recursive_delete()
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
69 if !has('unix')
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
70 return
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
71 endif
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
72 call mkdir('Xdir3')
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
73 call mkdir('Xdir3/subdir')
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
74 call mkdir('Xdir4')
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
75 split Xdir3/Xfile
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
76 call setline(1, ['a', 'b'])
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
77 w
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
78 w Xdir3/subdir/Xfile
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
79 w Xdir4/Xfile
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
80 close
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
81 silent !ln -s ../Xdir4 Xdir3/Xlink
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
82
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
83 call assert_true(isdirectory('Xdir3'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
84 call assert_equal(['a', 'b'], readfile('Xdir3/Xfile'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
85 call assert_true(isdirectory('Xdir3/subdir'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
86 call assert_equal(['a', 'b'], readfile('Xdir3/subdir/Xfile'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
87 call assert_true(isdirectory('Xdir4'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
88 call assert_true(isdirectory('Xdir3/Xlink'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
89 call assert_equal(['a', 'b'], readfile('Xdir4/Xfile'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
90
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
91 call assert_equal(0, delete('Xdir3', 'rf'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
92 call assert_false(isdirectory('Xdir3'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
93 call assert_equal(-1, delete('Xdir3', 'd'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
94 " symlink is deleted, not the directory it points to
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
95 call assert_true(isdirectory('Xdir4'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
96 call assert_equal(['a', 'b'], readfile('Xdir4/Xfile'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
97 call assert_equal(0, delete('Xdir4/Xfile'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
98 call assert_equal(0, delete('Xdir4', 'd'))
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
99 endfunc