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:
parent
cf56d4e35c
commit
165afa2377
@ -19,7 +19,8 @@ function test_trueorfalse {
|
|||||||
|
|
||||||
for default in True False; do
|
for default in True False; do
|
||||||
for name in one captrue lowtrue uppertrue capyes lowyes upperyes; 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
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -33,7 +34,8 @@ function test_trueorfalse {
|
|||||||
|
|
||||||
for default in True False; do
|
for default in True False; do
|
||||||
for name in zero capfalse lowfalse upperfalse capno lowno upperno; 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
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ ERROR=0
|
|||||||
PASS=0
|
PASS=0
|
||||||
FAILED_FUNCS=""
|
FAILED_FUNCS=""
|
||||||
|
|
||||||
|
# pass a test, printing out MSG
|
||||||
|
# usage: passed message
|
||||||
function passed {
|
function passed {
|
||||||
local lineno=$(caller 0 | awk '{print $1}')
|
local lineno=$(caller 0 | awk '{print $1}')
|
||||||
local function=$(caller 0 | awk '{print $2}')
|
local function=$(caller 0 | awk '{print $2}')
|
||||||
@ -25,9 +27,11 @@ function passed {
|
|||||||
msg="OK"
|
msg="OK"
|
||||||
fi
|
fi
|
||||||
PASS=$((PASS+1))
|
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 {
|
function failed {
|
||||||
local lineno=$(caller 0 | awk '{print $1}')
|
local lineno=$(caller 0 | awk '{print $1}')
|
||||||
local function=$(caller 0 | awk '{print $2}')
|
local function=$(caller 0 | awk '{print $2}')
|
||||||
@ -38,10 +42,16 @@ function failed {
|
|||||||
ERROR=$((ERROR+1))
|
ERROR=$((ERROR+1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# assert string comparision of val1 equal val2, printing out msg
|
||||||
|
# usage: assert_equal val1 val2 msg
|
||||||
function assert_equal {
|
function assert_equal {
|
||||||
local lineno=`caller 0 | awk '{print $1}'`
|
local lineno=`caller 0 | awk '{print $1}'`
|
||||||
local function=`caller 0 | awk '{print $2}'`
|
local function=`caller 0 | awk '{print $2}'`
|
||||||
local msg=$3
|
local msg=$3
|
||||||
|
|
||||||
|
if [ -z "$msg" ]; then
|
||||||
|
msg="OK"
|
||||||
|
fi
|
||||||
if [[ "$1" != "$2" ]]; then
|
if [[ "$1" != "$2" ]]; then
|
||||||
FAILED_FUNCS+="$function:L$lineno\n"
|
FAILED_FUNCS+="$function:L$lineno\n"
|
||||||
echo "ERROR: $1 != $2 in $function:L$lineno!"
|
echo "ERROR: $1 != $2 in $function:L$lineno!"
|
||||||
@ -49,10 +59,13 @@ function assert_equal {
|
|||||||
ERROR=$((ERROR+1))
|
ERROR=$((ERROR+1))
|
||||||
else
|
else
|
||||||
PASS=$((PASS+1))
|
PASS=$((PASS+1))
|
||||||
echo "$function:L$lineno - ok"
|
echo "PASS: $function:L$lineno - $msg"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# print a summary of passing and failing tests, exiting
|
||||||
|
# with an error if we have failed tests
|
||||||
|
# usage: report_results
|
||||||
function report_results {
|
function report_results {
|
||||||
echo "$PASS Tests PASSED"
|
echo "$PASS Tests PASSED"
|
||||||
if [[ $ERROR -gt 1 ]]; then
|
if [[ $ERROR -gt 1 ]]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user