damn.
[rsync/rsync.git] / test.sh
CommitLineData
d3394de1 1#!/bin/sh
ddddf27b 2
c8313794 3# Copyright (C) 1998,1999 Philip Hands <phil@hands.com>
ddddf27b
AT
4#
5# This program is distributable under the terms of the GNU GPL (see COPYING)
6#
5806b30f 7# This is a simple test script that tests a few rsync
ddddf27b
AT
8# features to make sure I haven't broken them before a release.
9#
10#
5806b30f 11
c8313794
AT
12# check if we are running under debian-test, and change behaviour to suit
13if 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
19else
20 cat <<EOF
8c3b0473
AT
21
22This set of tests is not completely portable. It is intended for developers
23not for end users. You may experience failures on some platforms that
24do not indicate a problem with rsync.
25
26EOF
c8313794
AT
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 }
37fi
8c3b0473 38
5806b30f 39TMP=/tmp/rsync-test.$$
ddddf27b
AT
40FROM=${TMP}/from
41TO=${TMP}/to
42F1=text1
43LOG=${TMP}/log
5806b30f
AT
44
45mkdir $TMP
ddddf27b
AT
46mkdir $FROM
47mkdir $TO
48
49# set up test data
50touch ${FROM}/empty
51mkdir ${FROM}/emptydir
52ps ax > ${FROM}/pslist
53echo -n "This file has no trailing lf" > ${FROM}/nolf
54ln -s nolf ${FROM}/nolf-symlink
55cat /etc/inittab /etc/services /etc/resolv.conf > ${FROM}/${F1}
56mkdir ${FROM}/dir
57cp ${FROM}/${F1} ${FROM}/dir
c8313794
AT
58mkdir ${FROM}/dir/subdir
59mkdir ${FROM}/dir/subdir/subsubdir
60ls -ltr /etc > ${FROM}/dir/subdir/subsubdir/etc-ltr-list
61mkdir ${FROM}/dir/subdir/subsubdir2
62ls -lt /bin > ${FROM}/dir/subdir/subsubdir2/bin-lt-list
ddddf27b
AT
63
64checkit() {
c8313794
AT
65 testnum=`expr 0${testnum} + 1`
66 log=${LOG}.${testnum}
ddddf27b
AT
67 failed=
68 echo "Running: \"$1\"" >${log}
69 echo "">>${log}
bd36966b
AT
70 eval "$1" >>${log} 2>&1
71 status=$?
72 if [ $status != 0 ]; then
73 failed="YES";
74 fi
ddddf27b
AT
75 echo "-------------">>${log}
76 echo "check how the files compare with diff:">>${log}
77 echo "">>${log}
c8313794 78 diff -ur $2 $3 >>${log} 2>&1 || failed=YES
ddddf27b
AT
79 echo "-------------">>${log}
80 echo "check how the directory listings compare with diff:">>${log}
81 echo "">>${log}
c8313794
AT
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
ddddf27b 85 if [ -z "${failed}" ] ; then
c8313794 86 test -z "${Debian}" && echo " done."
ddddf27b 87 rm $log
c8313794 88 return 0
ddddf27b 89 else
c8313794
AT
90 if test -n "${Debian}" ; then
91 cat ${log}
92 rm ${log}
93 else
bd36966b 94 echo " FAILED (test # ${testnum} status=$status).\a"
c8313794
AT
95 fi
96 return 1
ddddf27b
AT
97 fi
98}
99
c8313794 100
ddddf27b 101checkforlogs() {
c8313794
AT
102 # skip it if we're under debian-test
103 if test -n "${Debian}" ; then return 0 ; fi
104
ddddf27b
AT
105 if [ -f $1 ] ; then
106 cat <<EOF
107
108Failures have occured.
109
110You can find the output of the tests in these files:
111 $@
112
113Please hit <RETURN>
114EOF
115 read input
116 else
5806b30f 117
ddddf27b
AT
118 rm -rf ${TMP}
119 echo ""
120 echo "Tests Completed Successfully :-)"
121 fi
5806b30f
AT
122}
123
ddddf27b
AT
124# Main script starts here
125
c8313794 126runtest "basic operation" 'checkit "rsync -av ${FROM}/ ${TO}" ${FROM}/ ${TO}'
ddddf27b
AT
127
128ln ${FROM}/pslist ${FROM}/dir
c8313794 129runtest "hard links" 'checkit "rsync -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
ddddf27b
AT
130
131rm ${TO}/${F1}
c8313794 132runtest "one file" 'checkit "rsync -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
ddddf27b
AT
133
134echo "extra line" >> ${TO}/${F1}
c8313794 135runtest "extra data" 'checkit "rsync -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
ddddf27b
AT
136
137cp ${FROM}/${F1} ${TO}/ThisShouldGo
c8313794 138runtest " --delete" 'checkit "rsync --delete -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
ddddf27b 139
35f69d8a
AT
140LONGDIR=${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
141mkdir -p ${LONGDIR}
142date > ${LONGDIR}/1
143ls -la / > ${LONGDIR}/2
c8313794 144runtest "long paths" 'checkit "rsync --delete -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
35f69d8a 145
c8313794
AT
146if 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}'
ddddf27b 150
c8313794
AT
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
ddddf27b 156else
c8313794 157 printmsg "Skipping SSH tests because ssh is not in the path"
ddddf27b
AT
158fi
159
c8313794
AT
160rm -rf ${TO}
161mkdir -p ${FROM}2/dir/subdir
162cp -a ${FROM}/dir/subdir/subsubdir ${FROM}2/dir/subdir
a2edb26c 163cp ${FROM}/dir/* ${FROM}2/dir 2>/dev/null
c8313794
AT
164runtest "excludes" 'checkit "rsync -vv -Hlrt --delete --include /dir/ --include /dir/\* --include /dir/\*/subsubdir --include /dir/\*/subsubdir/\*\* --exclude \*\* ${FROM}/dir ${TO}" ${FROM}2/ ${TO}'
165rm -r ${FROM}2
166
ddddf27b 167checkforlogs ${LOG}.?