summaryrefslogtreecommitdiffhomepage
path: root/tests/cp_tests.mk
blob: 1dc4c5ac46e3eb20f92ee285917752500370be82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# cp_tests.mk - Set of test cases for busybox cp
# -------------
# Copyright (C) 2000 Karl M. Hegbloom <karlheg@debian.org> GPL
#

# GNU `cp'
GCP = /bin/cp
# BusyBox `cp'
BCP = $(shell pwd)/cp

all:: cp_tests
clean:: cp_clean

cp_clean:
	- rm -rf cp_tests cp_*.{gnu,bb} cp

cp_tests: cp_clean cp check_exists check_simple_cp check_cp_symlnk \
	check_cp_symlink_w_a check_cp_files_to_dir check_cp_files_to_dir_w_d \
	check_cp_files_to_dir_w_p check_cp_files_to_dir_w_p_and_d \ 
	check_cp_dir_to_dir_wo_a check_cp_dir_to_dir_w_a \
	check_cp_dir_to_dir_w_a_take_two

check_exists:
	@echo;
	@echo "No output from diff means busybox cp is functioning properly.";
	@echo "Some tests might show timestamp differences that are Ok.";

	@echo;
	@echo Verify that busybox cp exists;
	@echo ------------------------------;
	[ -x ${BCP} ] || exit 0

	@echo;
	mkdir cp_tests;

check_simple_cp:
	@echo Copy a file to a copy of the file;
	@echo ------------------------------;
	cd cp_tests;				\
	 echo A file > afile;			\
	 ls -l afile > ../cp_afile_afilecopy.gnu; \
	 ${GCP} afile afilecopy;		\
	 ls -l afile afilecopy >> ../cp_afile_afilecopy.gnu;

	@echo;
	rm -rf cp_tests/*;

	@echo;
	cd cp_tests;				\
	 echo A file > afile;			\
	 ls -l afile > ../cp_afile_afilecopy.bb; \
	 ${BCP} afile afilecopy;		\
	 ls -l afile afilecopy >> ../cp_afile_afilecopy.bb;

	@echo;
	@echo Might show timestamp differences.
	-diff -u cp_afile_afilecopy.gnu cp_afile_afilecopy.bb;

	@echo;
	rm -rf cp_tests/*;

check_cp_symlnk:
	@echo; echo Copy a file pointed to by a symlink;
	@echo ------------------------------;
	cd cp_tests;				\
	 mkdir here there;			\
	 echo A file > afile;			\
	 cd here;				\
	  ln -s ../afile .;			\

	@echo;
	cd cp_tests;				\
	 ls -lR . > ../cp_symlink.gnu;		\
	 ${GCP} here/afile there;		\
	 ls -lR . >> ../cp_symlink.gnu;

	@echo;
	rm -rf cp_tests/there/*;

	sleep 1;

	@echo;
	cd cp_tests;				\
	 ls -lR . > ../cp_symlink.bb;		\
	 ${BCP} here/afile there;		\
	 ls -lR . >> ../cp_symlink.bb;

	@echo;
	@echo Will show timestamp difference.
	-diff -u cp_symlink.gnu cp_symlink.bb;

	@echo;
	rm -rf cp_tests/*

check_cp_symlink_w_a:
	@echo; echo Copy a symlink, useing the -a switch.;
	@echo ------------------------------;
	cd cp_tests;				\
	 echo A file > afile;			\
	 mkdir here there;			\
	 cd here;				\
	  ln -s ../afile .

	cd cp_tests;				\
	 ls -lR . > ../cp_a_symlink.gnu;	\
	 ${GCP} -a here/afile there;		\
	 ls -lR . >> ../cp_a_symlink.gnu;

	@echo;
	rm -rf cp_tests/there/*;

	sleep 1;

	@echo;
	cd cp_tests;				\
	 echo A file > afile;			\
	 ls -lR . > ../cp_a_symlink.bb;		\
	 ${BCP} -a here/afile there;		\
	 ls -lR . >> ../cp_a_symlink.bb;

	@echo;
	diff -u cp_a_symlink.gnu cp_a_symlink.bb;

	@echo;
	rm -rf cp_tests/*;


check_cp_files_to_dir:
	# Copy a set of files to a directory.
	@echo; echo Copy a set of files to a directory.;
	@echo ------------------------------;
	cd cp_tests;				\
	 echo A file number one > afile1;	\
	 echo A file number two, blah. > afile2; \
	 ln -s afile1 symlink1;			\
	 mkdir there;

	cd cp_tests;				\
	 ${GCP} afile1 afile2 symlink1 there/;	\
	 ls -lR > ../cp_files_dir.gnu;

	@echo;
	rm -rf cp_tests/there/*;

	@echo;
	cd cp_tests;				\
	 ${BCP} afile1 afile2 symlink1 there/;	\
	 ls -lR > ../cp_files_dir.bb;

	@echo;
	diff -u cp_files_dir.gnu cp_files_dir.bb;

	@echo;
	rm -rf cp_tests/*;

check_cp_files_to_dir_w_d:
	# Copy a set of files to a directory with the -d switch.
	@echo; echo Copy a set of files to a directory with the -d switch.;
	@echo ------------------------------;
	cd cp_tests;				\
	 echo A file number one > afile1;	\
	 echo A file number two, blah. > afile2; \
	 ln -s afile1 symlink1;			\
	 mkdir there1;				\
	 ${GCP} -d afile1 afile2 symlink1 there1/; \
	 ls -lR > ../cp_d_files_dir.gnu;

	@echo;
	rm -rf cp_tests/{afile{1,2},symlink1,there1};

	@echo;
	cd cp_tests;				\
	 echo A file number one > afile1;	\
	 echo A file number two, blah. > afile2; \
	 ln -s afile1 symlink1;			\
	 mkdir there1;				\
	 ${BCP} -d afile1 afile2 symlink1 there1/; \
	 ls -lR > ../cp_d_files_dir.bb;

	@echo;
	diff -u cp_d_files_dir.gnu cp_d_files_dir.bb;

	@echo;
	rm -rf cp_tests/{afile{1,2},symlink1,there1};

check_cp_files_to_dir_w_p:
	# Copy a set of files to a directory with the -p switch.
	@echo; echo Copy a set of files to a directory with the -p switch.;
	@echo ------------------------------;
	cd cp_tests;				\
	 echo A file number one > afile1;	\
	 echo A file number two, blah. > afile2; \
	 touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
	 ln -s afile1 symlink1;			\
	 mkdir there1;				\
	 ${GCP} -p afile1 afile2 symlink1 there1/; \
	 ls -lR > ../cp_p_files_dir.gnu;

	@echo;
	rm -rf cp_tests/{afile{1,2},symlink1,there1};

	@echo;
	cd cp_tests;				\
	 echo A file number one > afile1;	\
	 echo A file number two, blah. > afile2; \
	 touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
	 ln -s afile1 symlink1;			\
	 mkdir there1;				\
	 ${BCP} -p afile1 afile2 symlink1 there1/; \
	 ls -lR > ../cp_p_files_dir.bb;

	@echo;
	diff -u cp_p_files_dir.gnu cp_p_files_dir.bb;

	@echo;
	rm -rf cp_tests/{afile{1,2},symlink1,there1};


check_cp_files_to_dir_w_p_and_d:
	@echo; echo Copy a set of files to a directory with -p and -d switches.
	@echo ------------------------------;
	cd cp_tests;				\
	 echo A file number one > afile1;	\
	 echo A file number two, blah. > afile2; \
	 touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
	 ln -s afile1 symlink1;			\
	 mkdir there1;				\
	 ${GCP} -p -d afile1 afile2 symlink1 there1/; \
	 ls -lR > ../cp_pd_files_dir.gnu;

	@echo;
	rm -rf cp_tests/{afile{1,2},symlink1,there1};

	@echo;
	cd cp_tests;				\
	 echo A file number one > afile1;	\
	 echo A file number two, blah. > afile2; \
	 touch --date='Sat Jan 29 21:24:08 PST 2000' afile1; \
	 ln -s afile1 symlink1;			\
	 mkdir there1;				\
	 ${BCP} -p -d afile1 afile2 symlink1 there1/; \
	 ls -lR > ../cp_pd_files_dir.bb;

	@echo;
	diff -u cp_pd_files_dir.gnu cp_pd_files_dir.bb;

	@echo;
	rm -rf cp_tests/{afile{1,2},symlink1,there1};

check_cp_dir_to_dir_wo_a:
	# Copy a directory to another directory, without the -a switch.
	@echo; echo Copy a directory to another directory, without the -a switch.
	@echo ------------------------------;
	@echo There should be an error message about cannot cp a dir to a subdir of itself.
	cd cp_tests;				\
	 touch a b c;				\
	 mkdir adir;				\
	 ls -lR . > ../cp_a_star_adir.gnu;	\
	 ${GCP} -a * adir;			\
	 ls -lR . >> ../cp_a_star_adir.gnu;

	@echo
	@echo There should be an error message about cannot cp a dir to a subdir of itself.
	cd cp_tests;				\
	 rm -rf adir;				\
	 mkdir adir;				\
	 ls -lR . > ../cp_a_star_adir.bb;	\
	 ${BCP} -a * adir;			\
	 ls -lR . >> ../cp_a_star_adir.bb;

	@echo;
	diff -u cp_a_star_adir.gnu cp_a_star_adir.bb;

	# Done
	@echo;
	rm -rf cp_tests;
	@echo; echo Done.


check_cp_dir_to_dir_w_a:
	@echo; echo Copy a directory into another directory with the -a switch.
	@echo ------------------------------;
	cd cp_tests;				\
	 mkdir dir{a,b};			\
	 echo A file > dira/afile;		\
	 echo A file in dirb > dirb/afileindirb; \
	 ln -s dira/afile dira/alinktoafile;	\
	 mkdir dira/subdir1;			\
	 echo Another file > dira/subdir1/anotherfile; \
	 ls -lR . > ../cp_a_dira_dirb.gnu;	\
	 ${GCP} -a dira dirb;			\
	 ls -lR . >> ../cp_a_dira_dirb.gnu;

	@echo;
	rm -rf cp_tests/dir{a,b};

	@echo;
	cd cp_tests;				\
	 mkdir dir{a,b};			\
	 echo A file > dira/afile;		\
	 echo A file in dirb > dirb/afileindirb; \
	 ln -s dira/afile dira/alinktoafile;	\
	 mkdir dira/subdir1;			\
	 echo Another file > dira/subdir1/anotherfile; \
	 ls -lR . > ../cp_a_dira_dirb.bb;	\
	 ${BCP} -a dira dirb;			\
	 ls -lR . >> ../cp_a_dira_dirb.bb;

	@echo;
	diff -u cp_a_dira_dirb.gnu cp_a_dira_dirb.bb;

	@echo;
	rm -rf cp_tests/dir{a,b};


check_cp_dir_to_dir_w_a_take_two:
	@echo; echo Copy a directory into another directory with the -a switch;
	@echo ------------------------------;
	mkdir -p cp_tests/gnu;			\
	 mkdir -p cp_tests/bb;			\
	 cd cp_tests;				\
	 mkdir here there;			\
	 echo A file > here/afile;		\
	 mkdir here/adir;			\
	 touch here/adir/afileinadir;		\
	 ln -s $$(pwd) here/alink;

	@echo;
	cd cp_tests/gnu;			\
	 ls -lR . > ../../cp_a_dir_dir.gnu;	\
	 ${GCP} -a here/ there/;		\
	 ls -lR . >> ../../cp_a_dir_dir.gnu;

	@echo;
	rm -rf cp_tests/there/*;

	sleep 1;

	@echo;
	cd cp_tests/bb;				\
	 ls -lR . > ../../cp_a_dir_dir.bb;		\
	 ${BCP} -a here/ there/;		\
	 ls -lR . >> ../../cp_a_dir_dir.bb;

	@echo;
	echo "Erik 1"
	diff -u cp_a_dir_dir.gnu cp_a_dir_dir.bb;
	echo "Erik 2"

	@echo;
	echo "Erik 3"
	rm -rf cp_tests/*;