Mercurial > vim
annotate src/testdir/test_rename.vim @ 17657:0da9bc55c31a v8.1.1826
patch 8.1.1826: tests use hand coded feature and option checks
commit https://github.com/vim/vim/commit/8c5a278fc508da6dfe50e69b6ee734451aa4eafb
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Aug 7 23:07:07 2019 +0200
patch 8.1.1826: tests use hand coded feature and option checks
Problem: Tests use hand coded feature and option checks.
Solution: Use the commands from check.vim in more tests.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 07 Aug 2019 23:15:07 +0200 |
parents | 4024dbfd3099 |
children | 2029737e6a22 |
rev | line source |
---|---|
15961
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 " Test rename() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 func Test_rename_file_to_file() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 call writefile(['foo'], 'Xrename1') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 call assert_equal(0, rename('Xrename1', 'Xrename2')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 call assert_equal('', glob('Xrename1')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 call assert_equal(['foo'], readfile('Xrename2')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 " When the destination file already exists, it should be overwritten. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 call writefile(['foo'], 'Xrename1') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 call writefile(['bar'], 'Xrename2') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 call assert_equal(0, rename('Xrename1', 'Xrename2')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 call assert_equal('', glob('Xrename1')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 call assert_equal(['foo'], readfile('Xrename2')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 call delete('Xrename2') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 endfunc |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 func Test_rename_file_ignore_case() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 " With 'fileignorecase', renaming file will go through a temp file |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 " when the source and destination file only differ by case. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 set fileignorecase |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 call writefile(['foo'], 'Xrename') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 call assert_equal(0, rename('Xrename', 'XRENAME')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 call assert_equal(['foo'], readfile('XRENAME')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 set fileignorecase& |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 call delete('XRENAME') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 endfunc |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 func Test_rename_same_file() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 call writefile(['foo'], 'Xrename') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 " When the source and destination are the same file, nothing |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 " should be done. The source file should not be deleted. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 call assert_equal(0, rename('Xrename', 'Xrename')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 call assert_equal(['foo'], readfile('Xrename')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 call assert_equal(0, rename('./Xrename', 'Xrename')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 call assert_equal(['foo'], readfile('Xrename')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 call delete('Xrename') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 endfunc |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 func Test_rename_dir_to_dir() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 call mkdir('Xrenamedir1') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 call writefile(['foo'], 'Xrenamedir1/Xrenamefile') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 call assert_equal(0, rename('Xrenamedir1', 'Xrenamedir2')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 call assert_equal('', glob('Xrenamedir1')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 call assert_equal(['foo'], readfile('Xrenamedir2/Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 call delete('Xrenamedir2/Xrenamefile') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 call delete('Xrenamedir2', 'd') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 endfunc |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 func Test_rename_same_dir() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 call mkdir('Xrenamedir') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 call writefile(['foo'], 'Xrenamedir/Xrenamefile') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 call assert_equal(0, rename('Xrenamedir', 'Xrenamedir')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 call assert_equal(['foo'], readfile('Xrenamedir/Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 call delete('Xrenamedir/Xrenamefile') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 call delete('Xrenamedir', 'd') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 endfunc |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 func Test_rename_copy() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 " Check that when original file can't be deleted, rename() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 " still succeeds but copies the file. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 call mkdir('Xrenamedir') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 call writefile(['foo'], 'Xrenamedir/Xrenamefile') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 call setfperm('Xrenamedir', 'r-xr-xr-x') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 call assert_equal(0, rename('Xrenamedir/Xrenamefile', 'Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 if !has('win32') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 " On Windows, the source file is removed despite |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 " its directory being made not writable. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 call assert_equal(['foo'], readfile('Xrenamedir/Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 endif |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 call assert_equal(['foo'], readfile('Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 call setfperm('Xrenamedir', 'rwxrwxrwx') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 call delete('Xrenamedir/Xrenamefile') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 call delete('Xrenamedir', 'd') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 call delete('Xrenamefile') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 endfunc |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 func Test_rename_fails() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 call writefile(['foo'], 'Xrenamefile') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 " Can't rename into a non-existing directory. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 call assert_notequal(0, rename('Xrenamefile', 'Xdoesnotexist/Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 " Can't rename a non-existing file. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 call assert_notequal(0, rename('Xdoesnotexist', 'Xrenamefile2')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 call assert_equal('', glob('Xrenamefile2')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 " When rename() fails, the destination file should not be deleted. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 call assert_notequal(0, rename('Xdoesnotexist', 'Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 call assert_equal(['foo'], readfile('Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 " Can't rename to en empty file name. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 call assert_notequal(0, rename('Xrenamefile', '')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 call assert_fails('call rename("Xrenamefile", [])', 'E730') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 call assert_fails('call rename(0z, "Xrenamefile")', 'E976') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 call delete('Xrenamefile') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 endfunc |