test 100%
This commit is contained in:
+15
-15
@@ -3,8 +3,8 @@
|
||||
# CONSTANTS
|
||||
|
||||
MIAOU_BASH_ERROR=$(mktemp -t "$(basename "$0").XXXXXXXX" --tmpdir="/run/user/$(id -u)")
|
||||
MIAOU_BASH_DEBUG=${MIAOU_BASH_DEBUG:-false}
|
||||
readonly MIAOU_BASH_ERROR MIAOU_BASH_DEBUG
|
||||
MIAOU_DEBUG=${MIAOU_BASH_DEBUG:-false}
|
||||
readonly MIAOU_BASH_ERROR MIAOU_DEBUG
|
||||
|
||||
# FUNCTIONS
|
||||
|
||||
@@ -89,7 +89,7 @@ function on_exit {
|
||||
|
||||
# FIXME: too much tricky! (delayed stderr)
|
||||
if [[ -p /dev/stdout ]]; then
|
||||
failure_type='SUBSHELL TERM'
|
||||
failure_type='SUBSHELL_TERM'
|
||||
failure_payload="$last_error"
|
||||
|
||||
if [[ "$last_error" =~ $regex1 || "$last_error" =~ $regex2 ]]; then
|
||||
@@ -108,7 +108,7 @@ function on_exit {
|
||||
message=${BASH_REMATCH[2]}
|
||||
regex='^(.*): unbound variable$'
|
||||
if [[ $code == 1 ]] && [[ "$message" =~ $regex ]]; then
|
||||
failure_type='UNBOUND VARIABLE'
|
||||
failure_type='UNBOUND_VARIABLE'
|
||||
failure_payload="${BASH_REMATCH[1]}"
|
||||
stack_lines[0]=$line
|
||||
else
|
||||
@@ -180,7 +180,7 @@ function on_exit {
|
||||
else
|
||||
regex='^subshell term:'
|
||||
if [[ "$last_error" =~ $regex ]]; then
|
||||
failure_type='SUBSHELL TERM'
|
||||
failure_type='SUBSHELL_UNKNOWN'
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@@ -196,8 +196,8 @@ function on_exit {
|
||||
builtin exit "$code"
|
||||
}
|
||||
|
||||
function debug {
|
||||
is_true "${MIAOU_BASH_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true
|
||||
function miaou_debug {
|
||||
is_true "${MIAOU_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true
|
||||
}
|
||||
|
||||
function ansi_block_continuation {
|
||||
@@ -217,7 +217,7 @@ function ansi_block_error {
|
||||
|
||||
content=$(style_ansi "$1")
|
||||
content=$(style_padding "$content")
|
||||
detail=$(BG=BLACK style_padding "$2")
|
||||
detail=$(BG=BLACK FG=WHITE style_padding "$2")
|
||||
exit_code=$(FG=CYAN style_ansi " $3")
|
||||
printf "\r"
|
||||
BLOCK_CONTINUATION_COL=5 style_block "$content$detail$exit_code"
|
||||
@@ -249,22 +249,22 @@ function dump_failure {
|
||||
if [[ ${failure_type} == 'SUBSHELL SOURCE NOT FOUND' ]]; then
|
||||
:
|
||||
else
|
||||
debug '---error---'
|
||||
miaou_debug '---error---'
|
||||
if [[ $failure_type == 'SUBSHELL ERROR' ]]; then
|
||||
>&4 echo -e "${failure_payload}"
|
||||
else
|
||||
>&4 ansi_block_error "$failure_type" "$failure_payload" "$code"
|
||||
fi
|
||||
debug '---end of error---'
|
||||
miaou_debug '---end of error---'
|
||||
fi
|
||||
|
||||
debug '---stacktrace---'
|
||||
miaou_debug '---stacktrace---'
|
||||
>&4 ansi_traces stack_sources stack_lines stack_functions
|
||||
|
||||
# for i in "${failure_traces[@]}"; do
|
||||
# >&4 echo -e "$i"
|
||||
# done
|
||||
debug '---end of stacktrace---'
|
||||
miaou_debug '---end of stacktrace---'
|
||||
cleanup
|
||||
}
|
||||
|
||||
@@ -273,13 +273,13 @@ function dump_stderr {
|
||||
mapfile -t tmp_error <"$MIAOU_BASH_ERROR"
|
||||
is_true "$last_trim" && unset 'tmp_error[-1]' && tmp_error=("${tmp_error[@]}")
|
||||
if [[ "${#tmp_error[@]}" -gt 0 ]]; then
|
||||
debug '---stderr---'
|
||||
miaou_debug '---stderr---'
|
||||
>&4 printf '\r'
|
||||
for i in "${tmp_error[@]}"; do
|
||||
>&4 echo -e "$i"
|
||||
done
|
||||
else
|
||||
debug '---no stderr---'
|
||||
miaou_debug '---no stderr---'
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ BASH_ARGV0="$1" && shift # to pretend script runs by itself
|
||||
# magic FD + delayed tee => /dev/fd/3 means delayed stderr, /dev/fd/4 remains original stderr
|
||||
exec 3> >(tee "$MIAOU_BASH_ERROR" >/dev/null) 4>/dev/stderr
|
||||
|
||||
debug '---stdout---'
|
||||
miaou_debug '---stdout---'
|
||||
# shellcheck source=/dev/null
|
||||
source "$BASH_ARGV0" 2>&3
|
||||
dump_success
|
||||
|
||||
Reference in New Issue
Block a user