Improve test framework: tfw_cat and shell backtrace

tfw_cat() now behaves better if the file is missing a final newline.

Shell backtrace lines no longer prefixed with log prefix (timestamp).
This commit is contained in:
Andrew Bettison 2012-09-28 15:30:47 +09:30
parent d26c3f67e8
commit d8f06d0582

View File

@ -590,31 +590,37 @@ tfw_cat() {
local show_nonprinting= local show_nonprinting=
for file; do for file; do
case $file in case $file in
--header=*)
header="${1#*=}"
continue
;;
-v|--show-nonprinting)
show_nonprinting=-v
continue
;;
--stdout) --stdout)
tfw_log "#----- ${header:-stdout of ($executed)} -----" file="$_tfw_tmp/stdout"
cat $show_nonprinting $_tfw_tmp/stdout header="${header:-stdout of ($executed)}"
tfw_log "#-----"
header=
show_nonprinting=
;; ;;
--stderr) --stderr)
tfw_log "#----- ${header:-stderr of ($executed)} -----" file="$_tfw_tmp/stderr"
cat $show_nonprinting $_tfw_tmp/stderr header="${header:-stderr of ($executed)}"
tfw_log "#-----"
header=
show_nonprinting=
;; ;;
--header=*) header="${1#*=}";;
-v|--show-nonprinting) show_nonprinting=-v;;
*) *)
tfw_log "#----- ${header:-${file#$_tfw_tmp/}} -----" header="${header:-${file#$_tfw_tmp/}}"
cat $show_nonprinting "$file"
tfw_log "#-----"
header=
show_nonprinting=
;; ;;
esac esac
done >&$_tfw_log_fd local missing_nl=
tfw_log "#----- $header -----"
cat $show_nonprinting "$file" >&$_tfw_log_fd
if [ "$(tail -1c "$file")" != "$newline" ]; then
echo >&$_tfw_log_fd
missing_nl=" (no newline at end)"
fi
tfw_log "#-----$missing_nl"
header=
show_nonprinting=
done
} }
tfw_core_backtrace() { tfw_core_backtrace() {
@ -1265,14 +1271,14 @@ _tfw_failmsg() {
} }
_tfw_backtrace() { _tfw_backtrace() {
tfw_log '#----- backtrace -----' tfw_log '#----- shell backtrace -----'
local -i up=1 local -i up=1
while [ "${BASH_SOURCE[$up]}" == "${BASH_SOURCE[0]}" ]; do while [ "${BASH_SOURCE[$up]}" == "${BASH_SOURCE[0]}" ]; do
let up=up+1 let up=up+1
done done
local -i i=0 local -i i=0
while [ $up -lt ${#FUNCNAME[*]} -a "${BASH_SOURCE[$up]}" != "${BASH_SOURCE[0]}" ]; do while [ $up -lt ${#FUNCNAME[*]} -a "${BASH_SOURCE[$up]}" != "${BASH_SOURCE[0]}" ]; do
tfw_log "[$i] ${FUNCNAME[$(($up-1))]}() called from ${FUNCNAME[$up]}() at line ${BASH_LINENO[$(($up-1))]} of ${BASH_SOURCE[$up]}" echo "[$i] ${FUNCNAME[$(($up-1))]}() called from ${FUNCNAME[$up]}() at line ${BASH_LINENO[$(($up-1))]} of ${BASH_SOURCE[$up]}" >&$_tfw_log_fd
let up=up+1 let up=up+1
let i=i+1 let i=i+1
done done