Update internal.h to conditionally include asm/string.h
[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 cp_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 \
19         check_cp_files_to_dir_w_p check_cp_files_to_dir_w_p_and_d \
20         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
23 check_exists:
24         @echo;
25         @echo "No output from diff means busybox cp is functioning properly.";
26         @echo "Some tests might show timestamp differences that are Ok.";
27
28         @echo;
29         @echo Verify that busybox cp exists;
30         @echo ------------------------------;
31         [ -x ${BCP} ] || exit 0
32
33         @echo;
34         mkdir cp_tests;
35
36 check_simple_cp:
37         @echo Copy a file to a copy of the file;
38         @echo ------------------------------;
39         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;
46         rm -rf cp_tests/*;
47
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;
56         @echo Might show timestamp differences.
57         -diff -u cp_afile_afilecopy.gnu cp_afile_afilecopy.bb;
58
59         @echo;
60         rm -rf cp_tests/*;
61
62 check_cp_symlnk:
63         @echo; echo Copy a file pointed to by a symlink;
64         @echo ------------------------------;
65         cd cp_tests;                            \
66          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
95 check_cp_symlink_w_a:
96         @echo; echo Copy a symlink, useing the -a switch.;
97         @echo ------------------------------;
98         cd cp_tests;                            \
99          echo A file > afile;                   \
100          mkdir here there;                      \
101          cd here;                               \
102           ln -s ../afile .
103
104         cd cp_tests;                            \
105          ls -lR . > ../cp_a_symlink.gnu;        \
106          ${GCP} -a here/afile there;            \
107          ls -lR . >> ../cp_a_symlink.gnu;
108
109         @echo;
110         rm -rf cp_tests/there/*;
111
112         sleep 1;
113
114         @echo;
115         cd cp_tests;                            \
116          echo A file > afile;                   \
117          ls -lR . > ../cp_a_symlink.bb;         \
118          ${BCP} -a here/afile there;            \
119          ls -lR . >> ../cp_a_symlink.bb;
120
121         @echo;
122         diff -u cp_a_symlink.gnu cp_a_symlink.bb;
123
124         @echo;
125         rm -rf cp_tests/*;
126
127
128 check_cp_files_to_dir:
129         # Copy a set of files to a directory.
130         @echo; echo Copy a set of files to a directory.;
131         @echo ------------------------------;
132         cd cp_tests;                            \
133          echo A file number one > afile1;       \
134          echo A file number two, blah. > afile2; \
135          ln -s afile1 symlink1;                 \
136          mkdir there;
137
138         cd cp_tests;                            \
139          ${GCP} afile1 afile2 symlink1 there/;  \
140          ls -lR > ../cp_files_dir.gnu;
141
142         @echo;
143         rm -rf cp_tests/there/*;
144
145         @echo;
146         cd cp_tests;                            \
147          ${BCP} afile1 afile2 symlink1 there/;  \
148          ls -lR > ../cp_files_dir.bb;
149
150         @echo;
151         diff -u cp_files_dir.gnu cp_files_dir.bb;
152
153         @echo;
154         rm -rf cp_tests/*;
155
156 check_cp_files_to_dir_w_d:
157         # 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 ------------------------------;
160         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
186 check_cp_files_to_dir_w_p:
187         # 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 ------------------------------;
190         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
218
219 check_cp_files_to_dir_w_p_and_d:
220         @echo; echo Copy a set of files to a directory with -p and -d switches.
221         @echo ------------------------------;
222         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
250 check_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
280 check_cp_dir_to_dir_w_a:
281         @echo; echo Copy a directory into another directory with the -a switch.
282         @echo ------------------------------;
283         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
294         @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
312         @echo;
313         rm -rf cp_tests/dir{a,b};
314
315
316 check_cp_dir_to_dir_w_a_take_two:
317         @echo; echo Copy a directory into another directory with the -a switch;
318         @echo ------------------------------;
319         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;
327
328         @echo;
329         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;
333
334         @echo;
335         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