fix test
This commit is contained in:
+18
-19
@@ -3,8 +3,8 @@
|
|||||||
# CONSTANTS
|
# CONSTANTS
|
||||||
|
|
||||||
MIAOU_BASH_ERROR=$(mktemp -t "$(basename "$0").XXXXXXXX" --tmpdir="/run/user/$(id -u)")
|
MIAOU_BASH_ERROR=$(mktemp -t "$(basename "$0").XXXXXXXX" --tmpdir="/run/user/$(id -u)")
|
||||||
MIAOU_DEBUG=${MIAOU_BASH_DEBUG:-false}
|
MIAOU_BASH_DEBUG=${MIAOU_BASH_DEBUG:-false}
|
||||||
readonly MIAOU_BASH_ERROR MIAOU_DEBUG
|
readonly MIAOU_BASH_ERROR MIAOU_BASH_DEBUG
|
||||||
|
|
||||||
# FUNCTIONS
|
# FUNCTIONS
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ function on_exit {
|
|||||||
else
|
else
|
||||||
regex='^(.*): command not found$'
|
regex='^(.*): command not found$'
|
||||||
if [[ "$message" =~ $regex ]]; then
|
if [[ "$message" =~ $regex ]]; then
|
||||||
failure_type='COMMAND NOT FOUND'
|
failure_type='COMMAND_NOT_FOUND'
|
||||||
failure_payload="${BASH_REMATCH[1]}"
|
failure_payload="${BASH_REMATCH[1]}"
|
||||||
else
|
else
|
||||||
regex='^exit'
|
regex='^exit'
|
||||||
@@ -139,12 +139,12 @@ function on_exit {
|
|||||||
if [[ "$message" =~ $regex ]]; then
|
if [[ "$message" =~ $regex ]]; then
|
||||||
failure_payload="${BASH_REMATCH[1]}"
|
failure_payload="${BASH_REMATCH[1]}"
|
||||||
if [[ $code == 1 ]]; then
|
if [[ $code == 1 ]]; then
|
||||||
failure_type='SOURCE NOT FOUND'
|
failure_type='SOURCE_NOT_FOUND'
|
||||||
stack_lines[0]=$line
|
stack_lines[0]=$line
|
||||||
code=128 # change code to 128 to remember this embedded 'source not found' issue!
|
code=128 # change code to 128 to remember this embedded 'source not found' issue!
|
||||||
else
|
else
|
||||||
if [[ $code == 127 ]]; then
|
if [[ $code == 127 ]]; then
|
||||||
failure_type='FILE NOT FOUND'
|
failure_type='FILE_NOT_FOUND'
|
||||||
regex='\.sh$|\.bash$'
|
regex='\.sh$|\.bash$'
|
||||||
if [[ "$failure_payload" =~ $regex ]]; then
|
if [[ "$failure_payload" =~ $regex ]]; then
|
||||||
stack_functions[0]="${stack_functions[0]} (hint: prefer source than subshell:1)"
|
stack_functions[0]="${stack_functions[0]} (hint: prefer source than subshell:1)"
|
||||||
@@ -155,7 +155,7 @@ function on_exit {
|
|||||||
# >&2 echo "${last_error}"
|
# >&2 echo "${last_error}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
failure_type='UNKNOWN NOT FOUND'
|
failure_type='UNKNOWN_NOT_FOUND'
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -171,16 +171,16 @@ function on_exit {
|
|||||||
regex="^ .*:[0-9]* .*\$"
|
regex="^ .*:[0-9]* .*\$"
|
||||||
if [[ "$last_error" =~ $regex ]]; then
|
if [[ "$last_error" =~ $regex ]]; then
|
||||||
if [[ "${code}" == 128 ]]; then
|
if [[ "${code}" == 128 ]]; then
|
||||||
failure_type='SUBSHELL SOURCE NOT FOUND'
|
failure_type='SUBSHELL_SOURCE_NOT_FOUND'
|
||||||
stack_functions[0]="${stack_functions[0]} (hint: prefer source than subshell:2)"
|
stack_functions[0]="${stack_functions[0]} (hint: prefer source than subshell:2)"
|
||||||
else
|
else
|
||||||
failure_type='SUBSHELL ERROR'
|
failure_type='SUBSHELL_ERROR'
|
||||||
stack_functions[0]="${stack_functions[0]} (hint: prefer source than subshell:3)"
|
stack_functions[0]="${stack_functions[0]} (hint: prefer source than subshell:3)"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
regex='^subshell term:'
|
regex='^subshell term:'
|
||||||
if [[ "$last_error" =~ $regex ]]; then
|
if [[ "$last_error" =~ $regex ]]; then
|
||||||
failure_type='SUBSHELL_UNKNOWN'
|
failure_type='SUBSHELL_TERM2'
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -196,8 +196,8 @@ function on_exit {
|
|||||||
builtin exit "$code"
|
builtin exit "$code"
|
||||||
}
|
}
|
||||||
|
|
||||||
function miaou_debug {
|
function debug {
|
||||||
is_true "${MIAOU_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true
|
is_true "${MIAOU_BASH_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true
|
||||||
}
|
}
|
||||||
|
|
||||||
function ansi_block_continuation {
|
function ansi_block_continuation {
|
||||||
@@ -221,7 +221,6 @@ function ansi_block_error {
|
|||||||
exit_code=$(FG=CYAN style_ansi " $3")
|
exit_code=$(FG=CYAN style_ansi " $3")
|
||||||
printf "\r"
|
printf "\r"
|
||||||
BLOCK_CONTINUATION_COL=5 style_block "$content$detail$exit_code"
|
BLOCK_CONTINUATION_COL=5 style_block "$content$detail$exit_code"
|
||||||
# echo "$content$detail$exit_code"
|
|
||||||
ansi_reset
|
ansi_reset
|
||||||
FG=RED style_ansi " ║"
|
FG=RED style_ansi " ║"
|
||||||
echo
|
echo
|
||||||
@@ -249,22 +248,22 @@ function dump_failure {
|
|||||||
if [[ ${failure_type} == 'SUBSHELL SOURCE NOT FOUND' ]]; then
|
if [[ ${failure_type} == 'SUBSHELL SOURCE NOT FOUND' ]]; then
|
||||||
:
|
:
|
||||||
else
|
else
|
||||||
miaou_debug '---error---'
|
debug '---error---'
|
||||||
if [[ $failure_type == 'SUBSHELL ERROR' ]]; then
|
if [[ $failure_type == 'SUBSHELL ERROR' ]]; then
|
||||||
>&4 echo -e "${failure_payload}"
|
>&4 echo -e "${failure_payload}"
|
||||||
else
|
else
|
||||||
>&4 ansi_block_error "$failure_type" "$failure_payload" "$code"
|
>&4 ansi_block_error "$failure_type" "$failure_payload" "$code"
|
||||||
fi
|
fi
|
||||||
miaou_debug '---end of error---'
|
debug '---end of error---'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
miaou_debug '---stacktrace---'
|
debug '---stacktrace---'
|
||||||
>&4 ansi_traces stack_sources stack_lines stack_functions
|
>&4 ansi_traces stack_sources stack_lines stack_functions
|
||||||
|
|
||||||
# for i in "${failure_traces[@]}"; do
|
# for i in "${failure_traces[@]}"; do
|
||||||
# >&4 echo -e "$i"
|
# >&4 echo -e "$i"
|
||||||
# done
|
# done
|
||||||
miaou_debug '---end of stacktrace---'
|
debug '---end of stacktrace---'
|
||||||
cleanup
|
cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,13 +272,13 @@ function dump_stderr {
|
|||||||
mapfile -t tmp_error <"$MIAOU_BASH_ERROR"
|
mapfile -t tmp_error <"$MIAOU_BASH_ERROR"
|
||||||
is_true "$last_trim" && unset 'tmp_error[-1]' && tmp_error=("${tmp_error[@]}")
|
is_true "$last_trim" && unset 'tmp_error[-1]' && tmp_error=("${tmp_error[@]}")
|
||||||
if [[ "${#tmp_error[@]}" -gt 0 ]]; then
|
if [[ "${#tmp_error[@]}" -gt 0 ]]; then
|
||||||
miaou_debug '---stderr---'
|
debug '---stderr---'
|
||||||
>&4 printf '\r'
|
>&4 printf '\r'
|
||||||
for i in "${tmp_error[@]}"; do
|
for i in "${tmp_error[@]}"; do
|
||||||
>&4 echo -e "$i"
|
>&4 echo -e "$i"
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
miaou_debug '---no stderr---'
|
debug '---no stderr---'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,7 +306,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
|
# 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
|
exec 3> >(tee "$MIAOU_BASH_ERROR" >/dev/null) 4>/dev/stderr
|
||||||
|
|
||||||
miaou_debug '---stdout---'
|
debug '---stdout---'
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
source "$BASH_ARGV0" 2>&3
|
source "$BASH_ARGV0" 2>&3
|
||||||
dump_success
|
dump_success
|
||||||
|
|||||||
Reference in New Issue
Block a user