home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / rsync221.zip / test.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1999-03-04  |  4KB  |  131 lines

  1. #!/bin/sh
  2.  
  3. #
  4. # Copyright (C) 1998 Philip Hands <http://www.hands.com/~phil/>
  5. #
  6. # This program is distributable under the terms of the GNU GPL (see COPYING)
  7. #
  8. # This is a simple test script that tests a few rsync
  9. # features to make sure I haven't broken them before a release.
  10. #
  11. #
  12.  
  13. cat <<EOF
  14.  
  15. This set of tests is not completely portable. It is intended for developers
  16. not for end users. You may experience failures on some platforms that
  17. do not indicate a problem with rsync.
  18.  
  19. EOF
  20.  
  21. export PATH=.:$PATH
  22. TMP=/tmp/rsync-test.$$
  23. FROM=${TMP}/from
  24. TO=${TMP}/to
  25. F1=text1
  26. LOG=${TMP}/log
  27.  
  28. mkdir $TMP
  29. mkdir $FROM
  30. mkdir $TO
  31.  
  32. # set up test data
  33. touch ${FROM}/empty
  34. mkdir ${FROM}/emptydir
  35. ps ax > ${FROM}/pslist
  36. echo -n "This file has no trailing lf" > ${FROM}/nolf
  37. ln -s nolf ${FROM}/nolf-symlink
  38. cat /etc/inittab /etc/services /etc/resolv.conf > ${FROM}/${F1}
  39. mkdir ${FROM}/dir
  40. cp ${FROM}/${F1} ${FROM}/dir
  41.  
  42. checkit() {
  43.   echo -n "Test $4: $5:"
  44.   log=${LOG}.$4
  45.   failed=
  46.   echo "Running: \"$1\""  >${log}
  47.   echo "">>${log}
  48.   eval "$1 || failed=YES"  >>${log} 2>&1
  49.  
  50.   echo "-------------">>${log}
  51.   echo "check how the files compare with diff:">>${log}
  52.   echo "">>${log}
  53.   diff -ur $2 $3 >>${log} || failed=YES
  54.   echo "-------------">>${log}
  55.   echo "check how the directory listings compare with diff:">>${log}
  56.   echo "">>${log}
  57.   ls -la $2 > ${TMP}/ls-from
  58.   ls -la $3 > ${TMP}/ls-to
  59.   diff -u ${TMP}/ls-from ${TMP}/ls-to >>${log} || failed=YES
  60.   if [ -z "${failed}" ] ; then
  61.     echo "    done."
  62.     rm $log
  63.   else
  64.     echo "    FAILED."
  65.   fi
  66. }
  67.  
  68. checkforlogs() {
  69.   if [ -f $1 ] ; then
  70.     cat <<EOF
  71.  
  72. Failures have occured.
  73.  
  74. You can find the output of the tests in these files:
  75.   $@
  76.  
  77. Please hit <RETURN>
  78. EOF
  79.   read input
  80.   else
  81.  
  82.     rm -rf ${TMP}
  83.     echo ""
  84.     echo "Tests Completed Successfully :-)"
  85.   fi
  86. }
  87.  
  88. # Main script starts here
  89.  
  90. checkit "rsync -av ${FROM}/ ${TO}" ${FROM}/ ${TO} \
  91.   1 "basic operation"
  92.  
  93. ln ${FROM}/pslist ${FROM}/dir
  94. checkit "rsync -avH ${FROM}/ ${TO}" ${FROM}/ ${TO} \
  95.   2 "hard links"
  96.  
  97. rm ${TO}/${F1}
  98. checkit "rsync -avH ${FROM}/ ${TO}" ${FROM}/ ${TO} \
  99.   3 "one file"
  100.  
  101. echo "extra line" >> ${TO}/${F1}
  102. checkit "rsync -avH ${FROM}/ ${TO}" ${FROM}/ ${TO} \
  103.   4 "extra data"
  104.  
  105. cp ${FROM}/${F1} ${TO}/ThisShouldGo
  106. checkit "rsync --delete -avH ${FROM}/ ${TO}" ${FROM}/ ${TO} \
  107.   5 " --delete"
  108.  
  109. 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
  110. mkdir -p ${LONGDIR}
  111. date > ${LONGDIR}/1
  112. ls -la / > ${LONGDIR}/2
  113. checkit "rsync --delete -avH ${FROM}/ ${TO}" ${FROM}/ ${TO} \
  114.   6 "long paths"
  115.  
  116. if type ssh >/dev/null ; then
  117. rm -rf ${TO}
  118.   checkit "rsync -avH -e ssh ${FROM}/ localhost:${TO}" ${FROM}/ ${TO} \
  119.     7 "ssh: basic test"
  120.  
  121.   mv ${TO}/${F1} ${TO}/ThisShouldGo
  122.   checkit "rsync --delete -avH -e ssh ${FROM}/ localhost:${TO}" ${FROM}/ ${TO}\
  123.     8 "ssh: renamed file"
  124. else
  125.   echo ""
  126.   echo "**** Skipping SSH tests because ssh is not in the path ****"
  127.   echo ""
  128. fi
  129.  
  130. checkforlogs ${LOG}.?
  131.