blob: 33cd876be1248798f2252129b83da3ad584a7630 [file] [log] [blame]
Denys Vlasenkoa40f0622010-01-15 22:05:07 +01001#!/bin/sh
2# Copyright 2010 by Denys Vlasenko
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02003# Licensed under GPLv2, see file LICENSE in this source tree.
Denys Vlasenkoa40f0622010-01-15 22:05:07 +01004
5. ./testing.sh
6
7# Opening quote in "omitting directory 'dir'" message:
8sq='`' # GNU cp: `
9sq="'" # bbox cp: '
10
11rm -rf cp.testdir >/dev/null
12
13mkdir cp.testdir
14mkdir cp.testdir/dir
15> cp.testdir/dir/file
16ln -s file cp.testdir/dir/file_symlink
17
18> cp.testdir/file
19ln -s file cp.testdir/file_symlink
20ln -s dir cp.testdir/dir_symlink
21
22
23# testing "test name" "command" "expected result" "file input" "stdin"
24
25rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
26testing "cp" '\
Denys Vlasenko1e9bc262010-01-16 02:27:31 +010027cd cp.testdir || exit 1; cp * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
28test ! -L file && test -f file || echo BAD: file
29test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
30test ! -L dir && test ! -e dir || echo BAD: dir
31test ! -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink
Denys Vlasenkoa40f0622010-01-15 22:05:07 +010032' "\
33cp: omitting directory ${sq}dir'
34cp: omitting directory ${sq}dir_symlink'
351
36" "" ""
37
38rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
39testing "cp -d" '\
Denys Vlasenko1e9bc262010-01-16 02:27:31 +010040cd cp.testdir || exit 1; cp -d * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
41test ! -L file && test -f file || echo BAD: file
42test -L file_symlink && test -f file_symlink || echo BAD: file_symlink
43test ! -L dir && test ! -e dir || echo BAD: dir
44test -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink
Denys Vlasenkoa40f0622010-01-15 22:05:07 +010045' "\
46cp: omitting directory ${sq}dir'
471
48" "" ""
49
50rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
51testing "cp -P" '\
Denys Vlasenko1e9bc262010-01-16 02:27:31 +010052cd cp.testdir || exit 1; cp -P * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
53test ! -L file && test -f file || echo BAD: file
54test -L file_symlink && test -f file_symlink || echo BAD: file_symlink
55test ! -L dir && test ! -e dir || echo BAD: dir
56test -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink
Denys Vlasenkoa40f0622010-01-15 22:05:07 +010057' "\
58cp: omitting directory ${sq}dir'
591
60" "" ""
61
62rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
63testing "cp -L" '\
Denys Vlasenko1e9bc262010-01-16 02:27:31 +010064cd cp.testdir || exit 1; cp -L * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
65test ! -L file && test -f file || echo BAD: file
66test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
67test ! -L dir && test ! -e dir || echo BAD: dir
68test ! -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink
Denys Vlasenkoa40f0622010-01-15 22:05:07 +010069' "\
70cp: omitting directory ${sq}dir'
71cp: omitting directory ${sq}dir_symlink'
721
73" "" ""
74
75rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
76testing "cp -H" '\
Denys Vlasenko1e9bc262010-01-16 02:27:31 +010077cd cp.testdir || exit 1; cp -H * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
78test ! -L file && test -f file || echo BAD: file
79test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
80test ! -L dir && test ! -e dir || echo BAD: dir
81test ! -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink
Denys Vlasenkoa40f0622010-01-15 22:05:07 +010082' "\
83cp: omitting directory ${sq}dir'
84cp: omitting directory ${sq}dir_symlink'
851
86" "" ""
87
88rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
89testing "cp -R" '\
Denys Vlasenko1e9bc262010-01-16 02:27:31 +010090cd cp.testdir || exit 1; cp -R * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
91test ! -L file && test -f file || echo BAD: file
92test -L file_symlink && test -f file_symlink || echo BAD: file_symlink
93test ! -L dir && test -d dir || echo BAD: dir
94test -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
95test ! -L dir/file && test -f dir/file || echo BAD: dir/file
96test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
Denys Vlasenkoa40f0622010-01-15 22:05:07 +010097' "\
980
99" "" ""
100
101rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
102testing "cp -Rd" '\
Denys Vlasenko1e9bc262010-01-16 02:27:31 +0100103cd cp.testdir || exit 1; cp -Rd * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
104test ! -L file && test -f file || echo BAD: file
105test -L file_symlink && test -f file_symlink || echo BAD: file_symlink
106test ! -L dir && test -d dir || echo BAD: dir
107test -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
108test ! -L dir/file && test -f dir/file || echo BAD: dir/file
109test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
Denys Vlasenkoa40f0622010-01-15 22:05:07 +0100110' "\
1110
112" "" ""
113
114rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
115testing "cp -RP" '\
Denys Vlasenko1e9bc262010-01-16 02:27:31 +0100116cd cp.testdir || exit 1; cp -RP * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
117test ! -L file && test -f file || echo BAD: file
118test -L file_symlink && test -f file_symlink || echo BAD: file_symlink
119test ! -L dir && test -d dir || echo BAD: dir
120test -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
121test ! -L dir/file && test -f dir/file || echo BAD: dir/file
122test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
Denys Vlasenkoa40f0622010-01-15 22:05:07 +0100123' "\
1240
125" "" ""
126
127rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
128testing "cp -RL" '\
Denys Vlasenko1e9bc262010-01-16 02:27:31 +0100129cd cp.testdir || exit 1; cp -RL * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
130test ! -L file && test -f file || echo BAD: file
131test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
132test ! -L dir && test -d dir || echo BAD: dir
133test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
134test ! -L dir/file && test -f dir/file || echo BAD: dir/file
135test ! -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
Denys Vlasenkoa40f0622010-01-15 22:05:07 +0100136' "\
1370
138" "" ""
139
140rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
141# GNU coreutils 7.2 says:
142# cp: will not create hard link `../cp.testdir2/dir_symlink' to directory `../cp.testdir2/dir'
143test x"$SKIP_KNOWN_BUGS" = x"" && \
144testing "cp -RH" '\
Denys Vlasenko1e9bc262010-01-16 02:27:31 +0100145cd cp.testdir || exit 1; cp -RH * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
146test ! -L file && test -f file || echo BAD: file
147test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
148test ! -L dir && test -d dir || echo BAD: dir
149test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
150test ! -L dir/file && test -f dir/file || echo BAD: dir/file
151test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
Denys Vlasenkoa40f0622010-01-15 22:05:07 +0100152' "\
1530
154" "" ""
155
156rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
157# GNU coreutils 7.2 says:
158# cp: will not create hard link `../cp.testdir2/dir_symlink' to directory `../cp.testdir2/dir'
159test x"$SKIP_KNOWN_BUGS" = x"" && \
160testing "cp -RHP" '\
Denys Vlasenko1e9bc262010-01-16 02:27:31 +0100161cd cp.testdir || exit 1; cp -RHP * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
162test ! -L file && test -f file || echo BAD: file
163test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
164test ! -L dir && test -d dir || echo BAD: dir
165test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
166test ! -L dir/file && test -f dir/file || echo BAD: dir/file
167test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
Denys Vlasenkoa40f0622010-01-15 22:05:07 +0100168' "\
1690
170" "" ""
171
172rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
173testing "cp -RHL" '\
Denys Vlasenko1e9bc262010-01-16 02:27:31 +0100174cd cp.testdir || exit 1; cp -RHL * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
175test ! -L file && test -f file || echo BAD: file
176test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
177test ! -L dir && test -d dir || echo BAD: dir
178test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
179test ! -L dir/file && test -f dir/file || echo BAD: dir/file
180test ! -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
Denys Vlasenkoa40f0622010-01-15 22:05:07 +0100181' "\
1820
183" "" ""
184
185rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1
186# Wow! "cp -RLH" is not the same as "cp -RHL" (prev test)!
187# GNU coreutils 7.2 says:
188# cp: will not create hard link `../cp.testdir2/dir_symlink' to directory `../cp.testdir2/dir'
189test x"$SKIP_KNOWN_BUGS" = x"" && \
190testing "cp -RLH" '\
Denys Vlasenko1e9bc262010-01-16 02:27:31 +0100191cd cp.testdir || exit 1; cp -RLH * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1
192test ! -L file && test -f file || echo BAD: file
193test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink
194test ! -L dir && test -d dir || echo BAD: dir
195test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink
196test ! -L dir/file && test -f dir/file || echo BAD: dir/file
197test ! -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink
Denys Vlasenkoa40f0622010-01-15 22:05:07 +0100198' "\
1990
200" "" ""
201
202
203# Clean up
204rm -rf cp.testdir cp.testdir2 2>/dev/null
205
206exit $FAILCOUNT