Clean up output a little.
[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
e052b21f
MP
23
24####################
25# Build test directories TO and FROM, with FROM full of files.
26
3a4c683f
MP
27hands_setup() {
28 [ -d $FROM ] || mkdir $FROM
29 [ -d $TO ] || mkdir $TO
30
e052b21f
MP
31 # On some BSD systems, the umask affects the mode of created
32 # symlinks, even though the mode apparently has no effect on how
33 # the links behave in the future, and it cannot be changed using
34 # chmod! rsync always sets its umask to 000 so that it can
35 # accurately recreate permissions, but this script is probably run
36 # with a different umask.
37
38 # This causes a little problem that "ls -l" of the two will not be
39 # the same. So, we need to set our umask before doing any creations.
40
41 umask 0
42
3a4c683f
MP
43 # set up test data
44 touch ${FROM}/empty
45 mkdir ${FROM}/emptydir
e8ca5901
MP
46
47 # a few hundred lines of test
48 ls -lR / | head -200 > ${FROM}/filelist
3a4c683f
MP
49
50 # This might fail on systems that don't have -n
51 echo $ECHO_N "This file has no trailing lf$ECHO_C" > ${FROM}/nolf
52 ln -s nolf ${FROM}/nolf-symlink
751411c4 53 cat $srcdir/*.c | head -2000 > ${FROM}/${F1}
3a4c683f
MP
54 mkdir ${FROM}/dir
55 cp ${FROM}/${F1} ${FROM}/dir
56 mkdir ${FROM}/dir/subdir
57 mkdir ${FROM}/dir/subdir/subsubdir
58 ls -ltr /etc > ${FROM}/dir/subdir/subsubdir/etc-ltr-list
59 mkdir ${FROM}/dir/subdir/subsubdir2
60 ls -lt /bin > ${FROM}/dir/subdir/subsubdir2/bin-lt-list
e052b21f
MP
61
62 umask 077
3a4c683f 63}
3fedd74b
MP
64
65
e052b21f 66
3fedd74b
MP
67###########################
68# Run a test (in '$1') then compare directories $2 and $3 to see if
69# there are any difference. If there are, explain them.
70
71checkit() {
72 log=${LOG}
73 failed=
74 # the log accumulates all output; we only display it if there
75 # is a problem.
76
77 echo "Running: \"$1\"" >${log}
78 echo "">>${log}
79 eval "$1" >>${log} 2>&1
80 status=$?
81 if [ $status != 0 ]; then
82 failed="YES";
83 fi
84
85 echo "-------------">>${log}
86 echo "check how the files compare with diff:">>${log}
87 echo "">>${log}
37c3cf43 88 diff -cr $2 $3 >>${log} 2>&1 || failed=YES
3fedd74b
MP
89 echo "-------------">>${log}
90 echo "check how the directory listings compare with diff:">>${log}
91 echo "">>${log}
92 ( cd $2 ; ls -laR ) > ${TMP}/ls-from 2>>${log}
93 ( cd $3 ; ls -laR ) > ${TMP}/ls-to 2>>${log}
37c3cf43 94 diff -c ${TMP}/ls-from ${TMP}/ls-to >>${log} 2>&1 || failed=YES
3fedd74b
MP
95 if [ -z "${failed}" ] ; then
96 echo "${ECHO_T} done."
97 rm $log
98 return 0
99 else
100 echo "${ECHO_T} failed!"
101 cat ${log}
102 rm ${log}
103 return 1
104 fi
105}
106
863dff51
MP
107
108# In fact, we need a more general feature of capturing all stderr/log files,
109# and dumping them if something goes wrong.
110
111checkforlogs() {
112 # skip it if we're under debian-test
113 if test -n "${Debian}" ; then return 0 ; fi
114
115 if [ -f $1 -a -s $1 ] ; then
116 echo "Failures have occurred. $1 follows:" >&2
117 cat $1 >&2
118 exit 1
119 fi
120}
121
d2094cc3 122
4a7cb3e8 123build_rsyncd_conf() {
d2094cc3
MP
124 # Build an appropriate configuration file
125 conf="$scratchdir/test-rsyncd.conf"
126 echo "building configuration $conf"
127
128 port=2612
129 pidfile="$scratchdir/rsyncd.pid"
130 logfile="$scratchdir/rsyncd.log"
131
132 cat >$conf <<EOF
3aae15ec 133# rsyncd configuration file autogenerated by $0
d2094cc3 134
3aae15ec
MP
135pid file = $pidfile
136use chroot = no
137hosts allow = localhost, 127.0.0.1
138log file = $logfile
d2094cc3 139
3aae15ec
MP
140[test-from] = $scratchdir/daemon-from/
141 read only = yes
d2094cc3 142
3aae15ec
MP
143[test-to] = $scratchdir/daemon-to/
144 read only = no
d2094cc3
MP
145EOF
146}
147
148