0
0
mirror of https://github.com/vim/vim.git synced 2025-10-27 09:24:23 -04:00
Files
vim/src/testdir/test_filecopy.vim
Christian Brabandt b0905e269d patch 9.1.1524: tests: too many imports in the test suite
Problem:  tests: too many imports in the test suite
Solution: Clean up the imported scripts

Most tests make use of check.vim, so let's just source it once in
runtest.vim instead of having each test manually source it.

runtest.vim already sources shared.vim, which again sources
view_util.vim, so we don't need to source those two common
dependencies in all the other tests

And then check.vim sources term_util.vim already, so we can in addition
drop sourcing it explicitly in each single test script.

Note: test_expand_func.vim had to be updated to account for the changed
number of sourced files.

And finally check.vim uses line-continuation so let's also explicitly
enable line continuation via the 'cpo' option value.

related: #17677

Signed-off-by: Christian Brabandt <cb@256bit.org>
2025-07-07 20:39:29 +02:00

70 lines
1.9 KiB
VimL

" Test filecopy()
func Test_copy_file_to_file()
call writefile(['foo'], 'Xcopy1')
call assert_true(filecopy('Xcopy1', 'Xcopy2'))
call assert_equal(['foo'], readfile('Xcopy2'))
" When the destination file already exists, it should not be overwritten.
call writefile(['foo'], 'Xcopy1')
call writefile(['bar'], 'Xcopy2', 'D')
call assert_false(filecopy('Xcopy1', 'Xcopy2'))
call assert_equal(['bar'], readfile('Xcopy2'))
call delete('Xcopy2')
call delete('Xcopy1')
endfunc
func Test_copy_symbolic_link()
CheckUnix
call writefile(['text'], 'Xtestfile', 'D')
silent !ln -s -f Xtestfile Xtestlink
call assert_true(filecopy('Xtestlink', 'Xtestlink2'))
call assert_equal('link', getftype('Xtestlink2'))
call assert_equal(['text'], readfile('Xtestlink2'))
" When the destination file already exists, it should not be overwritten.
call assert_false(filecopy('Xtestlink', 'Xtestlink2'))
call delete('Xtestlink2')
call delete('Xtestlink')
call delete('Xtestfile')
endfunc
func Test_copy_dir_to_dir()
call mkdir('Xcopydir1')
call writefile(['foo'], 'Xcopydir1/Xfilecopy')
call mkdir('Xcopydir2')
" Directory copy is not supported
call assert_false(filecopy('Xcopydir1', 'Xcopydir2'))
call delete('Xcopydir2', 'rf')
call delete('Xcopydir1', 'rf')
endfunc
func Test_copy_fails()
CheckUnix
call writefile(['foo'], 'Xfilecopy', 'D')
" Can't copy into a non-existing directory.
call assert_false(filecopy('Xfilecopy', 'Xdoesnotexist/Xfilecopy'))
" Can't copy a non-existing file.
call assert_false(filecopy('Xdoesnotexist', 'Xfilecopy2'))
call assert_equal('', glob('Xfilecopy2'))
" Can't copy to en empty file name.
call assert_false(filecopy('Xfilecopy', ''))
call assert_fails('call filecopy("Xfilecopy", [])', 'E1174:')
call assert_fails('call filecopy(0z, "Xfilecopy")', 'E1174:')
endfunc
" vim: shiftwidth=2 sts=2 expandtab