1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#!/bin/bash
# This cannot be a plain function, because $LINENO would be
# relative to this file
# \todo: unset -x while in this function
function _MSG
{
_exitc=$1
_msg=$2
_col=$3
unused=$4
shift 4
line="${BASH_LINENO[0]}"
# If the terminal doesn't support color switching, we should not
# stop - so ignore return value.
tput setaf $_col || true
if [[ $_msg == "OK" || $_msg == "INFO" ]]
then
# Tests that were ok need not be a jump mark
echo "$CURRENT_TEST at $line: $@"
else
rec=${#BASH_LINENO[*]}
# It took me a long time to find out that expr returns an errorlevel,
# if it's result is 0; eg. 2 - 2 returns errorlevel 1.
for idx in `seq 3 $rec`
do
idx=`expr $rec - 2`
echo "\"$CURRENT_TEST\":${BASH_LINENO[$idx]}: calling ${FUNCNAME[$idx]}"
done
echo "\"$CURRENT_TEST\":$line: $_msg: $@"
fi
tput op || true
if [[ $_exitc == 1 ]]
then
trap '' ERR
exit 1
fi
}
export INFO="_MSG 0 INFO 5 \$LINENO"
export SUCCESS="_MSG 0 OK 2 \$LINENO"
export WARN="_MSG 0 WARNING 3 \$LINENO"
export ERROR="_MSG 1 NOK 1 \$LINENO"
# error, non-breaking
export ERROR_NB="_MSG 0 NOK 1 \$LINENO"
export FSVS_ERR_TRAP=true
# When we're checking results in some locale, we nonetheless need the
# output in plain english, so that the strings (eg. from diff) can be
# compared.
export LC_MESSAGES=C
export COMPARE="$TEST_PROG_DIR/compare"
export COMPAREWITH="$COMPARE $WC/"
export COMPARE_1_2="$COMPAREWITH $WC2/"
export PATH2SPOOL=$TEST_PROG_DIR/path2spool
trap '( eval $FSVS_ERR_TRAP ) ; $ERROR shell error' ERR
set -e -E
|