Fix msg argument to assert_equal

I noticed this was taking an argument but not dealing with it.  In
general the functions were undocumented, so I added some terse usage.

Also, the intent of the test-case was to expand the values before
using them as the message; make sure this happens by using a temp
variable.

Change-Id: Ib317ad1e9dd2a5d2232b9c64541fe4a601a2b8da
This commit is contained in:
Ian Wienand 2015-05-25 11:29:48 +10:00
parent cf56d4e35c
commit 165afa2377
2 changed files with 19 additions and 4 deletions

View File

@ -19,7 +19,8 @@ function test_trueorfalse {
for default in True False; do
for name in one captrue lowtrue uppertrue capyes lowyes upperyes; do
assert_equal "True" $(trueorfalse $default $name) "\$(trueorfalse $default $name)"
local msg="trueorfalse($default $name)"
assert_equal "True" $(trueorfalse $default $name) "$msg"
done
done
@ -33,7 +34,8 @@ function test_trueorfalse {
for default in True False; do
for name in zero capfalse lowfalse upperfalse capno lowno upperno; do
assert_equal "False" $(trueorfalse $default $name) "\$(trueorfalse $default $name)"
local msg="trueorfalse($default $name)"
assert_equal "False" $(trueorfalse $default $name) "$msg"
done
done
}

View File

@ -17,6 +17,8 @@ ERROR=0
PASS=0
FAILED_FUNCS=""
# pass a test, printing out MSG
# usage: passed message
function passed {
local lineno=$(caller 0 | awk '{print $1}')
local function=$(caller 0 | awk '{print $2}')
@ -25,9 +27,11 @@ function passed {
msg="OK"
fi
PASS=$((PASS+1))
echo $function:L$lineno $msg
echo "PASS: $function:L$lineno $msg"
}
# fail a test, printing out MSG
# usage: failed message
function failed {
local lineno=$(caller 0 | awk '{print $1}')
local function=$(caller 0 | awk '{print $2}')
@ -38,10 +42,16 @@ function failed {
ERROR=$((ERROR+1))
}
# assert string comparision of val1 equal val2, printing out msg
# usage: assert_equal val1 val2 msg
function assert_equal {
local lineno=`caller 0 | awk '{print $1}'`
local function=`caller 0 | awk '{print $2}'`
local msg=$3
if [ -z "$msg" ]; then
msg="OK"
fi
if [[ "$1" != "$2" ]]; then
FAILED_FUNCS+="$function:L$lineno\n"
echo "ERROR: $1 != $2 in $function:L$lineno!"
@ -49,10 +59,13 @@ function assert_equal {
ERROR=$((ERROR+1))
else
PASS=$((PASS+1))
echo "$function:L$lineno - ok"
echo "PASS: $function:L$lineno - $msg"
fi
}
# print a summary of passing and failing tests, exiting
# with an error if we have failed tests
# usage: report_results
function report_results {
echo "$PASS Tests PASSED"
if [[ $ERROR -gt 1 ]]; then