Commit | Line | Data |
---|---|---|
d820215b MP |
1 | #! /bin/sh |
2 | ||
3 | # Copyright (C) 2001 by Martin Pool <mbp@samba.org> | |
4 | ||
5 | # General-purpose test functions for rsync. | |
3a4c683f MP |
6 | |
7 | TMP="$scratchdir" | |
8 | FROM=${TMP}/from | |
9 | TO=${TMP}/to | |
10 | F1=text1 | |
11 | LOG=${TMP}/log | |
3fedd74b | 12 | RSYNC="$rsync_bin" |
3a4c683f MP |
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 | |
e8ca5901 MP |
30 | |
31 | # a few hundred lines of test | |
32 | ls -lR / | head -200 > ${FROM}/filelist | |
3a4c683f MP |
33 | |
34 | # This might fail on systems that don't have -n | |
35 | echo $ECHO_N "This file has no trailing lf$ECHO_C" > ${FROM}/nolf | |
36 | ln -s nolf ${FROM}/nolf-symlink | |
751411c4 | 37 | cat $srcdir/*.c | head -2000 > ${FROM}/${F1} |
3a4c683f MP |
38 | mkdir ${FROM}/dir |
39 | cp ${FROM}/${F1} ${FROM}/dir | |
40 | mkdir ${FROM}/dir/subdir | |
41 | mkdir ${FROM}/dir/subdir/subsubdir | |
42 | ls -ltr /etc > ${FROM}/dir/subdir/subsubdir/etc-ltr-list | |
43 | mkdir ${FROM}/dir/subdir/subsubdir2 | |
44 | ls -lt /bin > ${FROM}/dir/subdir/subsubdir2/bin-lt-list | |
45 | } | |
3fedd74b MP |
46 | |
47 | ||
48 | ########################### | |
49 | # Run a test (in '$1') then compare directories $2 and $3 to see if | |
50 | # there are any difference. If there are, explain them. | |
51 | ||
52 | checkit() { | |
53 | log=${LOG} | |
54 | failed= | |
55 | # the log accumulates all output; we only display it if there | |
56 | # is a problem. | |
57 | ||
58 | echo "Running: \"$1\"" >${log} | |
59 | echo "">>${log} | |
60 | eval "$1" >>${log} 2>&1 | |
61 | status=$? | |
62 | if [ $status != 0 ]; then | |
63 | failed="YES"; | |
64 | fi | |
65 | ||
66 | echo "-------------">>${log} | |
67 | echo "check how the files compare with diff:">>${log} | |
68 | echo "">>${log} | |
37c3cf43 | 69 | diff -cr $2 $3 >>${log} 2>&1 || failed=YES |
3fedd74b MP |
70 | echo "-------------">>${log} |
71 | echo "check how the directory listings compare with diff:">>${log} | |
72 | echo "">>${log} | |
73 | ( cd $2 ; ls -laR ) > ${TMP}/ls-from 2>>${log} | |
74 | ( cd $3 ; ls -laR ) > ${TMP}/ls-to 2>>${log} | |
37c3cf43 | 75 | diff -c ${TMP}/ls-from ${TMP}/ls-to >>${log} 2>&1 || failed=YES |
3fedd74b MP |
76 | if [ -z "${failed}" ] ; then |
77 | echo "${ECHO_T} done." | |
78 | rm $log | |
79 | return 0 | |
80 | else | |
81 | echo "${ECHO_T} failed!" | |
82 | cat ${log} | |
83 | rm ${log} | |
84 | return 1 | |
85 | fi | |
86 | } | |
87 | ||
863dff51 MP |
88 | |
89 | # In fact, we need a more general feature of capturing all stderr/log files, | |
90 | # and dumping them if something goes wrong. | |
91 | ||
92 | checkforlogs() { | |
93 | # skip it if we're under debian-test | |
94 | if test -n "${Debian}" ; then return 0 ; fi | |
95 | ||
96 | if [ -f $1 -a -s $1 ] ; then | |
97 | echo "Failures have occurred. $1 follows:" >&2 | |
98 | cat $1 >&2 | |
99 | exit 1 | |
100 | fi | |
101 | } | |
102 |