Some more updates and such...
[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
18         @echo;
19         @echo "No output from diff means busybox cp is functioning properly.";
20         @echo "Some tests might show timestamp differences that are Ok.";
21
22         @echo;
23         @echo Verify that busybox cp exists;
24         @echo ------------------------------;
25         [ -x ${BCP} ] || exit 0
26
27         @echo;
28         mkdir cp_tests;
29
30         @echo Copy a file to a copy of the file;
31         @echo ------------------------------;
32         cd cp_tests;                            \
33          echo A file > afile;                   \
34          ls -l afile > ../cp_afile_afilecopy.gnu; \
35          ${GCP} afile afilecopy;                \
36          ls -l afile afilecopy >> ../cp_afile_afilecopy.gnu;
37
38         @echo;
39         rm -rf cp_tests/*;
40
41         @echo;
42         cd cp_tests;                            \
43          echo A file > afile;                   \
44          ls -l afile > ../cp_afile_afilecopy.bb; \
45          ${BCP} afile afilecopy;                \
46          ls -l afile afilecopy >> ../cp_afile_afilecopy.bb;
47
48         @echo;
49         @echo Might show timestamp differences.
50         -diff -u cp_afile_afilecopy.gnu cp_afile_afilecopy.bb;
51
52         @echo;
53         rm -rf cp_tests/*;
54
55         @echo; echo Copy a file pointed to by a symlink;
56         @echo ------------------------------;
57         cd cp_tests;                            \
58          mkdir here there;                      \
59          echo A file > afile;                   \
60          cd here;                               \
61           ln -s ../afile .;                     \
62
63         @echo;
64         cd cp_tests;                            \
65          ls -lR . > ../cp_symlink.gnu;          \
66          ${GCP} here/afile there;               \
67          ls -lR . >> ../cp_symlink.gnu;
68
69         @echo;
70         rm -rf cp_tests/there/*;
71
72         sleep 1;
73
74         @echo;
75         cd cp_tests;                            \
76          ls -lR . > ../cp_symlink.bb;           \
77          ${BCP} here/afile there;               \
78          ls -lR . >> ../cp_symlink.bb;
79
80         @echo;
81         @echo Will show timestamp difference.
82         -diff -u cp_symlink.gnu cp_symlink.bb;
83
84         @echo;
85         rm -rf cp_tests/*
86
87         @echo; echo Copy a symlink, useing the -a switch.;
88         @echo ------------------------------;
89         cd cp_tests;                            \
90          echo A file > afile;                   \
91          mkdir here there;                      \
92          cd here;                               \
93           ln -s ../afile .
94
95         cd cp_tests;                            \
96          ls -lR . > ../cp_a_symlink.gnu;        \
97          ${GCP} -a here/afile there;            \
98          ls -lR . >> ../cp_a_symlink.gnu;
99
100         @echo;
101         rm -rf cp_tests/there/*;
102
103         sleep 1;
104
105         @echo;
106         cd cp_tests;                            \
107          echo A file > afile;                   \
108          ls -lR . > ../cp_a_symlink.bb;         \
109          ${BCP} -a here/afile there;            \
110          ls -lR . >> ../cp_a_symlink.bb;
111
112         @echo;
113         diff -u cp_a_symlink.gnu cp_a_symlink.bb;
114
115         @echo;
116         rm -rf cp_tests/*;
117
118         @echo; echo Copy a directory into another directory with the -a switch;
119         @echo ------------------------------;
120         cd cp_tests;                            \
121          mkdir here there;                      \
122          echo A file > here/afile;              \
123          mkdir here/adir;                       \
124          touch here/adir/afileinadir;           \
125          ln -s $$(pwd) here/alink;
126
127         @echo;
128         cd cp_tests;                            \
129          ls -lR . > ../cp_a_dir_dir.gnu;        \
130          ${GCP} -a here/ there/;                \
131          ls -lR . >> ../cp_a_dir_dir.gnu;
132
133         @echo;
134         rm -rf cp_tests/there/*;
135
136         sleep 1;
137
138         @echo;
139         cd cp_tests;                            \
140          ls -lR . > ../cp_a_dir_dir.bb;         \
141          ${BCP} -a here/ there/;                \
142          ls -lR . >> ../cp_a_dir_dir.bb;
143
144         @echo;
145         diff -u cp_a_dir_dir.gnu cp_a_dir_dir.bb;
146
147         @echo;
148         rm -rf cp_tests/*;
149
150         # Copy a set of files to a directory.
151         @echo; echo Copy a set of files to a directory.;
152         @echo ------------------------------;
153         cd cp_tests;                            \
154          echo A file number one > afile1;       \
155          echo A file number two, blah. > afile2; \
156          ln -s afile1 symlink1;                 \
157          mkdir there;
158
159         cd cp_tests;                            \
160          ${GCP} afile1 afile2 symlink1 there/;  \
161          ls -lR > ../cp_files_dir.gnu;
162
163         @echo;
164         rm -rf cp_tests/there/*;
165
166         @echo;
167         cd cp_tests;                            \
168          ${BCP} afile1 afile2 symlink1 there/;  \
169          ls -lR > ../cp_files_dir.bb;
170
171         @echo;
172         diff -u cp_files_dir.gnu cp_files_dir.bb;
173
174         @echo;
175         rm -rf cp_tests/*;
176
177         # Copy a set of files to a directory with the -d switch.
178         @echo; echo Copy a set of files to a directory with the -d switch.;
179         @echo ------------------------------;
180         cd cp_tests;                            \
181          echo A file number one > afile1;       \
182          echo A file number two, blah. > afile2; \
183          ln -s afile1 symlink1;                 \
184          mkdir there1;                          \
185          ${GCP} -d afile1 afile2 symlink1 there1/; \
186          ls -lR > ../cp_d_files_dir.gnu;
187
188         @echo;
189         rm -rf cp_tests/{afile{1,2},symlink1,there1};
190
191         @echo;
192         cd cp_tests;                            \
193          echo A file number one > afile1;       \
194          echo A file number two, blah. > afile2; \
195          ln -s afile1 symlink1;                 \
196          mkdir there1;                          \
197          ${BCP} -d afile1 afile2 symlink1 there1/; \
198          ls -lR > ../cp_d_files_dir.bb;
199
200         @echo;
201         diff -u cp_d_files_dir.gnu cp_d_files_dir.bb;
202
203         @echo;
204         rm -rf cp_tests/{afile{1,2},symlink1,there1};
205
206         # Copy a set of files to a directory with the -p switch.
207         @echo; echo Copy a set of files to a directory with the -p switch.;
208         @echo ------------------------------;
209         cd cp_tests;                            \
210          echo A file number one > afile1;       \
211          echo A file number two, blah. > afile2; \
212          touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
213          ln -s afile1 symlink1;                 \
214          mkdir there1;                          \
215          ${GCP} -p afile1 afile2 symlink1 there1/; \
216          ls -lR > ../cp_p_files_dir.gnu;
217
218         @echo;
219         rm -rf cp_tests/{afile{1,2},symlink1,there1};
220
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          ${BCP} -p afile1 afile2 symlink1 there1/; \
229          ls -lR > ../cp_p_files_dir.bb;
230
231         @echo;
232         diff -u cp_p_files_dir.gnu cp_p_files_dir.bb;
233
234         @echo;
235         rm -rf cp_tests/{afile{1,2},symlink1,there1};
236
237         @echo; echo Copy a set of files to a directory with -p and -d switches.
238         @echo ------------------------------;
239         cd cp_tests;                            \
240          echo A file number one > afile1;       \
241          echo A file number two, blah. > afile2; \
242          touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
243          ln -s afile1 symlink1;                 \
244          mkdir there1;                          \
245          ${GCP} -p -d afile1 afile2 symlink1 there1/; \
246          ls -lR > ../cp_pd_files_dir.gnu;
247
248         @echo;
249         rm -rf cp_tests/{afile{1,2},symlink1,there1};
250
251         @echo;
252         cd cp_tests;                            \
253          echo A file number one > afile1;       \
254          echo A file number two, blah. > afile2; \
255          touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
256          ln -s afile1 symlink1;                 \
257          mkdir there1;                          \
258          ${BCP} -p -d afile1 afile2 symlink1 there1/; \
259          ls -lR > ../cp_pd_files_dir.bb;
260
261         @echo;
262         diff -u cp_pd_files_dir.gnu cp_pd_files_dir.bb;
263
264         @echo;
265         rm -rf cp_tests/{afile{1,2},symlink1,there1};
266
267         @echo; echo Copy a directory into another directory with the -a switch.
268         @echo ------------------------------;
269         cd cp_tests;                            \
270          mkdir dir{a,b};                        \
271          echo A file > dira/afile;              \
272          echo A file in dirb > dirb/afileindirb; \
273          ln -s dira/afile dira/alinktoafile;    \
274          mkdir dira/subdir1;                    \
275          echo Another file > dira/subdir1/anotherfile; \
276          ls -lR . > ../cp_a_dira_dirb.gnu;      \
277          ${GCP} -a dira dirb;                   \
278          ls -lR . >> ../cp_a_dira_dirb.gnu;
279
280         @echo;
281         rm -rf cp_tests/dir{a,b};
282
283         @echo;
284         cd cp_tests;                            \
285          mkdir dir{a,b};                        \
286          echo A file > dira/afile;              \
287          echo A file in dirb > dirb/afileindirb; \
288          ln -s dira/afile dira/alinktoafile;    \
289          mkdir dira/subdir1;                    \
290          echo Another file > dira/subdir1/anotherfile; \
291          ls -lR . > ../cp_a_dira_dirb.bb;       \
292          ${BCP} -a dira dirb;                   \
293          ls -lR . >> ../cp_a_dira_dirb.bb;
294
295         @echo;
296         diff -u cp_a_dira_dirb.gnu cp_a_dira_dirb.bb;
297
298         @echo;
299         rm -rf cp_tests/dir{a,b};
300
301         # Copy a directory to another directory, without the -a switch.
302         @echo; echo Copy a directory to another directory, without the -a switch.
303         @echo ------------------------------;
304         @echo There should be an error message about cannot cp a dir to a subdir of itself.
305         cd cp_tests;                            \
306          touch a b c;                           \
307          mkdir adir;                            \
308          ls -lR . > ../cp_a_star_adir.gnu;      \
309          ${GCP} -a * adir;                      \
310          ls -lR . >> ../cp_a_star_adir.gnu;
311
312         @echo
313         @echo There should be an error message about cannot cp a dir to a subdir of itself.
314         cd cp_tests;                            \
315          rm -rf adir;                           \
316          mkdir adir;                            \
317          ls -lR . > ../cp_a_star_adir.bb;       \
318          ${BCP} -a * adir;                      \
319          ls -lR . >> ../cp_a_star_adir.bb;
320
321         @echo;
322         diff -u cp_a_star_adir.gnu cp_a_star_adir.bb;
323
324         # Done
325         @echo;
326         rm -rf cp_tests;
327         @echo; echo Done.