Browse Source

fix test

main
pvincent 3 days ago
parent
commit
56bc5d5a72
  1. 37
      bin/miaou-bash

37
bin/miaou-bash

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