From: Wayne Davison Date: Mon, 21 Sep 2020 20:15:43 +0000 (-0700) Subject: Check status of tests that pipe rsync's output & simplify output diffing. X-Git-Tag: v3.2.4pre1~129 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=122b0fdc4f1fb9595f633fd4daf347de157ff659;p=thirdparty%2Frsync.git Check status of tests that pipe rsync's output & simplify output diffing. --- diff --git a/testsuite/backup.test b/testsuite/backup.test index 87db33e5..3b49db94 100644 --- a/testsuite/backup.test +++ b/testsuite/backup.test @@ -15,8 +15,6 @@ makepath "$fromdir/deep" "$bakdir/dname" name1="$fromdir/deep/name1" name2="$fromdir/deep/name2" -outfile="$scratchdir/rsync.out" - cat "$srcdir"/[gr]*.[ch] > "$name1" cat "$srcdir"/[et]*.[ch] > "$name2" @@ -26,8 +24,7 @@ checkit "$RSYNC -ai --info=backup '$fromdir/' '$chkdir/'" "$fromdir" "$chkdir" cat "$srcdir"/[fgpr]*.[ch] > "$name1" cat "$srcdir"/[etw]*.[ch] > "$name2" -$RSYNC -ai --info=backup --no-whole-file --backup "$fromdir/" "$todir/" \ - | tee "$outfile" +checktee "$RSYNC -ai --info=backup --no-whole-file --backup '$fromdir/' '$todir/'" for fn in deep/name1 deep/name2; do grep "backed up $fn to $fn~" "$outfile" >/dev/null || test_fail "no backup message output for $fn" diff $diffopt "$fromdir/$fn" "$todir/$fn" || test_fail "copy of $fn failed" diff --git a/testsuite/daemon.test b/testsuite/daemon.test index 836ce33b..80d2baf6 100644 --- a/testsuite/daemon.test +++ b/testsuite/daemon.test @@ -21,9 +21,6 @@ . "$suitedir/rsync.fns" -chkfile="$scratchdir/rsync.chk" -outfile="$scratchdir/rsync.out" - SSH="src/support/lsh.sh --no-cd" FILE_REPL='s/^\([^d][^ ]*\) *\(..........[0-9]\) /\1 \2 /' DIR_REPL='s/^\(d[^ ]*\) *[0-9][.,0-9]* /\1 DIR /' @@ -57,21 +54,17 @@ test-to r/w test-scratch NOCOMMENT EOT -$RSYNC -ve "$SSH" --rsync-path="$RSYNC$confopt" localhost:: | tee "$outfile" +checkdiff2 "$RSYNC -ve '$SSH' --rsync-path='$RSYNC$confopt' localhost::" echo '====' -diff $diffopt "$chkfile" "$outfile" || test_fail "test 0 failed" RSYNC_CONNECT_PROG="$RSYNC --config=$conf --daemon" export RSYNC_CONNECT_PROG -$RSYNC -v localhost:: | tee "$outfile" +checkdiff2 "$RSYNC -v localhost::" echo '====' -diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed" -$RSYNC -r localhost::test-hidden \ - | sed "$FILE_REPL" | sed "$DIR_REPL" | sed "$LS_REPL" \ - | tee "$outfile" -cat <"$chkfile" +checkdiff "$RSYNC -r localhost::test-hidden" \ + "sed -e '$FILE_REPL' -e '$DIR_REPL' -e '$LS_REPL'" <"$chkfile" +checkdiff "$RSYNC -r localhost::test-from/f*" \ + "sed -e '$FILE_REPL' -e '$DIR_REPL' -e '$LS_REPL'" </dev/null; then - $RSYNC -rU localhost::test-from/f* \ - | sed "$FILE_REPL" | sed "$DIR_REPL" | sed "$LS_REPL" \ - | tee "$outfile" - cat <"$chkfile" + checkdiff "$RSYNC -rU localhost::test-from/f*" \ + "sed -e '$FILE_REPL' -e '$DIR_REPL' -e '$LS_REPL'" <"$chkfile" +checkdiff "$RSYNC -ai '$fromdir/block' '$todir/block2'" <"$chkfile" +checkdiff "$RSYNC -ai '$fromdir/block2' '$todir/block'" <"$chkfile" +checkdiff "$RSYNC -Di '$fromdir/block3' '$todir/block'" <"$chkfile" +cat >"$chkfile" <"$chkfile.new" mv "$chkfile.new" "$chkfile" fi -diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed" + +checkdiff2 "$RSYNC -aiHvv '$fromdir/' '$todir/'" v_filt echo "check how the directory listings compare with diff:" echo "" @@ -167,9 +153,7 @@ diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" if test "$CAN_HLINK_SPECIAL" = yes; then set -x - $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \ - | tee "$outfile" - cat <"$chkfile" + checkdiff "$RSYNC -aii --link-dest='$todir' '$fromdir/' '$chkdir/'" < "$name1" ln -s "$name1" "$name2" || test_fail "can't create symlink" -outfile="$scratchdir/rsync.out" - checkit "$RSYNC -avv '$fromdir/' '$fromdir/' '$fromdir/' '$fromdir/' '$fromdir/' '$fromdir/' '$fromdir/' '$fromdir/' '$fromdir/' '$fromdir/' '$todir/'" "$fromdir" "$todir" \ | tee "$outfile" diff --git a/testsuite/exclude.test b/testsuite/exclude.test index f9d1a990..c3f7185b 100644 --- a/testsuite/exclude.test +++ b/testsuite/exclude.test @@ -12,9 +12,6 @@ . "$suitedir/rsync.fns" -chkfile="$scratchdir/rsync.chk" -outfile="$scratchdir/rsync.out" - CVSIGNORE='*.junk' export CVSIGNORE @@ -228,16 +225,13 @@ checkit "$RSYNC -avv $relative_opts --exclude='$fromdir/foo/down' \ '$fromdir/foo' '$todir'" "$chkdir$fromdir/foo" "$todir$fromdir/foo" # Now we'll test the --update option. -$RSYNC -aiiO --update --info=skip "$scratchdir/up1/" "$scratchdir/up2/" \ - | tee "$outfile" -cat <"$chkfile" +checkdiff "$RSYNC -aiiO --update --info=skip '$scratchdir/up1/' '$scratchdir/up2/'" <f$all_plus extra-src .f$allspace same-newness >f..t.$dots src-newness EOT -diff $diffopt "$chkfile" "$outfile" || test_fail "--update test failed" # The script would have aborted on error, so getting here means we've won. exit 0 diff --git a/testsuite/hardlinks.test b/testsuite/hardlinks.test index 740d725f..6c4fafbc 100644 --- a/testsuite/hardlinks.test +++ b/testsuite/hardlinks.test @@ -13,8 +13,6 @@ SSH="$scratchdir/src/support/lsh.sh" -outfile="$scratchdir/rsync.out" - # Build some hardlinks fromdir="$scratchdir/from" @@ -70,7 +68,7 @@ echo "This is another file" >"$fromdir/solo" ln "$fromdir/solo" "$chkdir/solo" || test_fail "Can't create hardlink" # Make sure that the checksum data doesn't slide due to an HLINK_BUMP() change. -$RSYNC -aHivc --debug=HLINK5 "$fromdir/" "$chkdir/" | tee "$outfile" +checktee "$RSYNC -aHivc --debug=HLINK5 '$fromdir/' '$chkdir/'" grep solo "$outfile" && test_fail "Erroneous copy of solo file occurred!" # Make sure there's nothing wrong with sending a single file with -H diff --git a/testsuite/itemize.test b/testsuite/itemize.test index 9988cb72..146ed2ed 100644 --- a/testsuite/itemize.test +++ b/testsuite/itemize.test @@ -12,9 +12,6 @@ to2dir="$tmpdir/to2" -chkfile="$scratchdir/rsync.chk" -outfile="$scratchdir/rsync.out" - makepath "$fromdir/foo" makepath "$fromdir/bar/baz" cp_p "$srcdir/configure.ac" "$fromdir/foo/config1" @@ -28,10 +25,18 @@ ln "$fromdir/foo/config1" "$fromdir/foo/extra" rm -f "$to2dir" # Check if rsync is set to hard-link symlinks. -if egrep '^#define CAN_HARDLINK_SYMLINK 1' config.h >/dev/null; then +if $RSYNC --version | grep "[, ] hardlink-symlinks" >/dev/null; then L=hL + sym_dots="$allspace" + L_sym_dots=".L$allspace" + is_uptodate='is uptodate' + touch "$chkfile.extra" else L=cL + sym_dots="c.t.$dots" + L_sym_dots="cL$sym_dots" + is_uptodate='-> ../bar/baz/rsync' + echo "cL$sym_dots foo/sym $is_uptodate" >"$chkfile.extra" fi # Check if rsync can preserve time on symlinks @@ -48,9 +53,7 @@ case "$RSYNC" in ;; esac -$RSYNC -iplr "$fromdir/" "$todir/" \ - | tee "$outfile" -cat <"$chkfile" +checkdiff "$RSYNC -iplr '$fromdir/' '$todir/'" <f$all_plus foo/extra cL$all_plus foo/sym -> ../bar/baz/rsync EOT -diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed" # Ensure there are no accidental directory-time problems. $RSYNC -a -f '-! */' "$fromdir/" "$todir" cp_p "$srcdir/configure.ac" "$fromdir/foo/config2" chmod 601 "$fromdir/foo/config2" -$RSYNC -iplrH "$fromdir/" "$todir/" \ - | tee "$outfile" -cat <"$chkfile" +checkdiff "$RSYNC -iplrH '$fromdir/' '$todir/'" <f..T.$dots bar/baz/rsync >f..T.$dots foo/config1 >f.sTp$dots foo/config2 hf..T.$dots foo/extra => foo/config1 EOT -diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed" $RSYNC -a -f '-! */' "$fromdir/" "$todir" cp_p "$srcdir/config.sub" "$fromdir/foo/config2" @@ -88,38 +87,30 @@ umask 022 chmod 600 "$fromdir/foo/config2" chmod 777 "$todir/bar/baz/rsync" -$RSYNC -iplrtc "$fromdir/" "$todir/" \ - | tee "$outfile" -cat <"$chkfile" +checkdiff "$RSYNC -iplrtc '$fromdir/' '$todir/'" <fcstp$dots foo/config2 cLc$T.$dots foo/sym -> ../bar/baz/rsync EOT -diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed" cp_p "$srcdir/configure.ac" "$fromdir/foo/config2" chmod 600 "$fromdir/foo/config2" # Lack of -t is for unchanged hard-link stress-test! -$RSYNC -vvplrH "$fromdir/" "$todir/" \ - | tee "$outfile" -filter_outfile -cat <"$chkfile" +checkdiff "$RSYNC -vvplrH '$fromdir/' '$todir/'" \ + v_filt <"$chkfile" +checkdiff "$RSYNC -ivvplrtH '$fromdir/' '$todir/'" \ + v_filt <"$chkfile" hf$allspace foo/extra .L$allspace foo/sym -> ../bar/baz/rsync EOT -diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed" chmod 757 "$todir/foo/config1" touch "$todir/foo/config2" -$RSYNC -vplrtH "$fromdir/" "$todir/" \ - | tee "$outfile" -filter_outfile -cat <"$chkfile" +checkdiff "$RSYNC -vplrtH '$fromdir/' '$todir/'" \ + v_filt <"$chkfile" +checkdiff "$RSYNC -iplrtH '$fromdir/' '$todir/'" <f..t.$dots foo/config2 EOT -diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed" -$RSYNC -ivvplrtH --copy-dest=../to "$fromdir/" "$to2dir/" \ - | tee "$outfile" -filter_outfile -case `tail -1 "$outfile"` in -cLc.t*) - sym_dots="c.t.$dots" - L_sym_dots="cL$sym_dots" - is_uptodate='-> ../bar/baz/rsync' - echo "cL$sym_dots foo/sym $is_uptodate" >"$chkfile.extra" - L=cL - ;; -*) - sym_dots="$allspace" - L_sym_dots=".L$allspace" - is_uptodate='is uptodate' - touch "$chkfile.extra" - ;; -esac -cat <"$chkfile" +checkdiff "$RSYNC -ivvplrtH --copy-dest=../to '$fromdir/' '$to2dir/'" \ + v_filt < foo/config1 cL$sym_dots foo/sym -> ../bar/baz/rsync EOT -diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed" rm -rf "$to2dir" -$RSYNC -iplrtH --copy-dest=../to "$fromdir/" "$to2dir/" \ - | tee "$outfile" cat - "$chkfile.extra" <"$chkfile" hf$allspace foo/extra => foo/config1 EOT -diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed" +checkdiff2 "$RSYNC -iplrtH --copy-dest=../to '$fromdir/' '$to2dir/'" rm -rf "$to2dir" -$RSYNC -vvplrtH --copy-dest="$todir" "$fromdir/" "$to2dir/" \ - | tee "$outfile" -filter_outfile -cat <"$chkfile" +checkdiff "$RSYNC -vvplrtH --copy-dest='$todir' '$fromdir/' '$to2dir/'" \ + v_filt < foo/config1 EOT -diff $diffopt "$chkfile" "$outfile" || test_fail "test 10 failed" rm -rf "$to2dir" -$RSYNC -ivvplrtH --link-dest="$todir" "$fromdir/" "$to2dir/" \ - | tee "$outfile" -filter_outfile -cat <"$chkfile" +checkdiff "$RSYNC -ivvplrtH --link-dest='$todir' '$fromdir/' '$to2dir/'" \ + v_filt < foo/config1 $L$sym_dots foo/sym -> ../bar/baz/rsync EOT -diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed" rm -rf "$to2dir" -$RSYNC -iplrtH --dry-run --link-dest=../to "$fromdir/" "$to2dir/" \ - | tee "$outfile" -cat - "$chkfile.extra" <"$chkfile" -EOT -diff $diffopt "$chkfile" "$outfile" || test_fail "test 12 failed" +checkdiff "$RSYNC -iplrtH --dry-run --link-dest=../to '$fromdir/' '$to2dir/'" <"$chkfile.extra" rm -rf "$to2dir" -$RSYNC -iplrtH --link-dest=../to "$fromdir/" "$to2dir/" \ - | tee "$outfile" -cat - "$chkfile.extra" <"$chkfile" -EOT -diff $diffopt "$chkfile" "$outfile" || test_fail "test 13 failed" +checkdiff "$RSYNC -iplrtH --link-dest=../to '$fromdir/' '$to2dir/'" <"$chkfile.extra" rm -rf "$to2dir" -$RSYNC -vvplrtH --link-dest="$todir" "$fromdir/" "$to2dir/" \ - | tee "$outfile" -filter_outfile -cat <"$chkfile" +checkdiff "$RSYNC -vvplrtH --link-dest='$todir' '$fromdir/' '$to2dir/'" \ + v_filt <"$chkfile" +checkdiff "$RSYNC -ivvplrtH --compare-dest='$todir' '$fromdir/' '$to2dir/'" \ + v_filt < ../bar/baz/rsync EOT -diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed" rm -rf "$to2dir" -$RSYNC -iplrtH --compare-dest="$todir" "$fromdir/" "$to2dir/" \ - | tee "$outfile" -cat - "$chkfile.extra" <"$chkfile" -EOT -diff $diffopt "$chkfile" "$outfile" || test_fail "test 16 failed" +checkdiff "$RSYNC -iplrtH --compare-dest='$todir' '$fromdir/' '$to2dir/'" <"$chkfile.extra" rm -rf "$to2dir" -$RSYNC -vvplrtH --compare-dest="$todir" "$fromdir/" "$to2dir/" \ - | tee "$outfile" -filter_outfile -cat <"$chkfile" +checkdiff "$RSYNC -vvplrtH --compare-dest='$todir' '$fromdir/' '$to2dir/'" \ + v_filt <"$extrafile" $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$extradir/" -outfile="$scratchdir/rsync.out" - cd "$fromdir" # Main script starts here diff --git a/testsuite/rsync.fns b/testsuite/rsync.fns index 68389e70..4a7cd3d3 100644 --- a/testsuite/rsync.fns +++ b/testsuite/rsync.fns @@ -12,7 +12,7 @@ # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. -# +# # You should have received a copy of the GNU Lesser General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. @@ -22,6 +22,9 @@ fromdir="$tmpdir/from" todir="$tmpdir/to" chkdir="$tmpdir/chk" +chkfile="$scratchdir/rsync.chk" +outfile="$scratchdir/rsync.out" + # For itemized output: all_plus='+++++++++' allspace=' ' @@ -75,10 +78,10 @@ cp_touch() { fi } -# Call this if you want to filter out verbose messages (-v or -vv) from -# the output of an rsync run (whittling the output down to just the file -# messages). This isn't needed if you use -i without -v. -filter_outfile() { +# Call this if you want to filter (stdin -> stdout) verbose messages (-v or +# -vv) from an rsync run (whittling the output down to just the file messages). +# This isn't needed if you use -i without -v. +v_filt() { sed -e '/^building file list /d' \ -e '/^sending incremental file list/d' \ -e '/^created directory /d' \ @@ -87,9 +90,7 @@ filter_outfile() { -e '/^total: /d' \ -e '/^client charset: /d' \ -e '/^server charset: /d' \ - -e '/^$/,$d' \ - <"$outfile" >"$outfile.new" - mv "$outfile.new" "$outfile" + -e '/^$/,$d' } printmsg() { @@ -149,7 +150,7 @@ check_perms() { test_fail "failed test $3" } -rsync_getgroups() { +rsync_getgroups() { "$TOOLDIR/getgroups" } @@ -171,7 +172,7 @@ hands_setup() { # the links behave in the future, and it cannot be changed using # chmod! rsync always sets its umask to 000 so that it can # accurately recreate permissions, but this script is probably run - # with a different umask. + # with a different umask. # This causes a little problem that "ls -l" of the two will not be # the same. So, we need to set our umask before doing any creations. @@ -213,7 +214,7 @@ hands_setup() { #################### # Many machines do not have "mkdir -p", so we have to build up long paths. -# How boring. +# How boring. makepath() { for p in "${@}"; do (echo " makepath $p" @@ -223,11 +224,11 @@ makepath() { then cd / fi - + # This will break if $p contains a space. for c in `echo $p | tr '/' ' '` - do - if [ -d "$c" ] || mkdir "$c" + do + if [ -d "$c" ] || mkdir "$c" then cd "$c" || return $? else @@ -262,8 +263,8 @@ checkit() { ;; esac - echo "Running: \"$1\"" - eval "$1" + echo "Running: \"$1\"" + eval "$1" status=$? if [ $status != 0 ]; then failed="$failed status=$status" @@ -302,6 +303,57 @@ checkit() { } +# Run a test in $1 and make sure it has a zero exit status. Capture the +# output into $outfile and echo it to stdout. +checktee() { + echo "Running: \"$1\"" + eval "$1" >"$outfile" + status=$? + cat "$outfile" + if [ $status != 0 ]; then + echo "Failed: status=$status" + return 1 + fi + return 0 +} + + +# Slurp stdin into $chkfile and then call checkdiff2(). +checkdiff() { + cat >"$chkfile" # Save off stdin + checkdiff2 "${@}" +} + + +# Run a test in $1 and make sure it has a zero exit status. Capture the output +# into $outfile. If $2 is set, use it to filter the outfile. If resulting +# outfile differs from the chkfile data, fail with an error. +checkdiff2() { + failed= + + echo "Running: \"$1\"" + eval "$1" >"$outfile" + status=$? + cat "$outfile" + if [ $status != 0 ]; then + failed="$failed status=$status" + fi + + if [ "$2" ]; then + eval "cat '$outfile' | $2 >'$outfile.new'" + mv "$outfile.new" "$outfile" + fi + + diff $diffopt "$chkfile" "$outfile" || failed="$failed output differs" + + if [ "$failed" ] ; then + echo "Failed: $failed" + return 1 + fi + return 0 +} + + build_rsyncd_conf() { # Build an appropriate configuration file conf="$scratchdir/test-rsyncd.conf" @@ -404,7 +456,7 @@ test_skipped() { exit 77 } -# It failed, but we expected that. don't dump out error logs, +# It failed, but we expected that. Don't dump out error logs, # because most users won't want to see them. But do leave # the working directory around. test_xfail() { @@ -437,7 +489,7 @@ then else echo "Testing for symlinks using '$TEST_SYMLINK_CMD'" fi - + # Test whether something is a link, allowing for shell peculiarities is_a_link() { @@ -451,5 +503,5 @@ is_a_link() { # directory has to be writable by the nobody user in some cases. The # best thing is probably to explicitly chmod those directories after # creation. - + umask 022