blob: 956f3d718072e8908ea411a1e2e34cf8a5596b6b [file] [log] [blame]
Shougo Matsushita60c87432024-06-03 22:59:27 +02001" Test filecopy()
2
Shougo Matsushita60c87432024-06-03 22:59:27 +02003func Test_copy_file_to_file()
4 call writefile(['foo'], 'Xcopy1')
5
6 call assert_true(filecopy('Xcopy1', 'Xcopy2'))
7
8 call assert_equal(['foo'], readfile('Xcopy2'))
9
10 " When the destination file already exists, it should not be overwritten.
11 call writefile(['foo'], 'Xcopy1')
12 call writefile(['bar'], 'Xcopy2', 'D')
13 call assert_false(filecopy('Xcopy1', 'Xcopy2'))
14 call assert_equal(['bar'], readfile('Xcopy2'))
15
16 call delete('Xcopy2')
17 call delete('Xcopy1')
18endfunc
19
20func Test_copy_symbolic_link()
21 CheckUnix
22
23 call writefile(['text'], 'Xtestfile', 'D')
24 silent !ln -s -f Xtestfile Xtestlink
25
26 call assert_true(filecopy('Xtestlink', 'Xtestlink2'))
27 call assert_equal('link', getftype('Xtestlink2'))
28 call assert_equal(['text'], readfile('Xtestlink2'))
29
30 " When the destination file already exists, it should not be overwritten.
31 call assert_false(filecopy('Xtestlink', 'Xtestlink2'))
32
33 call delete('Xtestlink2')
34 call delete('Xtestlink')
35 call delete('Xtestfile')
36endfunc
37
38func Test_copy_dir_to_dir()
39 call mkdir('Xcopydir1')
40 call writefile(['foo'], 'Xcopydir1/Xfilecopy')
41 call mkdir('Xcopydir2')
42
43 " Directory copy is not supported
44 call assert_false(filecopy('Xcopydir1', 'Xcopydir2'))
45
46 call delete('Xcopydir2', 'rf')
47 call delete('Xcopydir1', 'rf')
48endfunc
49
50func Test_copy_fails()
51 CheckUnix
52
53 call writefile(['foo'], 'Xfilecopy', 'D')
54
55 " Can't copy into a non-existing directory.
56 call assert_false(filecopy('Xfilecopy', 'Xdoesnotexist/Xfilecopy'))
57
58 " Can't copy a non-existing file.
59 call assert_false(filecopy('Xdoesnotexist', 'Xfilecopy2'))
60 call assert_equal('', glob('Xfilecopy2'))
61
62 " Can't copy to en empty file name.
63 call assert_false(filecopy('Xfilecopy', ''))
64
65 call assert_fails('call filecopy("Xfilecopy", [])', 'E1174:')
66 call assert_fails('call filecopy(0z, "Xfilecopy")', 'E1174:')
67endfunc
68
69" vim: shiftwidth=2 sts=2 expandtab