Clean up Phil's test more.
[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
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}
3fedd74b
MP
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
50checkit() {
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