Cleanup check_logs feature.
[rsync/rsync.git] / testsuite / rsync.fns
1 #! /bin/sh
2
3 # Copyright (C) 2001 by Martin Pool <mbp@samba.org>
4
5 # General-purpose test functions for rsync.
6
7 TMP="$scratchdir"
8 FROM=${TMP}/from
9 TO=${TMP}/to
10 F1=text1
11 LOG=${TMP}/log
12 RSYNC="$rsync_bin"
13
14 runtest() {
15     echo $ECHO_N "Test $1: $ECHO_C"
16     eval "$2"
17 }
18
19 printmsg() {
20     echo "$1"
21 }
22
23 hands_setup() {
24     [ -d $FROM ] || mkdir $FROM
25     [ -d $TO ] || mkdir $TO
26
27     # set up test data
28     touch ${FROM}/empty
29     mkdir ${FROM}/emptydir
30     ps ax > ${FROM}/pslist
31
32     # This might fail on systems that don't have -n
33     echo $ECHO_N "This file has no trailing lf$ECHO_C" > ${FROM}/nolf
34     ln -s nolf ${FROM}/nolf-symlink
35     cat /etc/inittab /etc/services /etc/resolv.conf > ${FROM}/${F1}
36     mkdir ${FROM}/dir
37     cp ${FROM}/${F1} ${FROM}/dir
38     mkdir ${FROM}/dir/subdir
39     mkdir ${FROM}/dir/subdir/subsubdir
40     ls -ltr /etc > ${FROM}/dir/subdir/subsubdir/etc-ltr-list
41     mkdir ${FROM}/dir/subdir/subsubdir2
42     ls -lt /bin > ${FROM}/dir/subdir/subsubdir2/bin-lt-list
43 }
44
45
46 ###########################
47 # Run a test (in '$1') then compare directories $2 and $3 to see if
48 # there are any difference.  If there are, explain them.
49
50 checkit() {
51     log=${LOG}
52     failed=
53     # the log accumulates all output; we only display it if there 
54     # is a problem.
55
56     echo "Running: \"$1\""  >${log}
57     echo "">>${log}
58     eval "$1"  >>${log} 2>&1
59     status=$?
60     if [ $status != 0 ]; then
61         failed="YES";
62     fi
63
64     echo "-------------">>${log}
65     echo "check how the files compare with diff:">>${log}
66     echo "">>${log}
67     diff -ur $2 $3 >>${log} 2>&1 || failed=YES
68     echo "-------------">>${log}
69     echo "check how the directory listings compare with diff:">>${log}
70     echo "">>${log}
71     ( cd $2 ; ls -laR ) > ${TMP}/ls-from 2>>${log}
72     ( cd $3 ; ls -laR ) > ${TMP}/ls-to  2>>${log}
73     diff -u ${TMP}/ls-from ${TMP}/ls-to >>${log} 2>&1 || failed=YES
74     if [ -z "${failed}" ] ; then
75         echo "${ECHO_T} done."
76         rm $log
77         return 0
78     else
79         echo "${ECHO_T} failed!"
80         cat ${log}
81         rm ${log}
82         return 1
83     fi
84 }
85
86
87 # In fact, we need a more general feature of capturing all stderr/log files,
88 # and dumping them if something goes wrong.
89
90 checkforlogs() {
91   # skip it if we're under debian-test
92   if test -n "${Debian}" ; then return 0 ; fi
93
94   if [ -f $1 -a -s $1 ] ; then
95         echo "Failures have occurred.  $1 follows:" >&2
96         cat $1 >&2
97         exit 1
98   fi
99 }
100