From 874a3a9ef7c31d2d36d7d7fdf77a2772fd85d61d Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Wed, 20 Nov 2013 15:03:48 +1030 Subject: [PATCH] Improve test framework: shell backtraces When in a the finalise part of a test (possibly as a result of a failure or error), make sure that shell backtraces do not list the test case functions that failed, since they have already been reported in a backtrace at the point of failure --- testframework.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/testframework.sh b/testframework.sh index 4f447ad9..004d2e90 100644 --- a/testframework.sh +++ b/testframework.sh @@ -1263,7 +1263,7 @@ _tfw_fail() { _tfw_backtrace() { tfw_log '#----- shell backtrace -----' local -i up=1 - while [ "${BASH_SOURCE[$up]}" == "${BASH_SOURCE[0]}" ]; do + while [ "${BASH_SOURCE[$up]}" == "${BASH_SOURCE[0]}" -a "${FUNCNAME[$up]}" != '_tfw_finalise' ]; do let up=up+1 done local -i i=0 @@ -1307,10 +1307,14 @@ _tfw_errormsg() { local -i up=1 local -i top=${#FUNCNAME[*]} let top=top-1 - while [ $up -lt $top -a "${BASH_SOURCE[$up]}" == "${BASH_SOURCE[0]}" ]; do + while [ $up -lt $top -a "${BASH_SOURCE[$up]}" = "${BASH_SOURCE[0]}" -a "${FUNCNAME[$up]}" != '_tfw_finalise' ]; do let up=up+1 done - tfw_log "ERROR: in ${FUNCNAME[$up]}: $*" + if [ "${BASH_SOURCE[$up]}" = "${BASH_SOURCE[0]}" ]; then + tfw_log "ERROR: $*" + else + tfw_log "ERROR: in ${FUNCNAME[$up]}: $*" + fi } _tfw_error() {