If we're using built-in *printf functions, then provide prototypes.
[rsync/rsync.git] / testsuite / rsync.fns
CommitLineData
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
7TMP="$scratchdir"
8FROM=${TMP}/from
9TO=${TMP}/to
10F1=text1
11LOG=${TMP}/log
3fedd74b 12RSYNC="$rsync_bin"
3a4c683f
MP
13
14runtest() {
15 echo $ECHO_N "Test $1: $ECHO_C"
16 eval "$2"
17}
18
19printmsg() {
20 echo "$1"
21}
22
23hands_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
52checkit() {
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
92checkforlogs() {
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
d2094cc3
MP
103
104function build_rsyncd_conf {
105 # Build an appropriate configuration file
106 conf="$scratchdir/test-rsyncd.conf"
107 echo "building configuration $conf"
108
109 port=2612
110 pidfile="$scratchdir/rsyncd.pid"
111 logfile="$scratchdir/rsyncd.log"
112
113 cat >$conf <<EOF
3aae15ec 114# rsyncd configuration file autogenerated by $0
d2094cc3 115
3aae15ec
MP
116pid file = $pidfile
117use chroot = no
118hosts allow = localhost, 127.0.0.1
119log file = $logfile
d2094cc3 120
3aae15ec
MP
121[test-from] = $scratchdir/daemon-from/
122 read only = yes
d2094cc3 123
3aae15ec
MP
124[test-to] = $scratchdir/daemon-to/
125 read only = no
d2094cc3
MP
126EOF
127}
128
129