Fixed tunit.sh to report test counts and times automatically like junit does, moved the totals into the footer, and updated the readme

This commit is contained in:
2012-12-19 23:05:04 -05:00
parent 79e7086bb6
commit a80407c637
2 changed files with 25 additions and 27 deletions

View File

@@ -10,13 +10,12 @@ Example output
akesterson@akesterson-pc ~/source/upstream/git/shunit akesterson@akesterson-pc ~/source/upstream/git/shunit
$ bash tests/tunit.sh $ bash tests/tunit.sh
==== 0 TESTS in 0 SECONDS : 0 ERRORS, 0 FAILURES ====
[super::class] someTest .... [OK] [super::class] someTest .... [OK]
[super::class] someOtherTest .... [FAILED] [super::class] someOtherTest .... [FAILED]
generic failure : Yo dawg, I heard you like failures generic failure : Yo dawg, I heard you like failures
This is some raw data, please read it This is some raw data, please read it
==== 2 TESTS in 0 SECONDS : 1 ERRORS, 1 FAILURES ====
akesterson@akesterson-pc ~/source/upstream/git/shunit akesterson@akesterson-pc ~/source/upstream/git/shunit
$ bash tests/junit.sh $ bash tests/junit.sh

View File

@@ -7,6 +7,11 @@
# #
# If COLOR=on, then the OK/FAIL bits are in RED or GREEN. # If COLOR=on, then the OK/FAIL bits are in RED or GREEN.
TUNIT_FAILURES=0
TUNIT_ERRORS=0
TUNIT_TESTS=0
TUNIT_TIMERSTART=$(date "+%s")
COLOR=${COLOR:-on} COLOR=${COLOR:-on}
if [ "$COLOR" == "on" ]; then if [ "$COLOR" == "on" ]; then
@@ -24,36 +29,13 @@ function tunit_header()
{ {
if [ "$1" == "--help" ]; then if [ "$1" == "--help" ]; then
cat <<EOF cat <<EOF
tunit_header(tests, errors, failures, elapsed) tunit_header()
Generate a tunit header, to display one or more tunit_testcase()s. Generate a tunit header, to display one or more tunit_testcase()s.
tests : total number of tests. Tunit doesn't have a header, so this function doesn't currently do anything.
errors : total number of errors
failures : total number of failed test cases
elapsed : The total number of seconds elapsed during testing
EOF EOF
return 1 return 1
fi fi
local tests errors failures elapsed encoding
local errcolor failcolor
tests=${1:-0}
errors=${2:-0}
failures=${3:-0}
elapsed=${4:-0}
errcolor="${COLOR_GREEN}"
failcolor="${COLOR_GREEN}"
if [ $errors -gt 0 ]; then
errcolor="${COLOR_RED}"
fi
if [ $failures -gt 0 ]; then
failcolor="${COLOR_RED}"
fi
echo
echo "==== $tests TESTS in $elapsed SECONDS : ${errcolor}$errors ERRORS${COLOR_NORMAL}, ${errcolor}$failures FAILURES${COLOR_NORMAL} ===="
} }
function tunit_footer() function tunit_footer()
@@ -66,6 +48,20 @@ function tunit_footer()
EOF EOF
return 1 return 1
fi fi
local errcolor failcolor elapsed
elapsed=$(expr $(date "+%s") - $TUNIT_TIMERSTART)
errcolor="${COLOR_GREEN}"
failcolor="${COLOR_GREEN}"
if [ $TUNIT_ERRORS -gt 0 ]; then
errcolor="${COLOR_RED}"
fi
if [ $TUNIT_FAILURES -gt 0 ]; then
failcolor="${COLOR_RED}"
fi
echo
echo "==== $TUNIT_TESTS TESTS in $elapsed SECONDS : ${errcolor}$TUNIT_ERRORS ERRORS${COLOR_NORMAL}, ${errcolor}$TUNIT_FAILURES FAILURES${COLOR_NORMAL} ===="
return 0 return 0
} }
@@ -95,8 +91,11 @@ EOF
failmsg="$5" failmsg="$5"
cdata="$6" cdata="$6"
TUNIT_TESTS=$(expr $TUNIT_TESTS + 1)
printf "[$classname] $testname .... " printf "[$classname] $testname .... "
if [ "$failtype" != "" ]; then if [ "$failtype" != "" ]; then
TUNIT_ERRORS=$(expr $TUNIT_ERRORS + 1)
TUNIT_FAILURES=$(expr $TUNIT_FAILURES + 1)
echo "${COLOR_RED}[FAILED]" echo "${COLOR_RED}[FAILED]"
echo " $failtype : $failmsg" echo " $failtype : $failmsg"
echo "$cdata" | sed s/"^"/" "/g echo "$cdata" | sed s/"^"/" "/g