report exit code when failing a test
[rsync/rsync.git] / test.sh
1 #!/bin/sh
2
3 # Copyright (C) 1998,1999 Philip Hands <phil@hands.com>
4 #
5 # This program is distributable under the terms of the GNU GPL (see COPYING)
6 #
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.
9 #
10 #
11
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
16   
17   . ${DEBIANTEST_LIB}/functions.sh
18   Debian=1
19 else
20   cat <<EOF
21
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.
25
26 EOF
27   export PATH=.:$PATH
28   runtest() {
29     echo -n "Test $1: "
30     eval "$2"
31   }
32   printmsg() {
33     echo ""
34     echo "**** ${1}^G ****"
35     echo ""  
36   }
37 fi
38
39 TMP=/tmp/rsync-test.$$
40 FROM=${TMP}/from
41 TO=${TMP}/to
42 F1=text1
43 LOG=${TMP}/log
44
45 mkdir $TMP
46 mkdir $FROM
47 mkdir $TO
48
49 # set up test data
50 touch ${FROM}/empty
51 mkdir ${FROM}/emptydir
52 ps ax > ${FROM}/pslist
53 echo -n "This file has no trailing lf" > ${FROM}/nolf
54 ln -s nolf ${FROM}/nolf-symlink
55 cat /etc/inittab /etc/services /etc/resolv.conf > ${FROM}/${F1}
56 mkdir ${FROM}/dir
57 cp ${FROM}/${F1} ${FROM}/dir
58 mkdir ${FROM}/dir/subdir
59 mkdir ${FROM}/dir/subdir/subsubdir
60 ls -ltr /etc > ${FROM}/dir/subdir/subsubdir/etc-ltr-list
61 mkdir ${FROM}/dir/subdir/subsubdir2
62 ls -lt /bin > ${FROM}/dir/subdir/subsubdir2/bin-lt-list
63
64 checkit() {
65   testnum=`expr 0${testnum} + 1`
66   log=${LOG}.${testnum}
67   failed=
68   echo "Running: \"$1\""  >${log}
69   echo "">>${log}
70   eval "$1"  >>${log} 2>&1
71   status=$?
72   if [ $status != 0 ]; then
73     failed="YES";
74   fi
75   echo "-------------">>${log}
76   echo "check how the files compare with diff:">>${log}
77   echo "">>${log}
78   diff -ur $2 $3 >>${log} 2>&1 || failed=YES
79   echo "-------------">>${log}
80   echo "check how the directory listings compare with diff:">>${log}
81   echo "">>${log}
82   ( cd $2 ; ls -laR ) > ${TMP}/ls-from 2>>${log}
83   ( cd $3 ; ls -laR ) > ${TMP}/ls-to  2>>${log}
84   diff -u ${TMP}/ls-from ${TMP}/ls-to >>${log} 2>&1 || failed=YES
85   if [ -z "${failed}" ] ; then
86     test -z "${Debian}" && echo "       done."
87     rm $log
88     return 0
89   else
90     if test -n "${Debian}" ; then
91       cat ${log}
92       rm ${log}
93     else
94       echo "    FAILED (test # ${testnum} status=$status).\a"
95     fi
96     return 1
97   fi
98 }
99
100
101 checkforlogs() {
102   # skip it if we're under debian-test
103   if test -n "${Debian}" ; then return 0 ; fi
104
105   if [ -f $1 ] ; then
106     cat <<EOF
107
108 Failures have occured.
109
110 You can find the output of the tests in these files:
111   $@
112
113 Please hit <RETURN>
114 EOF
115   read input
116   else
117
118     rm -rf ${TMP}
119     echo ""
120     echo "Tests Completed Successfully :-)"
121   fi
122 }
123
124 # Main script starts here
125
126 runtest "basic operation" 'checkit "rsync -av ${FROM}/ ${TO}" ${FROM}/ ${TO}'
127
128 ln ${FROM}/pslist ${FROM}/dir
129 runtest "hard links" 'checkit "rsync -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
130
131 rm ${TO}/${F1}
132 runtest "one file" 'checkit "rsync -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
133
134 echo "extra line" >> ${TO}/${F1}
135 runtest "extra data" 'checkit "rsync -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
136
137 cp ${FROM}/${F1} ${TO}/ThisShouldGo
138 runtest " --delete" 'checkit "rsync --delete -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
139
140 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
141 mkdir -p ${LONGDIR}
142 date > ${LONGDIR}/1
143 ls -la / > ${LONGDIR}/2
144 runtest "long paths" 'checkit "rsync --delete -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
145
146 if type ssh >/dev/null 2>&1; then
147   if [ "`ssh -o'BatchMode yes' localhost echo yes 2>/dev/null`" = "yes" ]; then
148   rm -rf ${TO}
149     runtest "ssh: basic test" 'checkit "rsync -avH -e ssh ${FROM}/ localhost:${TO}" ${FROM}/ ${TO}'
150
151     mv ${TO}/${F1} ${TO}/ThisShouldGo
152     runtest "ssh: renamed file" 'checkit "rsync --delete -avH -e ssh ${FROM}/ localhost:${TO}" ${FROM}/ ${TO}'
153   else
154   printmsg "Skipping SSH tests because ssh conection to localhost not authorised"
155   fi
156 else
157   printmsg "Skipping SSH tests because ssh is not in the path"
158 fi
159
160 rm -rf ${TO}
161 mkdir -p ${FROM}2/dir/subdir
162 cp -a ${FROM}/dir/subdir/subsubdir ${FROM}2/dir/subdir
163 cp ${FROM}/dir/* ${FROM}2/dir 2>/dev/null
164 runtest "excludes" 'checkit "rsync -vv -Hlrt --delete --include /dir/ --include /dir/\* --include /dir/\*/subsubdir  --include /dir/\*/subsubdir/\*\* --exclude \*\* ${FROM}/dir ${TO}" ${FROM}2/ ${TO}'
165 rm -r ${FROM}2
166
167 checkforlogs ${LOG}.?