pvincent 2 weeks ago
parent
commit
f2cd414660
  1. 33
      poc
  2. 12
      test/stub/scenario.bash

33
poc

@ -16,12 +16,15 @@ function is_true {
# example:
# alias toto="bash -c \"[[ \\\$MIAOU_DEBUG == 'true' ]] && echo yes \\\$* || echo nope\""
function miaou_debug {
is_true "${MIAOU_DEBUG}" && >/dev/tty builtin echo -e "\r\e[90mDEBUG <==> \e[95m$*\e[0m" || true
is_true "${MIAOU_DEBUG}" && >/dev/tty builtin echo -e "\e[90mDEBUG <==> \e[33m$*\e[0m" || true
}
function on_error {
>/dev/tty printf '\r' # force carriage return explicitly
code="${1:-100}"
miaou_debug "on_error: $code ($$ -- $BASHPID)"
if [[ $$ == "$BASHPID" ]]; then
>&2 echo "${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: command_error: ${code}"
failure_type="COMMAND_ERROR"
@ -33,19 +36,34 @@ function on_error {
}
function dump_stderr {
>&2 printf '' # force flush
miaou_debug --stderr--
mapfile -t tmp_error <"$MIAOU_BASH_ERROR"
for i in "${tmp_error[@]}"; do >&4 echo -e "$i"; done
for i in "${tmp_error[@]}"; do
echo -e "$i"
done
miaou_debug --end of stderr--
}
function dump_failure {
miaou_debug --error box--
echo FAILURE: "$failure_type"
miaou_debug --end of error box--
}
function dump_stacktrace {
miaou_debug --stacktrace--
echo stacktrace...
miaou_debug --end of stacktrace--
}
function on_exit {
code="${1:-0}"
failure_type="${failure_type:-UNDEFINED}"
dump_stderr
2>&3 >&3 dump_stderr
2>&3 >&3 dump_failure
2>&3 >&3 dump_stacktrace
miaou_debug "on_exit $code $failure_type"
}
@ -73,6 +91,7 @@ trap 'on_exit $?' EXIT
trap 'on_pipe' PIPE
echo "--SOURCE scenario ${BASHPID}"
exec 3> >(tee "$MIAOU_BASH_ERROR" >/dev/null) 4>/dev/stderr
source ./test/stub/scenario.bash subshell_term 2>&3
exec 3>/dev/stderr
2>"$MIAOU_BASH_ERROR" source ./test/stub/scenario.bash subshell_term
exec 3>-
echo "--SUCCESS scenario"

12
test/stub/scenario.bash

@ -14,15 +14,17 @@ function do_subshell_false {
function do_subshell_term {
echo -n toto est fluo
>&2 echo -n 'error in transla...'
echo first line.
# echo -n second line...
# >&2 echo stderr1
# grep none none 2>/dev/null
# echo 'toto' | grep none
# echo 'toto' | return 3
echo -n "found1=$(grep nope nope)"
echo "found1=$(grep nope nope | grep none)"
echo "found2=$(command_not_found)"
echo SHOULD NOT SHOW UP!
# echo "found1=$(grep nope nope | grep none)"
# echo "found2=$(command_not_found)"
# echo SHOULD NOT SHOW UP!
}
function do_last_false {

Loading…
Cancel
Save