From 9880ade93bd571149eb02706377371f6cf050f4f Mon Sep 17 00:00:00 2001 From: pvincent Date: Sat, 25 Jul 2026 13:40:47 +0400 Subject: [PATCH] before subshell error test hint --- bin/miaou-bash | 6 ++++-- test/miaou-bash.test.bash | 9 +++++---- test/stub/scenario.bash | 8 ++------ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/bin/miaou-bash b/bin/miaou-bash index 283cbcb..174e945 100755 --- a/bin/miaou-bash +++ b/bin/miaou-bash @@ -168,8 +168,10 @@ function on_exit { last_trim=false # keep the last error for next stacktrace error_block=false failure_type='SUBSHELL_ERROR' - >&4 echo "SUBSHELL_ERROR caught up" - stack_functions[0]="${stack_functions[0]} (hint: prefer source than subshell:2)" + # + # >&4 echo "SUBSHELL_ERROR caught up ${BASH_SOURCE[*]} ${BASH_LINENO[*]}" + # + stack_functions[0]="${stack_functions[0]} (hint: prefer source than subshell)" [[ "${code}" == 128 ]] && failure_type='SUBSHELL_SOURCE_NOT_FOUND' else failure_type='UNDEFINED' diff --git a/test/miaou-bash.test.bash b/test/miaou-bash.test.bash index 2f4c97e..f9711f2 100755 --- a/test/miaou-bash.test.bash +++ b/test/miaou-bash.test.bash @@ -22,9 +22,10 @@ function strip_ansi { function fail_type { ((TEST_COUNT++)) - local i line first error_start_above regex + local i line first error_start_above regex hint_message + hint_message="${3:-}" mapfile -t stderr <<<"$(./test/stub/scenario.bash "$1" 2>&1 >/dev/null)" - # echo "stderr countains ${#stderr[@]}" + echo "stderr countains ${#stderr[@]}" error_start_above=false regex="║[[:blank:]]+([A-Z|_]+)" for i in "${stderr[@]}"; do @@ -40,6 +41,7 @@ function fail_type { fi fi done + [[ -n "${hint_message}" ]] && echo "hint message to find out..." echo "error in: $1" && return 1 } @@ -55,8 +57,7 @@ fail_type command_not_found COMMAND_NOT_FOUND fail_type exit EXIT fail_type source_not_found SOURCE_NOT_FOUND fail_type file_not_found FILE_NOT_FOUND -fail_type subshell_source_not_found SUBSHELL_SOURCE_NOT_FOUND -fail_type subshell_error SUBSHELL_ERROR +fail_type subshell_error COMMAND_NOT_FOUND '(hint: prefer source than subshell)' failed=$((TEST_COUNT - SUCCESS_COUNT)) diff --git a/test/stub/scenario.bash b/test/stub/scenario.bash index 2d043d3..782d1e0 100755 --- a/test/stub/scenario.bash +++ b/test/stub/scenario.bash @@ -87,17 +87,13 @@ function do_file_not_found { ./lib/fake/nope.bash } -function do_subshell_source_not_found { +function do_subshell_error { output=$(miaou_debug "---subshell1--$$ $BASHPID $PPID--") output=$(miaou_debug "---subshell2--$$ $BASHPID $PPID--") : "$output" - "${MIAOU_BASH_DIR}/test/stub/extra/library.bash" - + "$BASEDIR/extra/library.bash" } -function do_subshell_error { - : -} # FUNCTIONS function call_function_which_will_exit {