Upgrade from including popt1.2 to a version of popt1.5 trimmed down to
[rsync.git] / test.sh
blobe9c953aa16b084820b79fedb41afec5276145119
1 #!/bin/sh
3 # Copyright (C) 1998,1999 Philip Hands <phil@hands.com>
5 # This program is distributable under the terms of the GNU GPL (see COPYING)
7 # This is a simple test script that tests a few rsync
8 # features to make sure I haven't broken them before a release.
12 # check if we are running under debian-test, and change behaviour to suit
13 if test -n "${DEBIANTEST_LIB}" ; then
14 # make sure rsync is installed
15 test -e /usr/bin/rsync || exit 0
17 . ${DEBIANTEST_LIB}/functions.sh
18 Debian=1
19 else
20 cat <<EOF
22 This set of tests is not completely portable. It is intended for developers
23 not for end users. You may experience failures on some platforms that
24 do not indicate a problem with rsync.
26 EOF
28 RSYNC=`pwd`/rsync
30 runtest() {
31 echo -n "Test $1: "
32 eval "$2"
34 printmsg() {
35 echo ""
36 echo "**** ${1}^G ****"
37 echo ""
41 TMP=/tmp/rsync-test.$$
42 FROM=${TMP}/from
43 TO=${TMP}/to
44 F1=text1
45 LOG=${TMP}/log
47 mkdir $TMP
48 mkdir $FROM
49 mkdir $TO
51 # set up test data
52 touch ${FROM}/empty
53 mkdir ${FROM}/emptydir
54 ps ax > ${FROM}/pslist
55 echo -n "This file has no trailing lf" > ${FROM}/nolf
56 ln -s nolf ${FROM}/nolf-symlink
57 cat /etc/inittab /etc/services /etc/resolv.conf > ${FROM}/${F1}
58 mkdir ${FROM}/dir
59 cp ${FROM}/${F1} ${FROM}/dir
60 mkdir ${FROM}/dir/subdir
61 mkdir ${FROM}/dir/subdir/subsubdir
62 ls -ltr /etc > ${FROM}/dir/subdir/subsubdir/etc-ltr-list
63 mkdir ${FROM}/dir/subdir/subsubdir2
64 ls -lt /bin > ${FROM}/dir/subdir/subsubdir2/bin-lt-list
66 checkit() {
67 testnum=`expr 0${testnum} + 1`
68 log=${LOG}.${testnum}
69 failed=
70 echo "Running: \"$1\"" >${log}
71 echo "">>${log}
72 eval "$1" >>${log} 2>&1
73 status=$?
74 if [ $status != 0 ]; then
75 failed="YES";
77 echo "-------------">>${log}
78 echo "check how the files compare with diff:">>${log}
79 echo "">>${log}
80 diff -ur $2 $3 >>${log} 2>&1 || failed=YES
81 echo "-------------">>${log}
82 echo "check how the directory listings compare with diff:">>${log}
83 echo "">>${log}
84 ( cd $2 ; ls -laR ) > ${TMP}/ls-from 2>>${log}
85 ( cd $3 ; ls -laR ) > ${TMP}/ls-to 2>>${log}
86 diff -u ${TMP}/ls-from ${TMP}/ls-to >>${log} 2>&1 || failed=YES
87 if [ -z "${failed}" ] ; then
88 test -z "${Debian}" && echo " done."
89 rm $log
90 return 0
91 else
92 if test -n "${Debian}" ; then
93 cat ${log}
94 rm ${log}
95 else
96 echo " FAILED (test # ${testnum} status=$status).\a"
98 return 1
103 checkforlogs() {
104 # skip it if we're under debian-test
105 if test -n "${Debian}" ; then return 0 ; fi
107 if [ -f $1 ] ; then
108 cat <<EOF
110 Failures have occured.
112 You can find the output of the tests in these files:
115 Please hit <RETURN>
117 read input
118 else
120 rm -rf ${TMP}
121 echo ""
122 echo "Tests Completed Successfully :-)"
126 # Main script starts here
128 runtest "basic operation" 'checkit "$RSYNC -av ${FROM}/ ${TO}" ${FROM}/ ${TO}'
130 ln ${FROM}/pslist ${FROM}/dir
131 runtest "hard links" 'checkit "$RSYNC -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
133 rm ${TO}/${F1}
134 runtest "one file" 'checkit "$RSYNC -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
136 echo "extra line" >> ${TO}/${F1}
137 runtest "extra data" 'checkit "$RSYNC -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
139 cp ${FROM}/${F1} ${TO}/ThisShouldGo
140 runtest " --delete" 'checkit "$RSYNC --delete -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
142 LONGDIR=${FROM}/This-is-a-directory-with-a-stupidly-long-name-created-in-an-attempt-to-provoke-an-error-found-in-2.0.11-that-should-hopefully-never-appear-again-if-this-test-does-its-job/This-is-a-directory-with-a-stupidly-long-name-created-in-an-attempt-to-provoke-an-error-found-in-2.0.11-that-should-hopefully-never-appear-again-if-this-test-does-its-job/This-is-a-directory-with-a-stupidly-long-name-created-in-an-attempt-to-provoke-an-error-found-in-2.0.11-that-should-hopefully-never-appear-again-if-this-test-does-its-job
143 mkdir -p ${LONGDIR}
144 date > ${LONGDIR}/1
145 ls -la / > ${LONGDIR}/2
146 runtest "long paths" 'checkit "$RSYNC --delete -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
148 if type ssh >/dev/null 2>&1; then
149 if [ "`ssh -o'BatchMode yes' localhost echo yes 2>/dev/null`" = "yes" ]; then
150 rm -rf ${TO}
151 runtest "ssh: basic test" 'checkit "$RSYNC -avH -e ssh --rsync-path=$RSYNC ${FROM}/ localhost:${TO}" ${FROM}/ ${TO}'
153 mv ${TO}/${F1} ${TO}/ThisShouldGo
154 runtest "ssh: renamed file" 'checkit "$RSYNC --delete -avH -e ssh --rsync-path=$RSYNC ${FROM}/ localhost:${TO}" ${FROM}/ ${TO}'
155 else
156 printmsg "Skipping SSH tests because ssh conection to localhost not authorised"
158 else
159 printmsg "Skipping SSH tests because ssh is not in the path"
162 rm -rf ${TO}
163 mkdir -p ${FROM}2/dir/subdir
164 cp -a ${FROM}/dir/subdir/subsubdir ${FROM}2/dir/subdir
165 cp ${FROM}/dir/* ${FROM}2/dir 2>/dev/null
166 runtest "excludes" 'checkit "$RSYNC -vv -Hlrt --delete --include /dir/ --include /dir/\* --include /dir/\*/subsubdir --include /dir/\*/subsubdir/\*\* --exclude \*\* ${FROM}/dir ${TO}" ${FROM}2/ ${TO}'
167 rm -r ${FROM}2
169 checkforlogs ${LOG}.?