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