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