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