b96c5cea6ce96a4edf96d5dcc2281d2334e86a09
[oweals/busybox.git] / tests / cp_tests.mk
1 # cp_tests.mk - Set of test cases for busybox cp
2 # -------------
3 # Copyright (C) 2000 Karl M. Hegbloom <karlheg@debian.org> GPL
4 #
5
6 # GNU `cp'
7 GCP = /bin/cp
8 # BusyBox `cp'
9 BCP = $(shell pwd)/cp
10
11 all:: cp_tests
12 clean:: cp_clean
13
14 cp_clean:
15         - rm -rf cp_tests cp_*.{gnu,bb} cp
16
17 # check_cp_dir_to_dir_wo_a removed from this list; see below
18 cp_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 \
20         check_cp_files_to_dir_w_p check_cp_files_to_dir_w_p_and_d \
21         check_cp_dir_to_dir_w_a \
22         check_cp_dir_to_dir_w_a_take_two
23
24 check_exists:
25         @echo;
26         @echo "No output from diff means busybox cp is functioning properly.";
27         @echo "Some tests might show timestamp differences that are Ok.";
28
29         @echo;
30         @echo Verify that busybox cp exists;
31         @echo ------------------------------;
32         [ -x ${BCP} ] || exit 0
33
34         @echo;
35         mkdir cp_tests;
36
37 check_simple_cp:
38         @echo Copy a file to a copy of the file;
39         @echo ------------------------------;
40         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;
47         rm -rf cp_tests/*;
48
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;
57         @echo Might show timestamp differences.
58         -diff -u cp_afile_afilecopy.gnu cp_afile_afilecopy.bb;
59
60         @echo;
61         rm -rf cp_tests/*;
62
63 check_cp_symlnk:
64         @echo; echo Copy a file pointed to by a symlink;
65         @echo ------------------------------;
66         cd cp_tests;                            \
67          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
96 check_cp_symlink_w_a:
97         @echo; echo Copy a symlink, useing the -a switch.;
98         @echo ------------------------------;
99         cd cp_tests;                            \
100          echo A file > afile;                   \
101          mkdir here there;                      \
102          cd here;                               \
103           ln -s ../afile .
104
105         cd cp_tests;                            \
106          ls -lR . > ../cp_a_symlink.gnu;        \
107          ${GCP} -a here/afile there;            \
108          ls -lR . >> ../cp_a_symlink.gnu;
109
110         @echo;
111         rm -rf cp_tests/there/*;
112
113         sleep 1;
114
115         @echo;
116         cd cp_tests;                            \
117          echo A file > afile;                   \
118          ls -lR . > ../cp_a_symlink.bb;         \
119          ${BCP} -a here/afile there;            \
120          ls -lR . >> ../cp_a_symlink.bb;
121
122         @echo;
123         diff -u cp_a_symlink.gnu cp_a_symlink.bb;
124
125         @echo;
126         rm -rf cp_tests/*;
127
128
129 check_cp_files_to_dir:
130         # Copy a set of files to a directory.
131         @echo; echo Copy a set of files to a directory.;
132         @echo ------------------------------;
133         cd cp_tests;                            \
134          echo A file number one > afile1;       \
135          echo A file number two, blah. > afile2; \
136          ln -s afile1 symlink1;                 \
137          mkdir there;
138
139         cd cp_tests;                            \
140          ${GCP} afile1 afile2 symlink1 there/;  \
141          ls -lR > ../cp_files_dir.gnu;
142
143         @echo;
144         rm -rf cp_tests/there/*;
145
146         @echo;
147         cd cp_tests;                            \
148          ${BCP} afile1 afile2 symlink1 there/;  \
149          ls -lR > ../cp_files_dir.bb;
150
151         @echo;
152         diff -u cp_files_dir.gnu cp_files_dir.bb;
153
154         @echo;
155         rm -rf cp_tests/*;
156
157 check_cp_files_to_dir_w_d:
158         # 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 ------------------------------;
161         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
187 check_cp_files_to_dir_w_p:
188         # 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 ------------------------------;
191         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
219
220 check_cp_files_to_dir_w_p_and_d:
221         @echo; echo Copy a set of files to a directory with -p and -d switches.
222         @echo ------------------------------;
223         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
251 # 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.
256 check_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
286 check_cp_dir_to_dir_w_a:
287         @echo; echo Copy a directory into another directory with the -a switch.
288         @echo ------------------------------;
289         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
300         @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
318         @echo;
319         rm -rf cp_tests/dir{a,b};
320
321
322 check_cp_dir_to_dir_w_a_take_two:
323         @echo; echo Copy a directory into another directory with the -a switch;
324         @echo ------------------------------;
325         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;
333
334         @echo;
335         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;
339
340         @echo;
341         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