#
# $Id$
#
-# Ethereal - Network traffic analyzer
-# By Gerald Combs <gerald@ethereal.com>
+# Wireshark - Network traffic analyzer
+# By Gerald Combs <gerald@wireshark.org>
# Copyright 2005 Ulf Lamping
#
# This program is free software; you can redistribute it and/or
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
+#
# References:
# coloring the output
-color_reset="tput sgr0"
-color_green='\E[32;40m'
-color_red='\E[31;40m'
-color_blue='\E[36;40m'
+if [ $USE_COLOR -eq 1 ] ; then
+ color_reset="tput sgr0"
+ color_green='\E[32;40m'
+ color_red='\E[31;40m'
+ color_yellow='\E[33;40m'
+ color_blue='\E[36;40m'
+else
+ color_reset="/bin/true"
+ color_green=''
+ color_red=''
+ color_yellow=''
+ color_blue=''
+fi
# runtime flags
TEST_RUN="OFF"
# output counters
TEST_OK=0 # global count of succeeded steps
TEST_FAILED=0 # global count of failed steps
+TEST_SKIPPED=0 # global count of failed steps
+TEST_STEP_PRE_CB=
TEST_STEP_POST_CB=
# level number of this test item (suite or step)
test_level() {
- LIMIT=100
-
- for ((a=0; a <= LIMIT ; a++))
+ LIMIT_LEVEL=100
+
+ for ((a=0; a <= LIMIT_LEVEL ; a++))
do
if [ ! $a -eq 0 ]; then
echo -n "."
#echo "end"
return
fi
- done
+ done
}
# set output format
# run the actual test suite
$2
-
+
# results
if [ $TEST_RUN = "ON" ]; then
echo ""
echo "Ok : $TEST_OK"
echo -n -e $color_red
echo "Failed: $TEST_FAILED"
+ echo -n -e $color_yellow
+ echo "Skipped: $TEST_SKIPPED"
$color_reset
fi
- # exit status
- #if [ $TEST_FAILED -eq 0 ]; then
- # exit 0
- #else
- # exit 1
- #fi
-
TEST_RUN="OFF"
+
+ # exit status
+ if [ $TEST_FAILED -eq 0 ]; then
+ return 0
+ else
+ return 1
+ fi
}
# show this test suite subitems
$2
-
+
echo ""
}
test_suite_add() {
# increase step counter of this nesting level
let "TEST_STEPS[$TEST_NESTING_LEVEL] += 1"
-
+
if [ $TEST_RUN = "ON" ]; then
echo ""
fi
-
- # title output if we'll list the subitems
+
+ # title output if we'll list the subitems
if [[ $TEST_RUN = "ON" ]]; then
echo -n -e $color_blue
test_level
# reset test step counter back to zero
TEST_STEP=0
-
+
# call the suites function
let "TEST_NESTING_LEVEL += 1"
TEST_STEPS[$TEST_NESTING_LEVEL]=0
test_level
echo " Suite: $1 (${TEST_STEPS[TEST_NESTING_LEVEL+1]} subitems)"
$color_reset
- fi
+ fi
}
if [[ ($TEST_RUN = "ON" && $TEST_OUTPUT = "DOTTED") && $TEST_NESTING_LEVEL -eq 0 ]]; then
echo ""
fi
-
+
if [[ ( $TEST_RUN = "ON" && $TEST_OUTPUT = "VERBOSE" ) || $TEST_NESTING_LEVEL -eq 0 ]]; then
echo -n -e $color_blue
test_level
$color_reset
fi
- if [ $TEST_RUN = "ON" ]; then
+ if [ $TEST_RUN = "ON" ]; then
+ # preprecessing step
+ $TEST_STEP_PRE_CB
#echo "command: "$2" opt1: "$3" opt2: "$4" opt3: "$5" opt4: "$6" opt5: "$7
TEST_STEP_NAME=$1
# actually run the command to test now
- $2
+ $2
#"$3" "$4" "$5" "$6" "$7"
+ # post precessing step
$TEST_STEP_POST_CB
else
if [[ $TEST_NESTING_LEVEL -eq 0 ]]; then
}
-# set the a post processing function
+# set the preprocessing function
+# $1 remark
+test_step_set_pre() {
+ TEST_STEP_PRE_CB=$1
+}
+
+# set the post processing function
# $1 remark
test_step_set_post() {
TEST_STEP_POST_CB=$1
if [[ $TEST_RUN = "ON" && $TEST_OUTPUT = "DOTTED" ]]; then
echo ""
fi
-
+
# remark
echo -n -e $color_blue
echo " Remark: $1"
test_step_ok() {
# count appearance
let "TEST_OK += 1"
-
+
# output in green
echo -n -e $color_green
-
+
if [ $TEST_OUTPUT = "VERBOSE" ]; then
echo " Ok"
else
echo -n .
fi
-
+
$color_reset
}
# $1 output text
test_step_failed() {
let "TEST_FAILED += 1"
-
+
# output in red
echo -n -e "$color_red"
-
+
echo ""
echo "\"$TEST_STEP_NAME\" Failed!"
echo $1
-
+
$color_reset
-
+
exit 1
-
+
# XXX - add a mechanism to optionally stop here
}
+# the test step succeeded
+test_step_skipped() {
+ # count appearance
+ let "TEST_SKIPPED += 1"
+
+ # output in green
+ echo -n -e $color_yellow
+
+ if [ $TEST_OUTPUT = "VERBOSE" ]; then
+ echo " Skipped"
+ else
+ echo -n .
+ fi
+
+ $color_reset
+}
+
+test_step_output_print() {
+ wait
+ printf "\n"
+ for f in "$@"; do
+ if [[ -f "$f" ]]; then
+ printf " --> $f\n"
+ cat "$f"
+ printf " <--\n"
+ else
+ printf " --> $f: doesn't exist (or isn't a file)\n"
+ fi
+ done
+}
+
+## Emacs
+## Local Variables:
+## tab-width: 8
+## indent-tabs-mode: t
+## sh-basic-offset: 8
+## End: