refactored test
This commit is contained in:
+9
-18
@@ -29,18 +29,8 @@ function exit {
|
||||
}
|
||||
|
||||
function on_usr1 {
|
||||
last_error=$(tail -n1 "$MIAOU_BASH_ERROR")
|
||||
cleanup
|
||||
regex='subshell term: ([0-9]*)'
|
||||
if [[ "$last_error" =~ $regex ]]; then
|
||||
code="${BASH_REMATCH[1]}"
|
||||
debug "on_usr1 code=${code}"
|
||||
builtin exit "${code}"
|
||||
else
|
||||
debug "on_usr1 unknown last error: $last_error"
|
||||
builtin exit 200
|
||||
fi
|
||||
# >&2 echo "${BASH_SOURCE[2]}: line ${BASH_LINENO[0]}: subshell termination $code from ${FUNCNAME[1]}"
|
||||
builtin exit 1
|
||||
}
|
||||
|
||||
function on_return {
|
||||
@@ -89,17 +79,21 @@ function on_exit {
|
||||
failure_payload=''
|
||||
|
||||
if [[ $code -gt 0 ]]; then
|
||||
|
||||
last_error=$(tail -n1 "$MIAOU_BASH_ERROR")
|
||||
last_source=${stack_sources[0]}
|
||||
last_source=${last_source//./"\."} # replace '.' with '\.'
|
||||
regex1="^$last_source: line ([0-9]+): (.*)\$"
|
||||
regex2="^$last_source:([0-9]+) (.*)\$"
|
||||
|
||||
# FIXME: too much tricky
|
||||
# FIXME: too much tricky! (delayed stderr)
|
||||
if [[ -p /dev/stdout ]]; then
|
||||
last_error="subshell term: $code"
|
||||
>&2 echo "$last_error"
|
||||
failure_type='SUBSHELL TERM'
|
||||
failure_payload="$last_error"
|
||||
last_error="${BASH_SOURCE[1]}:${BASH_LINENO[0]} subshell term $code"
|
||||
kill -USR1 $$
|
||||
else
|
||||
failure_type='UNKNOWN'
|
||||
fi
|
||||
|
||||
# debug "last_error=[$last_error] <=> ${last_source}"
|
||||
@@ -159,9 +153,6 @@ function on_exit {
|
||||
failure_type='UNKNOWN NOT FOUND'
|
||||
fi
|
||||
fi
|
||||
else
|
||||
failure_type='UNKNOWN'
|
||||
failure_payload="${message}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@@ -169,7 +160,7 @@ function on_exit {
|
||||
fi
|
||||
fi
|
||||
else
|
||||
failure_type='UNDEFINED'
|
||||
# failure_type='UNDEFINED'
|
||||
debug "last error=${last_error}"
|
||||
failure_payload="${last_error}"
|
||||
regex="^ .*:[0-9]* .*\$"
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
# do not use miaou-bash as the shebang
|
||||
|
||||
./test/stub/scenario.bash success >/dev/null
|
||||
[[ $(./test/stub/scenario.bash unbound_variable 2>&1 1>/dev/null) =~ 'TYPE: UNBOUND VARIABLE' ]]
|
||||
[[ $(./test/stub/scenario.bash false 2>&1 1>/dev/null) =~ 'TYPE: FALSE' ]]
|
||||
# functions
|
||||
|
||||
function assert {
|
||||
./test/stub/scenario.bash "$1" >/dev/null || (echo "error in: $1" && exit 1)
|
||||
}
|
||||
|
||||
function fail_type {
|
||||
stderr=$(./test/stub/scenario.bash "$1" 2>&1 >/dev/null)
|
||||
code="$?"
|
||||
regex="TYPE: $2"
|
||||
[[ "$code" != 0 ]] && [[ "$stderr" =~ $regex ]] || (echo "error in: $1" && exit 1)
|
||||
}
|
||||
|
||||
# main
|
||||
|
||||
assert success
|
||||
fail_type subshell_term 'SUBSHELL TERM'
|
||||
fail_type unbound_variable 'UNBOUND VARIABLE'
|
||||
fail_type false 'FALSE'
|
||||
|
||||
@@ -10,6 +10,8 @@ readonly BASEDIR
|
||||
function do_subshell_term {
|
||||
# grep nope nope
|
||||
echo "found=$(grep nope nope)"
|
||||
echo "found=$(command_not_found)"
|
||||
command_not_found
|
||||
}
|
||||
|
||||
function do_last_false {
|
||||
|
||||
Reference in New Issue
Block a user