tidy-html5/test/cmp.sh

110 lines
2.4 KiB
Bash
Raw Normal View History

2014-08-05 17:08:53 +00:00
#!/bin/sh
#< cmp.sh - 20140805
# If you have the tidied HTML output from two version of 'tidy' then
# this can COMPARE the files ONE BY ONE
#
BN=`basename $0`
TMPDIR1=$1
TMPDIR2=$2
OUTLOG="temp.diff"
2015-09-17 11:42:43 +00:00
TMPDOP="-ua"
2014-08-05 17:08:53 +00:00
usage()
{
echo ""
echo "Usage: ./$BN directory1 directory2"
echo ""
echo "$BN: If you have the tidied HTML output from two version of 'tidy' then "
2015-09-17 11:42:43 +00:00
echo "$BN: this can COMPARE the output files ONE BY ONE, output to $OUTLOG"
2014-08-05 17:08:53 +00:00
echo ""
}
2015-09-17 11:42:43 +00:00
d_now()
{
date +%Y%m%d%H%M%S
}
2014-08-05 17:08:53 +00:00
if [ -z "$TMPDIR1" ] || [ -z "$TMPDIR2" ] || [ "$TMPDIR1" = "--help" ] || [ "$TMPDIR1" = "-h" ] || [ "$TMPDIR1" = "-?" ]; then
usage
exit 1
fi
if [ ! -d "$TMPDIR1" ]; then
usage
2015-09-17 11:42:43 +00:00
echo "$BN: Can NOT locate directory 1 '$TMPDIR1'!"
2014-08-05 17:08:53 +00:00
exit 1
fi
if [ ! -d "$TMPDIR2" ]; then
usage
2015-09-17 11:42:43 +00:00
echo "$BN: Can NOT locate directory 2 '$TMPDIR2'!"
2014-08-05 17:08:53 +00:00
exit 1
fi
shift
shift
TMPCNT1=0
TMPCNT2=0
2014-08-06 10:12:49 +00:00
SAMECNT=0
DIFFCNT=0
2015-09-17 11:42:43 +00:00
DIFFFILES=""
2014-08-05 17:08:53 +00:00
2015-09-17 11:42:43 +00:00
# 20150917 - Maybe should be ALL, not just html
TMPMASK="*"
# TMPMASK="*.html"
for fil in $TMPDIR1/$TMPMASK; do
2014-08-05 17:08:53 +00:00
TMPCNT1=`expr $TMPCNT1 + 1`
done
2015-09-17 11:42:43 +00:00
for fil in $TMPDIR2/$TMPMASK; do
2014-08-05 17:08:53 +00:00
TMPCNT2=`expr $TMPCNT2 + 1`
done
2015-09-17 11:42:43 +00:00
echo "$BN: Found $TMPCNT1 files in $TMPDIR1"
echo "$BN: Found $TMPCNT2 files in $TMPDIR2"
2014-08-05 17:08:53 +00:00
if [ -f "$OUTLOG" ]; then
rm -f $OUTLOG
fi
2015-09-17 11:42:43 +00:00
TMPNOW=`d_now`
echo "$BN: Compare of '$TMPDIR1' and '$TMPDIR2' on $TMPNOW" >> $OUTLOG
echo "$BN: Found $TMPCNT1 files in $TMPDIR1" >> $OUTLOG
echo "$BN: Found $TMPCNT2 files in $TMPDIR2" >> $OUTLOG
2014-08-05 17:08:53 +00:00
2015-09-17 11:42:43 +00:00
for fil in $TMPDIR1/$TMPMASK; do
2014-08-05 17:08:53 +00:00
bfil=`basename $fil`
if [ -f "$TMPDIR2/$bfil" ]; then
2015-09-17 11:42:43 +00:00
diff $TMPDOP $TMPDIR1/$bfil $TMPDIR2/$bfil >> $OUTLOG
2014-08-06 10:12:49 +00:00
if [ "$?" = "0" ]; then
2015-09-17 11:42:43 +00:00
echo "diff $TMPDOP $TMPDIR1/$bfil $TMPDIR2/$bfil are the SAME" >> $OUTLOG
2014-08-06 10:12:49 +00:00
SAMECNT=`expr $SAMECNT + 1`
else
2015-09-17 11:42:43 +00:00
echo "diff $TMPDOP $TMPDIR1/$bfil $TMPDIR2/$bfil are DIFFERENT! *** CHECK DIFFERENCE ***" >> $OUTLOG
2014-08-06 10:12:49 +00:00
DIFFCNT=`expr $DIFFCNT + 1`
2015-09-17 11:42:43 +00:00
DIFFFILES="$DIFFFILES $bfil"
2014-08-06 10:12:49 +00:00
fi
2014-08-05 17:08:53 +00:00
else
2015-09-17 11:42:43 +00:00
echo "$BN: File $bfil not found in dir 2 $TMPDIR2" >> $OUTLOG
2014-08-05 17:08:53 +00:00
fi
done
2014-08-06 10:12:49 +00:00
TOTCNT=`expr $SAMECNT + $DIFFCNT`
2015-09-17 11:42:43 +00:00
echo "" >> $OUTLOG
2014-08-06 10:12:49 +00:00
echo "$BN: Of the $TOTCNT compares made, $SAMECNT are the SAME, $DIFFCNT are DIFFERENT"
echo "$BN: Of the $TOTCNT compares made, $SAMECNT are the SAME, $DIFFCNT are DIFFERENT" >> $OUTLOG
2015-09-17 11:42:43 +00:00
if [ ! "$DIFFCNT" = "0" ]; then
echo "$BN: VERIFY $DIFFCNT $DIFFFILES"
echo "$BN: VERIFY $DIFFCNT $DIFFFILES" >> $OUTLOG
fi
echo "" >> $OUTLOG
2014-08-05 17:08:53 +00:00
2015-09-17 11:42:43 +00:00
echo "$BN: Full results are in $OUTLOG"
echo ""
2014-08-05 17:08:53 +00:00
# eof