Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Make the bash scripts path-agnostic #18

Merged
merged 1 commit into from
May 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 49 additions & 50 deletions tools-sh/_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ fi
# Change these if necessary:
#############################################################################

# Relative path from this script to the top-level tidy-html5-tests directory.
project_root_dir=".."
# Absolute path of the top-level tidy-html5-tests directory.
project_root_dir="$(readlink -e $(dirname $0)/..)"

# These are all relative from the project_root_dir directory.
cases_base_dir="cases"
Expand Down Expand Up @@ -72,7 +72,7 @@ set_environment()
# cd "${cwd}"

# *Only* set TY_CASES_SETNAME if it's not already set!
if [ -z "$TY_CASES_SETNAME" ]; then
if [ -z "${TY_CASES_SETNAME}" ]; then
export TY_CASES_SETNAME="${cases_setname}"
fi

Expand All @@ -92,20 +92,20 @@ set_environment()

report_environment()
{
echo "TY_PROJECT_ROOT_DIR = $TY_PROJECT_ROOT_DIR"
echo " TY_CASES_BASE_DIR = $TY_CASES_BASE_DIR"
echo " TY_CASES_DIR = $TY_CASES_DIR"
echo " TY_EXPECTS_DIR = $TY_EXPECTS_DIR"
echo " TY_EXPECTS_FILE = $TY_EXPECTS_FILE"
echo " TY_CONFIG_DEFAULT = $TY_CONFIG_DEFAULT"
echo " TY_VERSION_FILE = $TY_VERSION_FILE"
echo "TY_RESULTS_BASE_DIR = $TY_RESULTS_BASE_DIR"
echo " TY_RESULTS_DIR = $TY_RESULTS_DIR"
echo " TY_RESULTS_FILE = $TY_RESULTS_FILE"
echo " TY_TMP_DIR = $TY_TMP_DIR"
echo " TY_TMP_FILE = $TY_TMP_FILE"
echo " TY_TIDY_PATH = $TY_TIDY_PATH"
echo " TY_CASES_SETNAME = $TY_CASES_SETNAME"
echo "TY_PROJECT_ROOT_DIR = ${TY_PROJECT_ROOT_DIR}"
echo " TY_CASES_BASE_DIR = ${TY_CASES_BASE_DIR}"
echo " TY_CASES_DIR = ${TY_CASES_DIR}"
echo " TY_EXPECTS_DIR = ${TY_EXPECTS_DIR}"
echo " TY_EXPECTS_FILE = ${TY_EXPECTS_FILE}"
echo " TY_CONFIG_DEFAULT = ${TY_CONFIG_DEFAULT}"
echo " TY_VERSION_FILE = ${TY_VERSION_FILE}"
echo "TY_RESULTS_BASE_DIR = ${TY_RESULTS_BASE_DIR}"
echo " TY_RESULTS_DIR = ${TY_RESULTS_DIR}"
echo " TY_RESULTS_FILE = ${TY_RESULTS_FILE}"
echo " TY_TMP_DIR = ${TY_TMP_DIR}"
echo " TY_TMP_FILE = ${TY_TMP_FILE}"
echo " TY_TIDY_PATH = ${TY_TIDY_PATH}"
echo " TY_CASES_SETNAME = ${TY_CASES_SETNAME}"
}

report_testbase_version()
Expand All @@ -119,10 +119,10 @@ report_tidy_version()
local version=$(${TY_TIDY_PATH} -v)
if [ ! "$?" = "0" ]; then
echo ""
echo "$BN: ${TY_TIDY_PATH}"
echo "$BN: Tidy was unable to run '${TY_TIDY_PATH} -v' successfully."
echo "${BN}: ${TY_TIDY_PATH}"
echo "${BN}: Tidy was unable to run '${TY_TIDY_PATH} -v' successfully."
echo ""
ERROR_COUNT=$(($ERROR_COUNT + 1))
ERROR_COUNT=$((${ERROR_COUNT} + 1))
return 1
fi
echo $version
Expand All @@ -137,10 +137,10 @@ test_case_file()
{
if [ ! -f "$1" ]; then
echo ""
echo "$BN: Case file: $1"
echo "$BN: This case file was not found. Is the number correct?"
echo "${BN}: Case file: $1"
echo "${BN}: This case file was not found. Is the number correct?"
echo ""
ERROR_COUNT=$(($ERROR_COUNT + 1))
ERROR_COUNT=$((${ERROR_COUNT} + 1))
return 1
fi
}
Expand All @@ -149,10 +149,10 @@ test_case_config()
{
if [ ! -f "$1" ]; then
echo ""
echo "$BN: Config file: $1"
echo "$BN: This configuration file was not found."
echo "${BN}: Config file: $1"
echo "${BN}: This configuration file was not found."
echo ""
ERROR_COUNT=$(($ERROR_COUNT + 1))
ERROR_COUNT=$((${ERROR_COUNT} + 1))
return 1
fi
}
Expand All @@ -162,9 +162,9 @@ test_file_general()
{
if [ ! -f "$1" ]; then
echo ""
echo "$BN: $1"
echo "$BN: This file is needed but was not found."
ERROR_COUNT=$(($ERROR_COUNT + 1))
echo "${BN}: $1"
echo "${BN}: This file is needed but was not found."
ERROR_COUNT=$((${ERROR_COUNT} + 1))
return 1
fi
}
Expand All @@ -174,10 +174,10 @@ test_file_expects()
{
if [ ! -f "$1" ]; then
echo ""
echo "$BN: Expects file: $1"
echo "$BN: This file is needed for the compare, but this may not be a problem."
echo "$BN: Maybe there is no 'expects' file for test $1!"
ERROR_COUNT=$(($ERROR_COUNT + 1))
echo "${BN}: Expects file: $1"
echo "${BN}: This file is needed for the compare, but this may not be a problem."
echo "${BN}: Maybe there is no 'expects' file for test $1!"
ERROR_COUNT=$((${ERROR_COUNT} + 1))
return 1
fi
}
Expand All @@ -187,11 +187,11 @@ test_file_output()
{
if [ ! -f "$1" ]; then
echo ""
echo "$BN: Tidy output: $1"
echo "$BN: This file is needed for the compare. It is strange this it was not created."
echo "$BN: *** NEEDS CHECKING ***"
echo "${BN}: Tidy output: $1"
echo "${BN}: This file is needed for the compare. It is strange this it was not created."
echo "${BN}: *** NEEDS CHECKING ***"
echo ""
ERROR_COUNT=$(($ERROR_COUNT + 1))
ERROR_COUNT=$((${ERROR_COUNT} + 1))
return 1
fi
}
Expand All @@ -200,11 +200,11 @@ test_results_base_dir()
{
if [ ! -d "${TY_RESULTS_BASE_DIR}" ]; then
echo ""
echo "$BN: ${TY_RESULTS_BASE_DIR}"
echo "$BN: This results directory was not found; it must be created yourself."
echo "$BN: This script does NOT create this directory."
echo "${BN}: ${TY_RESULTS_BASE_DIR}"
echo "${BN}: This results directory was not found; it must be created yourself."
echo "${BN}: This script does NOT create this directory."
echo ""
ERROR_COUNT=$(($ERROR_COUNT + 1))
ERROR_COUNT=$((${ERROR_COUNT} + 1))
return 1
fi
}
Expand All @@ -213,21 +213,21 @@ test_tidy_path()
{
if [ -z "${TY_TIDY_PATH+x}" ]; then
echo ""
echo "$BN: TY_TIDY_PATH is not set"
echo "$BN: You must call this script with an argument pointing to an instance"
echo "$BN: of HTML Tidy, or set the TY_TIDY_PATH environment variable to"
echo "$BN: point to an instance of HTML Tidy."
echo "${BN}: TY_TIDY_PATH is not set"
echo "${BN}: You must call this script with an argument pointing to an instance"
echo "${BN}: of HTML Tidy, or set the TY_TIDY_PATH environment variable to"
echo "${BN}: point to an instance of HTML Tidy."
echo ""
ERROR_COUNT=$(($ERROR_COUNT + 1))
ERROR_COUNT=$((${ERROR_COUNT} + 1))
return 1
fi

if [ ! -x "${TY_TIDY_PATH}" ]; then
echo ""
echo "$BN: ${TY_TIDY_PATH}"
echo "$BN: This instance of Tidy was not found. Is it on your path?"
echo "${BN}: ${TY_TIDY_PATH}"
echo "${BN}: This instance of Tidy was not found. Is it on your path?"
echo ""
ERROR_COUNT=$(($ERROR_COUNT + 1))
ERROR_COUNT=$((${ERROR_COUNT} + 1))
return 1
fi
}
Expand All @@ -241,4 +241,3 @@ test_tidy_path()
BN="`basename $0`"
ERROR_COUNT=0
# eof

5 changes: 3 additions & 2 deletions tools-sh/_envtest.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

source _environment.sh
DIR="$(readlink -e $(dirname $0))"
source "${DIR}/_environment.sh"

set_environment

Expand All @@ -14,4 +15,4 @@ test_results_base_dir

version=$(report_tidy_version)

echo $version
echo "${version}"
80 changes: 40 additions & 40 deletions tools-sh/cmp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
# this can COMPARE the files ONE BY ONE
#
BN=`basename $0`
DIR="$(readlink -e $(dirname $0))"

TMPDIR1=$1
TMPDIR2=$2
TMPDIR1="$1"
TMPDIR2="$2"
OUTLOG="temp.diff"
TMPDOP="-ua"

usage()
{
echo ""
echo "Usage: ./$BN directory1 directory2"
echo "Usage: ./${BN} directory1 directory2"
echo ""
echo "$BN: If you have the tidied HTML output from two version of 'tidy' then "
echo "$BN: this can COMPARE the output files ONE BY ONE, output to $OUTLOG"
echo "${BN}: If you have the tidied HTML output from two version of 'tidy' then "
echo "${BN}: this can COMPARE the output files ONE BY ONE, output to ${OUTLOG}"
echo ""
}

Expand All @@ -25,21 +26,21 @@ d_now()
date +%Y%m%d%H%M%S
}

if [ -z "$TMPDIR1" ] || [ -z "$TMPDIR2" ] || [ "$TMPDIR1" = "--help" ] || [ "$TMPDIR1" = "-h" ] || [ "$TMPDIR1" = "-?" ]; then
if [ -z "${TMPDIR1}" ] || [ -z "${TMPDIR2}" ] || [ "${TMPDIR1}" = "--help" ] || [ "${TMPDIR1}" = "-h" ] || [ "${TMPDIR1}" = "-?" ]; then
usage
exit 1
fi


if [ ! -d "$TMPDIR1" ]; then
if [ ! -d "${TMPDIR1}" ]; then
usage
echo "$BN: Can NOT locate directory 1 '$TMPDIR1'!"
echo "${BN}: Can NOT locate directory 1 '${TMPDIR1}'!"
exit 1
fi

if [ ! -d "$TMPDIR2" ]; then
if [ ! -d "${TMPDIR2}" ]; then
usage
echo "$BN: Can NOT locate directory 2 '$TMPDIR2'!"
echo "${BN}: Can NOT locate directory 2 '${TMPDIR2}'!"
exit 1
fi

Expand All @@ -56,54 +57,53 @@ DIFFFILES=""
TMPMASK="*"
# TMPMASK="*.html"

for fil in $TMPDIR1/$TMPMASK; do
TMPCNT1=`expr $TMPCNT1 + 1`
for fil in "${TMPDIR1}"/${TMPMASK}; do
TMPCNT1=`expr ${TMPCNT1} + 1`
done

for fil in $TMPDIR2/$TMPMASK; do
TMPCNT2=`expr $TMPCNT2 + 1`
for fil in "${TMPDIR2}"/${TMPMASK}; do
TMPCNT2=`expr ${TMPCNT2} + 1`
done

echo "$BN: Found $TMPCNT1 files in $TMPDIR1"
echo "$BN: Found $TMPCNT2 files in $TMPDIR2"
echo "${BN}: Found ${TMPCNT1} files in ${TMPDIR1}"
echo "${BN}: Found ${TMPCNT2} files in ${TMPDIR2}"

if [ -f "$OUTLOG" ]; then
rm -f $OUTLOG
if [ -f "${OUTLOG}" ]; then
rm -f "${OUTLOG}"
fi

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
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}"

for fil in $TMPDIR1/$TMPMASK; do
for fil in "${TMPDIR1}"/${TMPMASK}; do
bfil=`basename $fil`
if [ -f "$TMPDIR2/$bfil" ]; then
diff $TMPDOP $TMPDIR1/$bfil $TMPDIR2/$bfil >> $OUTLOG
if [ -f "${TMPDIR2}/$bfil" ]; then
diff "${TMPDOP}" "${TMPDIR1}/$bfil" "${TMPDIR2}/$bfil" >> "${OUTLOG}"
if [ "$?" = "0" ]; then
echo "diff $TMPDOP $TMPDIR1/$bfil $TMPDIR2/$bfil are the SAME" >> $OUTLOG
SAMECNT=`expr $SAMECNT + 1`
echo "diff ${TMPDOP} ${TMPDIR1}/$bfil ${TMPDIR2}/$bfil are the SAME" >> "${OUTLOG}"
SAMECNT=`expr ${SAMECNT} + 1`
else
echo "diff $TMPDOP $TMPDIR1/$bfil $TMPDIR2/$bfil are DIFFERENT! *** CHECK DIFFERENCE ***" >> $OUTLOG
DIFFCNT=`expr $DIFFCNT + 1`
DIFFFILES="$DIFFFILES $bfil"
echo "diff ${TMPDOP} ${TMPDIR1}/$bfil ${TMPDIR2}/$bfil are DIFFERENT! *** CHECK DIFFERENCE ***" >> "${OUTLOG}"
DIFFCNT=`expr ${DIFFCNT} + 1`
DIFFFILES="${DIFFFILES} $bfil"
fi
else
echo "$BN: File $bfil not found in dir 2 $TMPDIR2" >> $OUTLOG
echo "${BN}: File $bfil not found in dir 2 ${TMPDIR2}" >> "${OUTLOG}"
fi
done
TOTCNT=`expr $SAMECNT + $DIFFCNT`
echo "" >> $OUTLOG
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
if [ ! "$DIFFCNT" = "0" ]; then
echo "$BN: VERIFY $DIFFCNT $DIFFFILES"
echo "$BN: VERIFY $DIFFCNT $DIFFFILES" >> $OUTLOG
TOTCNT=`expr ${SAMECNT} + ${DIFFCNT}`
echo "" >> "${OUTLOG}"
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}"
if [ ! "${DIFFCNT}" = "0" ]; then
echo "${BN}: VERIFY ${DIFFCNT} ${DIFFFILES}"
echo "${BN}: VERIFY ${DIFFCNT} ${DIFFFILES}" >> "${OUTLOG}"
fi
echo "" >> $OUTLOG
echo "" >> "${OUTLOG}"

echo "$BN: Full results are in $OUTLOG"
echo "${BN}: Full results are in ${OUTLOG}"
echo ""

# eof

Loading