blob: f6e6c0df782b58deb3e873ce4e33743887780184 [file] [log] [blame]
Erik Andersen029011b2000-03-04 21:19:32 +00001# cp_tests.mk - Set of test cases for busybox cp
2# -------------
3# Copyright (C) 2000 Karl M. Hegbloom <karlheg@debian.org> GPL
4#
Erik Andersenfac10d72000-02-07 05:29:42 +00005
6# GNU `cp'
7GCP = /bin/cp
8# BusyBox `cp'
9BCP = $(shell pwd)/cp
10
Erik Andersen029011b2000-03-04 21:19:32 +000011all:: cp_tests
12clean:: cp_clean
Erik Andersenfac10d72000-02-07 05:29:42 +000013
Erik Andersen029011b2000-03-04 21:19:32 +000014cp_clean:
15 - rm -rf cp_tests cp_*.{gnu,bb} cp
16
Eric Andersen28c70b32000-06-14 20:42:57 +000017cp_tests: cp_clean cp check_exists check_simple_cp check_cp_symlnk \
18 check_cp_symlink_w_a check_cp_files_to_dir check_cp_files_to_dir_w_d \
Eric Andersen3f755032000-06-14 22:16:59 +000019 check_cp_files_to_dir_w_p check_cp_files_to_dir_w_p_and_d \
Eric Andersen28c70b32000-06-14 20:42:57 +000020 check_cp_dir_to_dir_wo_a check_cp_dir_to_dir_w_a \
21 check_cp_dir_to_dir_w_a_take_two
22
23check_exists:
Erik Andersenfac10d72000-02-07 05:29:42 +000024 @echo;
25 @echo "No output from diff means busybox cp is functioning properly.";
Erik Andersen029011b2000-03-04 21:19:32 +000026 @echo "Some tests might show timestamp differences that are Ok.";
Erik Andersenfac10d72000-02-07 05:29:42 +000027
28 @echo;
Erik Andersene90f4042000-04-21 21:53:58 +000029 @echo Verify that busybox cp exists;
30 @echo ------------------------------;
31 [ -x ${BCP} ] || exit 0
Erik Andersenfac10d72000-02-07 05:29:42 +000032
33 @echo;
34 mkdir cp_tests;
35
Eric Andersen28c70b32000-06-14 20:42:57 +000036check_simple_cp:
Erik Andersene90f4042000-04-21 21:53:58 +000037 @echo Copy a file to a copy of the file;
Erik Andersen029011b2000-03-04 21:19:32 +000038 @echo ------------------------------;
Erik Andersenfac10d72000-02-07 05:29:42 +000039 cd cp_tests; \
40 echo A file > afile; \
41 ls -l afile > ../cp_afile_afilecopy.gnu; \
42 ${GCP} afile afilecopy; \
43 ls -l afile afilecopy >> ../cp_afile_afilecopy.gnu;
44
45 @echo;
Erik Andersen029011b2000-03-04 21:19:32 +000046 rm -rf cp_tests/*;
Erik Andersenfac10d72000-02-07 05:29:42 +000047
48 @echo;
49 cd cp_tests; \
50 echo A file > afile; \
51 ls -l afile > ../cp_afile_afilecopy.bb; \
52 ${BCP} afile afilecopy; \
53 ls -l afile afilecopy >> ../cp_afile_afilecopy.bb;
54
55 @echo;
Erik Andersen029011b2000-03-04 21:19:32 +000056 @echo Might show timestamp differences.
57 -diff -u cp_afile_afilecopy.gnu cp_afile_afilecopy.bb;
Erik Andersenfac10d72000-02-07 05:29:42 +000058
59 @echo;
Erik Andersen029011b2000-03-04 21:19:32 +000060 rm -rf cp_tests/*;
Erik Andersenfac10d72000-02-07 05:29:42 +000061
Eric Andersen28c70b32000-06-14 20:42:57 +000062check_cp_symlnk:
Erik Andersene90f4042000-04-21 21:53:58 +000063 @echo; echo Copy a file pointed to by a symlink;
64 @echo ------------------------------;
Erik Andersenfac10d72000-02-07 05:29:42 +000065 cd cp_tests; \
Erik Andersen029011b2000-03-04 21:19:32 +000066 mkdir here there; \
67 echo A file > afile; \
68 cd here; \
69 ln -s ../afile .; \
70
71 @echo;
72 cd cp_tests; \
73 ls -lR . > ../cp_symlink.gnu; \
74 ${GCP} here/afile there; \
75 ls -lR . >> ../cp_symlink.gnu;
76
77 @echo;
78 rm -rf cp_tests/there/*;
79
80 sleep 1;
81
82 @echo;
83 cd cp_tests; \
84 ls -lR . > ../cp_symlink.bb; \
85 ${BCP} here/afile there; \
86 ls -lR . >> ../cp_symlink.bb;
87
88 @echo;
89 @echo Will show timestamp difference.
90 -diff -u cp_symlink.gnu cp_symlink.bb;
91
92 @echo;
93 rm -rf cp_tests/*
94
Eric Andersen28c70b32000-06-14 20:42:57 +000095check_cp_symlink_w_a:
Erik Andersene90f4042000-04-21 21:53:58 +000096 @echo; echo Copy a symlink, useing the -a switch.;
97 @echo ------------------------------;
Erik Andersen029011b2000-03-04 21:19:32 +000098 cd cp_tests; \
99 echo A file > afile; \
100 mkdir here there; \
101 cd here; \
102 ln -s ../afile .
103
Erik Andersene90f4042000-04-21 21:53:58 +0000104 cd cp_tests; \
Erik Andersen029011b2000-03-04 21:19:32 +0000105 ls -lR . > ../cp_a_symlink.gnu; \
106 ${GCP} -a here/afile there; \
107 ls -lR . >> ../cp_a_symlink.gnu;
108
109 @echo;
Erik Andersene90f4042000-04-21 21:53:58 +0000110 rm -rf cp_tests/there/*;
Erik Andersen029011b2000-03-04 21:19:32 +0000111
112 sleep 1;
Erik Andersenfac10d72000-02-07 05:29:42 +0000113
114 @echo;
115 cd cp_tests; \
116 echo A file > afile; \
Erik Andersen029011b2000-03-04 21:19:32 +0000117 ls -lR . > ../cp_a_symlink.bb; \
118 ${BCP} -a here/afile there; \
119 ls -lR . >> ../cp_a_symlink.bb;
Erik Andersenfac10d72000-02-07 05:29:42 +0000120
121 @echo;
122 diff -u cp_a_symlink.gnu cp_a_symlink.bb;
123
124 @echo;
Erik Andersene90f4042000-04-21 21:53:58 +0000125 rm -rf cp_tests/*;
Erik Andersenfac10d72000-02-07 05:29:42 +0000126
Erik Andersenfac10d72000-02-07 05:29:42 +0000127
Eric Andersen28c70b32000-06-14 20:42:57 +0000128check_cp_files_to_dir:
Erik Andersene90f4042000-04-21 21:53:58 +0000129 # Copy a set of files to a directory.
130 @echo; echo Copy a set of files to a directory.;
131 @echo ------------------------------;
Erik Andersenfac10d72000-02-07 05:29:42 +0000132 cd cp_tests; \
133 echo A file number one > afile1; \
134 echo A file number two, blah. > afile2; \
135 ln -s afile1 symlink1; \
Erik Andersen029011b2000-03-04 21:19:32 +0000136 mkdir there;
137
138 cd cp_tests; \
139 ${GCP} afile1 afile2 symlink1 there/; \
Erik Andersenfac10d72000-02-07 05:29:42 +0000140 ls -lR > ../cp_files_dir.gnu;
141
142 @echo;
Erik Andersen029011b2000-03-04 21:19:32 +0000143 rm -rf cp_tests/there/*;
Erik Andersenfac10d72000-02-07 05:29:42 +0000144
145 @echo;
146 cd cp_tests; \
Erik Andersen029011b2000-03-04 21:19:32 +0000147 ${BCP} afile1 afile2 symlink1 there/; \
Erik Andersenfac10d72000-02-07 05:29:42 +0000148 ls -lR > ../cp_files_dir.bb;
149
150 @echo;
151 diff -u cp_files_dir.gnu cp_files_dir.bb;
152
153 @echo;
Erik Andersen029011b2000-03-04 21:19:32 +0000154 rm -rf cp_tests/*;
Erik Andersenfac10d72000-02-07 05:29:42 +0000155
Eric Andersen28c70b32000-06-14 20:42:57 +0000156check_cp_files_to_dir_w_d:
Erik Andersene90f4042000-04-21 21:53:58 +0000157 # Copy a set of files to a directory with the -d switch.
158 @echo; echo Copy a set of files to a directory with the -d switch.;
159 @echo ------------------------------;
Erik Andersenfac10d72000-02-07 05:29:42 +0000160 cd cp_tests; \
161 echo A file number one > afile1; \
162 echo A file number two, blah. > afile2; \
163 ln -s afile1 symlink1; \
164 mkdir there1; \
165 ${GCP} -d afile1 afile2 symlink1 there1/; \
166 ls -lR > ../cp_d_files_dir.gnu;
167
168 @echo;
169 rm -rf cp_tests/{afile{1,2},symlink1,there1};
170
171 @echo;
172 cd cp_tests; \
173 echo A file number one > afile1; \
174 echo A file number two, blah. > afile2; \
175 ln -s afile1 symlink1; \
176 mkdir there1; \
177 ${BCP} -d afile1 afile2 symlink1 there1/; \
178 ls -lR > ../cp_d_files_dir.bb;
179
180 @echo;
181 diff -u cp_d_files_dir.gnu cp_d_files_dir.bb;
182
183 @echo;
184 rm -rf cp_tests/{afile{1,2},symlink1,there1};
185
Eric Andersen28c70b32000-06-14 20:42:57 +0000186check_cp_files_to_dir_w_p:
Erik Andersene90f4042000-04-21 21:53:58 +0000187 # Copy a set of files to a directory with the -p switch.
188 @echo; echo Copy a set of files to a directory with the -p switch.;
189 @echo ------------------------------;
Erik Andersenfac10d72000-02-07 05:29:42 +0000190 cd cp_tests; \
191 echo A file number one > afile1; \
192 echo A file number two, blah. > afile2; \
193 touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
194 ln -s afile1 symlink1; \
195 mkdir there1; \
196 ${GCP} -p afile1 afile2 symlink1 there1/; \
197 ls -lR > ../cp_p_files_dir.gnu;
198
199 @echo;
200 rm -rf cp_tests/{afile{1,2},symlink1,there1};
201
202 @echo;
203 cd cp_tests; \
204 echo A file number one > afile1; \
205 echo A file number two, blah. > afile2; \
206 touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
207 ln -s afile1 symlink1; \
208 mkdir there1; \
209 ${BCP} -p afile1 afile2 symlink1 there1/; \
210 ls -lR > ../cp_p_files_dir.bb;
211
212 @echo;
213 diff -u cp_p_files_dir.gnu cp_p_files_dir.bb;
214
215 @echo;
216 rm -rf cp_tests/{afile{1,2},symlink1,there1};
217
Eric Andersen28c70b32000-06-14 20:42:57 +0000218
219check_cp_files_to_dir_w_p_and_d:
Erik Andersene90f4042000-04-21 21:53:58 +0000220 @echo; echo Copy a set of files to a directory with -p and -d switches.
221 @echo ------------------------------;
Erik Andersenfac10d72000-02-07 05:29:42 +0000222 cd cp_tests; \
223 echo A file number one > afile1; \
224 echo A file number two, blah. > afile2; \
225 touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
226 ln -s afile1 symlink1; \
227 mkdir there1; \
228 ${GCP} -p -d afile1 afile2 symlink1 there1/; \
229 ls -lR > ../cp_pd_files_dir.gnu;
230
231 @echo;
232 rm -rf cp_tests/{afile{1,2},symlink1,there1};
233
234 @echo;
235 cd cp_tests; \
236 echo A file number one > afile1; \
237 echo A file number two, blah. > afile2; \
238 touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
239 ln -s afile1 symlink1; \
240 mkdir there1; \
241 ${BCP} -p -d afile1 afile2 symlink1 there1/; \
242 ls -lR > ../cp_pd_files_dir.bb;
243
244 @echo;
245 diff -u cp_pd_files_dir.gnu cp_pd_files_dir.bb;
246
247 @echo;
248 rm -rf cp_tests/{afile{1,2},symlink1,there1};
249
Eric Andersen28c70b32000-06-14 20:42:57 +0000250check_cp_dir_to_dir_wo_a:
251 # Copy a directory to another directory, without the -a switch.
252 @echo; echo Copy a directory to another directory, without the -a switch.
253 @echo ------------------------------;
254 @echo There should be an error message about cannot cp a dir to a subdir of itself.
255 cd cp_tests; \
256 touch a b c; \
257 mkdir adir; \
258 ls -lR . > ../cp_a_star_adir.gnu; \
259 ${GCP} -a * adir; \
260 ls -lR . >> ../cp_a_star_adir.gnu;
261
262 @echo
263 @echo There should be an error message about cannot cp a dir to a subdir of itself.
264 cd cp_tests; \
265 rm -rf adir; \
266 mkdir adir; \
267 ls -lR . > ../cp_a_star_adir.bb; \
268 ${BCP} -a * adir; \
269 ls -lR . >> ../cp_a_star_adir.bb;
270
271 @echo;
272 diff -u cp_a_star_adir.gnu cp_a_star_adir.bb;
273
274 # Done
275 @echo;
276 rm -rf cp_tests;
277 @echo; echo Done.
278
279
280check_cp_dir_to_dir_w_a:
Erik Andersene90f4042000-04-21 21:53:58 +0000281 @echo; echo Copy a directory into another directory with the -a switch.
282 @echo ------------------------------;
Erik Andersenfac10d72000-02-07 05:29:42 +0000283 cd cp_tests; \
284 mkdir dir{a,b}; \
285 echo A file > dira/afile; \
286 echo A file in dirb > dirb/afileindirb; \
287 ln -s dira/afile dira/alinktoafile; \
288 mkdir dira/subdir1; \
289 echo Another file > dira/subdir1/anotherfile; \
290 ls -lR . > ../cp_a_dira_dirb.gnu; \
291 ${GCP} -a dira dirb; \
292 ls -lR . >> ../cp_a_dira_dirb.gnu;
293
Erik Andersenfac10d72000-02-07 05:29:42 +0000294 @echo;
295 rm -rf cp_tests/dir{a,b};
296
297 @echo;
298 cd cp_tests; \
299 mkdir dir{a,b}; \
300 echo A file > dira/afile; \
301 echo A file in dirb > dirb/afileindirb; \
302 ln -s dira/afile dira/alinktoafile; \
303 mkdir dira/subdir1; \
304 echo Another file > dira/subdir1/anotherfile; \
305 ls -lR . > ../cp_a_dira_dirb.bb; \
306 ${BCP} -a dira dirb; \
307 ls -lR . >> ../cp_a_dira_dirb.bb;
308
309 @echo;
310 diff -u cp_a_dira_dirb.gnu cp_a_dira_dirb.bb;
311
Erik Andersenfac10d72000-02-07 05:29:42 +0000312 @echo;
313 rm -rf cp_tests/dir{a,b};
Erik Andersen029011b2000-03-04 21:19:32 +0000314
Eric Andersen28c70b32000-06-14 20:42:57 +0000315
316check_cp_dir_to_dir_w_a_take_two:
317 @echo; echo Copy a directory into another directory with the -a switch;
Erik Andersene90f4042000-04-21 21:53:58 +0000318 @echo ------------------------------;
Eric Andersen28c70b32000-06-14 20:42:57 +0000319 mkdir -p cp_tests/gnu; \
320 mkdir -p cp_tests/bb; \
321 cd cp_tests; \
322 mkdir here there; \
323 echo A file > here/afile; \
324 mkdir here/adir; \
325 touch here/adir/afileinadir; \
326 ln -s $$(pwd) here/alink;
Erik Andersen029011b2000-03-04 21:19:32 +0000327
328 @echo;
Eric Andersen28c70b32000-06-14 20:42:57 +0000329 cd cp_tests/gnu; \
330 ls -lR . > ../../cp_a_dir_dir.gnu; \
331 ${GCP} -a here/ there/; \
332 ls -lR . >> ../../cp_a_dir_dir.gnu;
Erik Andersene90f4042000-04-21 21:53:58 +0000333
Erik Andersen029011b2000-03-04 21:19:32 +0000334 @echo;
Eric Andersen28c70b32000-06-14 20:42:57 +0000335 rm -rf cp_tests/there/*;
336
337 sleep 1;
338
339 @echo;
340 cd cp_tests/bb; \
341 ls -lR . > ../../cp_a_dir_dir.bb; \
342 ${BCP} -a here/ there/; \
343 ls -lR . >> ../../cp_a_dir_dir.bb;
344
345 @echo;
346 echo "Erik 1"
347 diff -u cp_a_dir_dir.gnu cp_a_dir_dir.bb;
348 echo "Erik 2"
349
350 @echo;
351 echo "Erik 3"
352 rm -rf cp_tests/*;
353
354