Shougo Matsushita | 60c8743 | 2024-06-03 22:59:27 +0200 | [diff] [blame] | 1 | " Test filecopy() |
| 2 | |
Shougo Matsushita | 60c8743 | 2024-06-03 22:59:27 +0200 | [diff] [blame] | 3 | func 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') |
| 18 | endfunc |
| 19 | |
| 20 | func 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') |
| 36 | endfunc |
| 37 | |
| 38 | func 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') |
| 48 | endfunc |
| 49 | |
| 50 | func 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:') |
| 67 | endfunc |
| 68 | |
| 69 | " vim: shiftwidth=2 sts=2 expandtab |