blob: eb4860e709ed6f46cb96d95406094090ab4e054d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
# file : tests/test/script/builtin/mv.testscript
# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
.include ../common.testscript
: unknown-option
:
$c <<EOI && $b
mv -u 2>"mv: unknown option '-u'" == 1
EOI
: args
:
{
: none
:
$c <'mv 2>"mv: missing arguments" == 1' && $b
: no-source
:
$c <'mv a 2>"mv: missing source path" == 1' && $b
: no-trailing-sep
:
$c <<EOI && $b
mv a b c 2>"mv: multiple source paths without trailing separator for destination directory" == 1
EOI
: empty
:
{
: dest
:
$c <<EOI && $b
mv '' 2>"mv: invalid path ''" == 1
EOI
: src1
:
$c <<EOI && $b
mv '' a 2>"mv: invalid path ''" == 1
EOI
: src2
:
$c <<EOI && $b
mv '' a b/ 2>"mv: invalid path ''" == 1
EOI
}
}
: synopsis-1
:
: Move an entity to the specified path.
:
{
: file
:
{
: existing
:
{
: to-non-existing
:
$c <<EOI && $b
touch a;
mv a b && test -f b && test -f a == 1
EOI
: to-existing
:
$c <<EOI && $b
touch a b;
mv a b && test -f b && test -f a == 1
EOI
: to-self
:
$c <<EOI && $b
touch a;
mv a a 2>>/~%EOE% != 0
%mv: unable to move entity '.+/a' to itself%
EOE
EOI
: to-dir
:
$c <<EOI && $b
touch a;
mkdir b;
mv a b 2>>/~%EOE% != 0
%mv: unable to move entity '.+/a' to '.+/b': .+%
EOE
EOI
}
: outside-scope
:
: Need to use a path that unlikely exists (not to remove something useful).
:
{
: fail
:
: Moving path outside the testscript working directory fails.
:
$c <<EOI && $b
mv ../../a/b/c ./c 2>>/~%EOE% == 1
%mv: '.+/fail/a/b/c' is out of working directory '.+/fail/test'%
EOE
EOI
: force
:
: Moving path outside the testscript working directory is allowed with -f
: option. We fail after this check succeeds as the source path does not
: exist.
:
$c <<EOI && $b
mv -f ../../a/b/c ./c 2>>/~%EOE% == 1
%mv: unable to move entity '.+/force/a/b/c' to '.+/c': .+%
EOE
EOI
}
: cleanup
:
{
: existing
:
: Test that moving over an existing file does not move the cleanup. If
: it does, then the file would be removed while leaving the embedded
: scope, and so the cleanup registered by the outer touch would fail. We
: also test that the source path cleanup is removed, otherwise it would
: fail.
:
$c <<EOI && $b
+touch b
{
touch a;
mv a ../b
}
EOI
}
}
: dir
:
{
: existing
:
{
: to-non-existing
:
: Note the here we also test that b path is cleaned up as a directory.
:
$c <<EOI && $b
mkdir a;
mv a b && test -d b && test -d a == 1
EOI
: to-non-empty
:
$c <<EOI && $b
mkdir a b;
touch b/c;
mv a b 2>>/~%EOE% != 0
%mv: unable to move entity '.+/a' to '.+/b': .+%
EOE
EOI
: to-non-dir
:
$c <<EOI && $b
mkdir a;
touch b;
mv a b 2>>/~%EOE% != 0
%mv: unable to move entity '.+/a' to '.+/b': .+%
EOE
EOI
}
: working-dir
:
{
: src
:
{
$c <<EOI && $b
mv $~ b 2>"mv: '([string] $~)' contains test working directory '$~'" != 0
EOI
}
: dst
:
{
$c <<EOI && $b
mkdir a;
mv a "$~" 2>"mv: '$~' contains test working directory '$~'" != 0
EOI
}
}
: overlap
:
$c <<EOI && $b
mkdir a;
mv a a/b 2>>/~%EOE% != 0
%mv: unable to move entity '.+/a' to '.+/a/b': .+%
EOE
EOI
: cleanup
:
{
: sub-entry
:
{
mkdir a;
touch a/b;
mv a c
}
: reorder
:
: Test that a/, that is created before b/ and so should be removed after
: it, get removed before b/ after being renamed to b/c.
:
$c <<EOI && $b
mkdir a b;
mv a b/c
EOI
}
}
: non-existing
:
{
$c <<EOI && $b
mv a b 2>>/~%EOE% != 0
%mv: unable to move entity '.+/a' to '.+/b': .+%
EOE
EOI
}
}
: synopsis-2
:
: Move entities into the specified directory.
:
{
$c <<EOI && $b
mkdir a c;
touch a/b b;
mv a b c/;
test -d c/a && test -f c/a/b && test -f c/b
EOI
}
|