blob: b96c5cea6ce96a4edf96d5dcc2281d2334e86a09 [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 Andersen59ec6012000-12-11 17:33:08 +000017# check_cp_dir_to_dir_wo_a removed from this list; see below
Eric Andersen28c70b32000-06-14 20:42:57 +000018cp_tests: cp_clean cp check_exists check_simple_cp check_cp_symlnk \
19 check_cp_symlink_w_a check_cp_files_to_dir check_cp_files_to_dir_w_d \
Eric Andersen3f755032000-06-14 22:16:59 +000020 check_cp_files_to_dir_w_p check_cp_files_to_dir_w_p_and_d \
Eric Andersen59ec6012000-12-11 17:33:08 +000021 check_cp_dir_to_dir_w_a \
Eric Andersen28c70b32000-06-14 20:42:57 +000022 check_cp_dir_to_dir_w_a_take_two
23
24check_exists:
Erik Andersenfac10d72000-02-07 05:29:42 +000025 @echo;
26 @echo "No output from diff means busybox cp is functioning properly.";
Erik Andersen029011b2000-03-04 21:19:32 +000027 @echo "Some tests might show timestamp differences that are Ok.";
Erik Andersenfac10d72000-02-07 05:29:42 +000028
29 @echo;
Erik Andersene90f4042000-04-21 21:53:58 +000030 @echo Verify that busybox cp exists;
31 @echo ------------------------------;
32 [ -x ${BCP} ] || exit 0
Erik Andersenfac10d72000-02-07 05:29:42 +000033
34 @echo;
35 mkdir cp_tests;
36
Eric Andersen28c70b32000-06-14 20:42:57 +000037check_simple_cp:
Erik Andersene90f4042000-04-21 21:53:58 +000038 @echo Copy a file to a copy of the file;
Erik Andersen029011b2000-03-04 21:19:32 +000039 @echo ------------------------------;
Erik Andersenfac10d72000-02-07 05:29:42 +000040 cd cp_tests; \
41 echo A file > afile; \
42 ls -l afile > ../cp_afile_afilecopy.gnu; \
43 ${GCP} afile afilecopy; \
44 ls -l afile afilecopy >> ../cp_afile_afilecopy.gnu;
45
46 @echo;
Erik Andersen029011b2000-03-04 21:19:32 +000047 rm -rf cp_tests/*;
Erik Andersenfac10d72000-02-07 05:29:42 +000048
49 @echo;
50 cd cp_tests; \
51 echo A file > afile; \
52 ls -l afile > ../cp_afile_afilecopy.bb; \
53 ${BCP} afile afilecopy; \
54 ls -l afile afilecopy >> ../cp_afile_afilecopy.bb;
55
56 @echo;
Erik Andersen029011b2000-03-04 21:19:32 +000057 @echo Might show timestamp differences.
58 -diff -u cp_afile_afilecopy.gnu cp_afile_afilecopy.bb;
Erik Andersenfac10d72000-02-07 05:29:42 +000059
60 @echo;
Erik Andersen029011b2000-03-04 21:19:32 +000061 rm -rf cp_tests/*;
Erik Andersenfac10d72000-02-07 05:29:42 +000062
Eric Andersen28c70b32000-06-14 20:42:57 +000063check_cp_symlnk:
Erik Andersene90f4042000-04-21 21:53:58 +000064 @echo; echo Copy a file pointed to by a symlink;
65 @echo ------------------------------;
Erik Andersenfac10d72000-02-07 05:29:42 +000066 cd cp_tests; \
Erik Andersen029011b2000-03-04 21:19:32 +000067 mkdir here there; \
68 echo A file > afile; \
69 cd here; \
70 ln -s ../afile .; \
71
72 @echo;
73 cd cp_tests; \
74 ls -lR . > ../cp_symlink.gnu; \
75 ${GCP} here/afile there; \
76 ls -lR . >> ../cp_symlink.gnu;
77
78 @echo;
79 rm -rf cp_tests/there/*;
80
81 sleep 1;
82
83 @echo;
84 cd cp_tests; \
85 ls -lR . > ../cp_symlink.bb; \
86 ${BCP} here/afile there; \
87 ls -lR . >> ../cp_symlink.bb;
88
89 @echo;
90 @echo Will show timestamp difference.
91 -diff -u cp_symlink.gnu cp_symlink.bb;
92
93 @echo;
94 rm -rf cp_tests/*
95
Eric Andersen28c70b32000-06-14 20:42:57 +000096check_cp_symlink_w_a:
Erik Andersene90f4042000-04-21 21:53:58 +000097 @echo; echo Copy a symlink, useing the -a switch.;
98 @echo ------------------------------;
Erik Andersen029011b2000-03-04 21:19:32 +000099 cd cp_tests; \
100 echo A file > afile; \
101 mkdir here there; \
102 cd here; \
103 ln -s ../afile .
104
Erik Andersene90f4042000-04-21 21:53:58 +0000105 cd cp_tests; \
Erik Andersen029011b2000-03-04 21:19:32 +0000106 ls -lR . > ../cp_a_symlink.gnu; \
107 ${GCP} -a here/afile there; \
108 ls -lR . >> ../cp_a_symlink.gnu;
109
110 @echo;
Erik Andersene90f4042000-04-21 21:53:58 +0000111 rm -rf cp_tests/there/*;
Erik Andersen029011b2000-03-04 21:19:32 +0000112
113 sleep 1;
Erik Andersenfac10d72000-02-07 05:29:42 +0000114
115 @echo;
116 cd cp_tests; \
117 echo A file > afile; \
Erik Andersen029011b2000-03-04 21:19:32 +0000118 ls -lR . > ../cp_a_symlink.bb; \
119 ${BCP} -a here/afile there; \
120 ls -lR . >> ../cp_a_symlink.bb;
Erik Andersenfac10d72000-02-07 05:29:42 +0000121
122 @echo;
123 diff -u cp_a_symlink.gnu cp_a_symlink.bb;
124
125 @echo;
Erik Andersene90f4042000-04-21 21:53:58 +0000126 rm -rf cp_tests/*;
Erik Andersenfac10d72000-02-07 05:29:42 +0000127
Erik Andersenfac10d72000-02-07 05:29:42 +0000128
Eric Andersen28c70b32000-06-14 20:42:57 +0000129check_cp_files_to_dir:
Erik Andersene90f4042000-04-21 21:53:58 +0000130 # Copy a set of files to a directory.
131 @echo; echo Copy a set of files to a directory.;
132 @echo ------------------------------;
Erik Andersenfac10d72000-02-07 05:29:42 +0000133 cd cp_tests; \
134 echo A file number one > afile1; \
135 echo A file number two, blah. > afile2; \
136 ln -s afile1 symlink1; \
Erik Andersen029011b2000-03-04 21:19:32 +0000137 mkdir there;
138
139 cd cp_tests; \
140 ${GCP} afile1 afile2 symlink1 there/; \
Erik Andersenfac10d72000-02-07 05:29:42 +0000141 ls -lR > ../cp_files_dir.gnu;
142
143 @echo;
Erik Andersen029011b2000-03-04 21:19:32 +0000144 rm -rf cp_tests/there/*;
Erik Andersenfac10d72000-02-07 05:29:42 +0000145
146 @echo;
147 cd cp_tests; \
Erik Andersen029011b2000-03-04 21:19:32 +0000148 ${BCP} afile1 afile2 symlink1 there/; \
Erik Andersenfac10d72000-02-07 05:29:42 +0000149 ls -lR > ../cp_files_dir.bb;
150
151 @echo;
152 diff -u cp_files_dir.gnu cp_files_dir.bb;
153
154 @echo;
Erik Andersen029011b2000-03-04 21:19:32 +0000155 rm -rf cp_tests/*;
Erik Andersenfac10d72000-02-07 05:29:42 +0000156
Eric Andersen28c70b32000-06-14 20:42:57 +0000157check_cp_files_to_dir_w_d:
Erik Andersene90f4042000-04-21 21:53:58 +0000158 # Copy a set of files to a directory with the -d switch.
159 @echo; echo Copy a set of files to a directory with the -d switch.;
160 @echo ------------------------------;
Erik Andersenfac10d72000-02-07 05:29:42 +0000161 cd cp_tests; \
162 echo A file number one > afile1; \
163 echo A file number two, blah. > afile2; \
164 ln -s afile1 symlink1; \
165 mkdir there1; \
166 ${GCP} -d afile1 afile2 symlink1 there1/; \
167 ls -lR > ../cp_d_files_dir.gnu;
168
169 @echo;
170 rm -rf cp_tests/{afile{1,2},symlink1,there1};
171
172 @echo;
173 cd cp_tests; \
174 echo A file number one > afile1; \
175 echo A file number two, blah. > afile2; \
176 ln -s afile1 symlink1; \
177 mkdir there1; \
178 ${BCP} -d afile1 afile2 symlink1 there1/; \
179 ls -lR > ../cp_d_files_dir.bb;
180
181 @echo;
182 diff -u cp_d_files_dir.gnu cp_d_files_dir.bb;
183
184 @echo;
185 rm -rf cp_tests/{afile{1,2},symlink1,there1};
186
Eric Andersen28c70b32000-06-14 20:42:57 +0000187check_cp_files_to_dir_w_p:
Erik Andersene90f4042000-04-21 21:53:58 +0000188 # Copy a set of files to a directory with the -p switch.
189 @echo; echo Copy a set of files to a directory with the -p switch.;
190 @echo ------------------------------;
Erik Andersenfac10d72000-02-07 05:29:42 +0000191 cd cp_tests; \
192 echo A file number one > afile1; \
193 echo A file number two, blah. > afile2; \
194 touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
195 ln -s afile1 symlink1; \
196 mkdir there1; \
197 ${GCP} -p afile1 afile2 symlink1 there1/; \
198 ls -lR > ../cp_p_files_dir.gnu;
199
200 @echo;
201 rm -rf cp_tests/{afile{1,2},symlink1,there1};
202
203 @echo;
204 cd cp_tests; \
205 echo A file number one > afile1; \
206 echo A file number two, blah. > afile2; \
207 touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
208 ln -s afile1 symlink1; \
209 mkdir there1; \
210 ${BCP} -p afile1 afile2 symlink1 there1/; \
211 ls -lR > ../cp_p_files_dir.bb;
212
213 @echo;
214 diff -u cp_p_files_dir.gnu cp_p_files_dir.bb;
215
216 @echo;
217 rm -rf cp_tests/{afile{1,2},symlink1,there1};
218
Eric Andersen28c70b32000-06-14 20:42:57 +0000219
220check_cp_files_to_dir_w_p_and_d:
Erik Andersene90f4042000-04-21 21:53:58 +0000221 @echo; echo Copy a set of files to a directory with -p and -d switches.
222 @echo ------------------------------;
Erik Andersenfac10d72000-02-07 05:29:42 +0000223 cd cp_tests; \
224 echo A file number one > afile1; \
225 echo A file number two, blah. > afile2; \
226 touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
227 ln -s afile1 symlink1; \
228 mkdir there1; \
229 ${GCP} -p -d afile1 afile2 symlink1 there1/; \
230 ls -lR > ../cp_pd_files_dir.gnu;
231
232 @echo;
233 rm -rf cp_tests/{afile{1,2},symlink1,there1};
234
235 @echo;
236 cd cp_tests; \
237 echo A file number one > afile1; \
238 echo A file number two, blah. > afile2; \
239 touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
240 ln -s afile1 symlink1; \
241 mkdir there1; \
242 ${BCP} -p -d afile1 afile2 symlink1 there1/; \
243 ls -lR > ../cp_pd_files_dir.bb;
244
245 @echo;
246 diff -u cp_pd_files_dir.gnu cp_pd_files_dir.bb;
247
248 @echo;
249 rm -rf cp_tests/{afile{1,2},symlink1,there1};
250
Eric Andersen59ec6012000-12-11 17:33:08 +0000251# This test doesn't work any more; gnu cp now _does_ copy a directory
252# to a subdirectory of itself. What's worse, that "feature" has no
253# (documented) way to be disabled with command line switches.
254# It's not obvious that busybox cp should mimic this behavior.
255# For now, this test is removed from the cp_tests list, above.
Eric Andersen28c70b32000-06-14 20:42:57 +0000256check_cp_dir_to_dir_wo_a:
257 # Copy a directory to another directory, without the -a switch.
258 @echo; echo Copy a directory to another directory, without the -a switch.
259 @echo ------------------------------;
260 @echo There should be an error message about cannot cp a dir to a subdir of itself.
261 cd cp_tests; \
262 touch a b c; \
263 mkdir adir; \
264 ls -lR . > ../cp_a_star_adir.gnu; \
265 ${GCP} -a * adir; \
266 ls -lR . >> ../cp_a_star_adir.gnu;
267
268 @echo
269 @echo There should be an error message about cannot cp a dir to a subdir of itself.
270 cd cp_tests; \
271 rm -rf adir; \
272 mkdir adir; \
273 ls -lR . > ../cp_a_star_adir.bb; \
274 ${BCP} -a * adir; \
275 ls -lR . >> ../cp_a_star_adir.bb;
276
277 @echo;
278 diff -u cp_a_star_adir.gnu cp_a_star_adir.bb;
279
280 # Done
281 @echo;
282 rm -rf cp_tests;
283 @echo; echo Done.
284
285
286check_cp_dir_to_dir_w_a:
Erik Andersene90f4042000-04-21 21:53:58 +0000287 @echo; echo Copy a directory into another directory with the -a switch.
288 @echo ------------------------------;
Erik Andersenfac10d72000-02-07 05:29:42 +0000289 cd cp_tests; \
290 mkdir dir{a,b}; \
291 echo A file > dira/afile; \
292 echo A file in dirb > dirb/afileindirb; \
293 ln -s dira/afile dira/alinktoafile; \
294 mkdir dira/subdir1; \
295 echo Another file > dira/subdir1/anotherfile; \
296 ls -lR . > ../cp_a_dira_dirb.gnu; \
297 ${GCP} -a dira dirb; \
298 ls -lR . >> ../cp_a_dira_dirb.gnu;
299
Erik Andersenfac10d72000-02-07 05:29:42 +0000300 @echo;
301 rm -rf cp_tests/dir{a,b};
302
303 @echo;
304 cd cp_tests; \
305 mkdir dir{a,b}; \
306 echo A file > dira/afile; \
307 echo A file in dirb > dirb/afileindirb; \
308 ln -s dira/afile dira/alinktoafile; \
309 mkdir dira/subdir1; \
310 echo Another file > dira/subdir1/anotherfile; \
311 ls -lR . > ../cp_a_dira_dirb.bb; \
312 ${BCP} -a dira dirb; \
313 ls -lR . >> ../cp_a_dira_dirb.bb;
314
315 @echo;
316 diff -u cp_a_dira_dirb.gnu cp_a_dira_dirb.bb;
317
Erik Andersenfac10d72000-02-07 05:29:42 +0000318 @echo;
319 rm -rf cp_tests/dir{a,b};
Erik Andersen029011b2000-03-04 21:19:32 +0000320
Eric Andersen28c70b32000-06-14 20:42:57 +0000321
322check_cp_dir_to_dir_w_a_take_two:
323 @echo; echo Copy a directory into another directory with the -a switch;
Erik Andersene90f4042000-04-21 21:53:58 +0000324 @echo ------------------------------;
Eric Andersen28c70b32000-06-14 20:42:57 +0000325 mkdir -p cp_tests/gnu; \
326 mkdir -p cp_tests/bb; \
327 cd cp_tests; \
328 mkdir here there; \
329 echo A file > here/afile; \
330 mkdir here/adir; \
331 touch here/adir/afileinadir; \
332 ln -s $$(pwd) here/alink;
Erik Andersen029011b2000-03-04 21:19:32 +0000333
334 @echo;
Eric Andersen28c70b32000-06-14 20:42:57 +0000335 cd cp_tests/gnu; \
336 ls -lR . > ../../cp_a_dir_dir.gnu; \
337 ${GCP} -a here/ there/; \
338 ls -lR . >> ../../cp_a_dir_dir.gnu;
Erik Andersene90f4042000-04-21 21:53:58 +0000339
Erik Andersen029011b2000-03-04 21:19:32 +0000340 @echo;
Eric Andersen28c70b32000-06-14 20:42:57 +0000341 rm -rf cp_tests/there/*;
342
343 sleep 1;
344
345 @echo;
346 cd cp_tests/bb; \
347 ls -lR . > ../../cp_a_dir_dir.bb; \
348 ${BCP} -a here/ there/; \
349 ls -lR . >> ../../cp_a_dir_dir.bb;
350
351 @echo;
352 echo "Erik 1"
353 diff -u cp_a_dir_dir.gnu cp_a_dir_dir.bb;
354 echo "Erik 2"
355
356 @echo;
357 echo "Erik 3"
358 rm -rf cp_tests/*;
359
360