Improve test framework: tfw_cat --hexdump, TFWSTDOUT

Add -h|--hexdump option to tfw_cat() and fix faulty logic in tfw_cat()
-v option wof files not ending in \n (newline)

Add TFWSTDOUT and TFWSTDERR env vars set by execute() with absolute
path names of files containing stdout and stderr respectively (as an
alternative to using replayStdout() and replayStderr()).
This commit is contained in:
Andrew Bettison 2013-11-04 15:42:37 +10:30
parent b1b5a79f6f
commit 34c5522e48

View File

@ -869,7 +869,7 @@ tfw_cmp_version() {
# context that stdout (fd 1) is redirected. # context that stdout (fd 1) is redirected.
tfw_cat() { tfw_cat() {
local header= local header=
local show_nonprinting= local -a show=(cat)
for file; do for file; do
case $file in case $file in
--header=*) --header=*)
@ -877,15 +877,19 @@ tfw_cat() {
continue continue
;; ;;
-v|--show-nonprinting) -v|--show-nonprinting)
show_nonprinting=-v show=(cat -v)
continue
;;
-h|--hexdump)
show=(hd '</dev/null')
continue continue
;; ;;
--stdout) --stdout)
file="$_tfw_process_tmp/stdout" file="${TFWSTDOUT?}"
header="${header:-stdout of ($executed)}" header="${header:-stdout of ($executed)}"
;; ;;
--stderr) --stderr)
file="$_tfw_process_tmp/stderr" file="${TFWSTDERR?}"
header="${header:-stderr of ($executed)}" header="${header:-stderr of ($executed)}"
;; ;;
*) *)
@ -894,17 +898,19 @@ tfw_cat() {
esac esac
local missing_nl= local missing_nl=
tfw_log "#----- $header -----" tfw_log "#----- $header -----"
cat $show_nonprinting "$file" >&$_tfw_log_fd eval "${show[@]}" "$file" >&$_tfw_log_fd
if [ "$(tail -1c "$file")" != "$newline" ]; then if [ "${show[0]}" = cat -a "$(tail -1c "$file" | wc -l)" -eq 0 ]; then
echo >&$_tfw_log_fd echo >&$_tfw_log_fd
missing_nl=" (no newline at end)" missing_nl=" (no newline at end)"
fi fi
tfw_log "#-----$missing_nl" tfw_log "#-----$missing_nl"
header= header=
show_nonprinting= show=(cat)
done done
} }
# Format the standard input into multi columns within an output width set by the
# COLUMNS env var.
tfw_multicolumn() { tfw_multicolumn() {
$AWK ' $AWK '
function pad(s, n) { function pad(s, n) {
@ -965,11 +971,11 @@ assertRealTime() {
} }
replayStdout() { replayStdout() {
cat $_tfw_tmp/stdout cat ${TFWSTDOUT?}
} }
replayStderr() { replayStderr() {
cat $_tfw_tmp/stderr cat ${TFWSTDERR?}
} }
assertStdoutIs() { assertStdoutIs() {
@ -1147,8 +1153,10 @@ _tfw_execute() {
ulimit -S -c unlimited ulimit -S -c unlimited
rm -f core rm -f core
fi fi
export TFWSTDOUT="$_tfw_process_tmp/stdout"
export TFWSTDERR="$_tfw_process_tmp/stderr"
{ {
time -p "$_tfw_executable" "$@" >"$_tfw_process_tmp/stdout" 2>"$_tfw_process_tmp/stderr" time -p "$_tfw_executable" "$@" >"$TFWSTDOUT" 2>"$TFWSTDERR"
} 2>"$_tfw_process_tmp/times" & } 2>"$_tfw_process_tmp/times" &
local subshell_pid=$! local subshell_pid=$!
local timer_pid= local timer_pid=
@ -1194,7 +1202,6 @@ _tfw_execute() {
# Deal with exit status. # Deal with exit status.
if [ -n "$_tfw_opt_exit_status" ]; then if [ -n "$_tfw_opt_exit_status" ]; then
_tfw_message="exit status ($_tfw_exitStatus) of ($executed) is $_tfw_opt_exit_status" _tfw_message="exit status ($_tfw_exitStatus) of ($executed) is $_tfw_opt_exit_status"
_tfw_dump_stderr_on_fail=true
_tfw_assert [ "$_tfw_exitStatus" -eq "$_tfw_opt_exit_status" ] || _tfw_failexit || return $? _tfw_assert [ "$_tfw_exitStatus" -eq "$_tfw_opt_exit_status" ] || _tfw_failexit || return $?
$_tfw_assert_noise && tfw_log "# assert $_tfw_message" $_tfw_assert_noise && tfw_log "# assert $_tfw_message"
else else