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
| ... | ... |
@@ -19,7 +19,8 @@ function test_trueorfalse {
|
| 19 | 19 |
|
| 20 | 20 |
for default in True False; do |
| 21 | 21 |
for name in one captrue lowtrue uppertrue capyes lowyes upperyes; do |
| 22 |
- assert_equal "True" $(trueorfalse $default $name) "\$(trueorfalse $default $name)" |
|
| 22 |
+ local msg="trueorfalse($default $name)" |
|
| 23 |
+ assert_equal "True" $(trueorfalse $default $name) "$msg" |
|
| 23 | 24 |
done |
| 24 | 25 |
done |
| 25 | 26 |
|
| ... | ... |
@@ -33,7 +34,8 @@ function test_trueorfalse {
|
| 33 | 33 |
|
| 34 | 34 |
for default in True False; do |
| 35 | 35 |
for name in zero capfalse lowfalse upperfalse capno lowno upperno; do |
| 36 |
- assert_equal "False" $(trueorfalse $default $name) "\$(trueorfalse $default $name)" |
|
| 36 |
+ local msg="trueorfalse($default $name)" |
|
| 37 |
+ assert_equal "False" $(trueorfalse $default $name) "$msg" |
|
| 37 | 38 |
done |
| 38 | 39 |
done |
| 39 | 40 |
} |
| ... | ... |
@@ -17,6 +17,8 @@ ERROR=0 |
| 17 | 17 |
PASS=0 |
| 18 | 18 |
FAILED_FUNCS="" |
| 19 | 19 |
|
| 20 |
+# pass a test, printing out MSG |
|
| 21 |
+# usage: passed message |
|
| 20 | 22 |
function passed {
|
| 21 | 23 |
local lineno=$(caller 0 | awk '{print $1}')
|
| 22 | 24 |
local function=$(caller 0 | awk '{print $2}')
|
| ... | ... |
@@ -25,9 +27,11 @@ function passed {
|
| 25 | 25 |
msg="OK" |
| 26 | 26 |
fi |
| 27 | 27 |
PASS=$((PASS+1)) |
| 28 |
- echo $function:L$lineno $msg |
|
| 28 |
+ echo "PASS: $function:L$lineno $msg" |
|
| 29 | 29 |
} |
| 30 | 30 |
|
| 31 |
+# fail a test, printing out MSG |
|
| 32 |
+# usage: failed message |
|
| 31 | 33 |
function failed {
|
| 32 | 34 |
local lineno=$(caller 0 | awk '{print $1}')
|
| 33 | 35 |
local function=$(caller 0 | awk '{print $2}')
|
| ... | ... |
@@ -38,10 +42,16 @@ function failed {
|
| 38 | 38 |
ERROR=$((ERROR+1)) |
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 |
+# assert string comparision of val1 equal val2, printing out msg |
|
| 42 |
+# usage: assert_equal val1 val2 msg |
|
| 41 | 43 |
function assert_equal {
|
| 42 | 44 |
local lineno=`caller 0 | awk '{print $1}'`
|
| 43 | 45 |
local function=`caller 0 | awk '{print $2}'`
|
| 44 | 46 |
local msg=$3 |
| 47 |
+ |
|
| 48 |
+ if [ -z "$msg" ]; then |
|
| 49 |
+ msg="OK" |
|
| 50 |
+ fi |
|
| 45 | 51 |
if [[ "$1" != "$2" ]]; then |
| 46 | 52 |
FAILED_FUNCS+="$function:L$lineno\n" |
| 47 | 53 |
echo "ERROR: $1 != $2 in $function:L$lineno!" |
| ... | ... |
@@ -49,10 +59,13 @@ function assert_equal {
|
| 49 | 49 |
ERROR=$((ERROR+1)) |
| 50 | 50 |
else |
| 51 | 51 |
PASS=$((PASS+1)) |
| 52 |
- echo "$function:L$lineno - ok" |
|
| 52 |
+ echo "PASS: $function:L$lineno - $msg" |
|
| 53 | 53 |
fi |
| 54 | 54 |
} |
| 55 | 55 |
|
| 56 |
+# print a summary of passing and failing tests, exiting |
|
| 57 |
+# with an error if we have failed tests |
|
| 58 |
+# usage: report_results |
|
| 56 | 59 |
function report_results {
|
| 57 | 60 |
echo "$PASS Tests PASSED" |
| 58 | 61 |
if [[ $ERROR -gt 1 ]]; then |