From 6fb25d217df852e146de13f226311107eac35553 Mon Sep 17 00:00:00 2001 From: pvincent Date: Mon, 27 Jul 2026 14:47:15 +0400 Subject: [PATCH] arg0 --- poc | 19 ++++++++++++------- test/stub/scenario.bash | 13 +++++++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/poc b/poc index ce4549d..c5c5091 100755 --- a/poc +++ b/poc @@ -86,13 +86,14 @@ function dump_stacktrace { function on_exit { code="${1:-0}" - failure_type="${failure_type:-UNDEFINED}" 2>&3 >&3 dump_stderr - 2>&3 >&3 dump_failure - 2>&3 >&3 dump_stacktrace + if [[ -v failure_type ]]; then + 2>&3 >&3 dump_failure + 2>&3 >&3 dump_stacktrace + fi - miaou_debug "on_exit $code $failure_type" + miaou_debug "on_exit $code" } function on_pipe { @@ -131,12 +132,16 @@ set -euo pipefail set -E # HALT on subshell error # set -T # DEBUG RETURN +[[ $# -lt 1 ]] && >&2 echo 'ERROR: script expected!' && builtin exit 1 +BASH_ARGV0="$1" && shift # to pretend script runs by itself + trap 'on_error $?' ERR trap 'on_exit $?' EXIT trap 'on_pipe' PIPE -echo "--SOURCE scenario ${BASHPID}" +miaou_debug "--source from ${BASHPID}" exec 3>/dev/stderr -2>"$MIAOU_BASH_ERROR" source ./test/stub/scenario.bash subshell_term +# shellcheck source=/dev/null +2>"$MIAOU_BASH_ERROR" source "$BASH_ARGV0" exec 3>- -echo "--SUCCESS scenario" +miaou_debug '--source success' diff --git a/test/stub/scenario.bash b/test/stub/scenario.bash index 0bd908d..ecb4aa2 100755 --- a/test/stub/scenario.bash +++ b/test/stub/scenario.bash @@ -165,10 +165,15 @@ function usage { introspect_scenarii ( IFS='|' - echo "USAGE: $0 <${SCENARII[*]}>" + echo "USAGE: $0 " ) - echo -e "\trun case scenario which performs various bash statements and mostly fails" - echo -e "\tthese case scenarii helps testing the miaou-bash script" + echo -e "\trun a case scenario built from various bash statements and mostly ends up on failure" + echo -e "\tthese case scenarii provide the help suite needed for \`miaou-bash\`" + echo -e "\there is the list of available case scenario:" + local i + for i in "${SCENARII[@]}"; do + echo -e "\t- $i" + done } function introspect_scenarii { @@ -183,7 +188,7 @@ function test_contain_item { # MAIN -[[ $# -eq 0 ]] && >&2 echo 'arg1 expected!' && usage && exit 1 +[[ $# -eq 0 ]] && >&2 echo ' required!' && usage && exit 1 scenario="$1" introspect_scenarii