diff --git a/bin/miaou-bash b/bin/miaou-bash index 8cff1a1..1913f8c 100755 --- a/bin/miaou-bash +++ b/bin/miaou-bash @@ -170,17 +170,18 @@ function on_error { elif ! is_true "$CHILD_PROCESS"; then # in main process only, not from children! - local regex2 + local regex2 source lineno funcname last_error="${tmp_error[-1]}" regex2='^[[:space:]]+miaou_trace: source=(.*) lineno=(.*) funcname=(.*)$' if [[ "$last_error" =~ $regex2 ]]; then miaou_debug "" - trace_source="${BASH_REMATCH[1]}" - trace_lineno="${BASH_REMATCH[2]}" - trace_funcname="${BASH_REMATCH[3]}" - extra_source=("$trace_source") - extra_lineno=("$trace_lineno") - extra_funcname=("$trace_funcname") + source="${BASH_REMATCH[1]}" + lineno="${BASH_REMATCH[2]}" + funcname="${BASH_REMATCH[3]}" + [[ "$funcname" == '
' ]] && funcname="$funcname (hint: prefer source than child process)" + extra_source=("$source") + extra_lineno=("$lineno") + extra_funcname=("$funcname") # miaou_debug "" # go backward for ((i = ${#tmp_error[@]} - 2; i >= 0; i--)); do @@ -190,6 +191,7 @@ function on_error { source="${BASH_REMATCH[1]}" lineno="${BASH_REMATCH[2]}" funcname="${BASH_REMATCH[3]}" + [[ "$funcname" == '
' ]] && funcname="$funcname (hint: prefer source than child process)" extra_source=("$source" "${extra_source[@]}") extra_lineno=("$lineno" "${extra_lineno[@]}") extra_funcname=("$funcname" "${extra_funcname[@]}") diff --git a/test/miaou-bash.test.bash b/test/miaou-bash.test.bash index db022ee..cc50e57 100755 --- a/test/miaou-bash.test.bash +++ b/test/miaou-bash.test.bash @@ -21,15 +21,20 @@ function fail_type { local success regex hint_message success=false hint_message="${3:-}" - mapfile -t stderr <<<"$(miaou-bash ./test/stub/scenario.bash "$1" 2>&1 >/dev/null 3>/dev/null)" - last_error="${stderr[-1]}" + # mapfile -t stderr <<<"$(miaou-bash ./test/stub/scenario.bash "$1" 2>&1 >/dev/null 3>/dev/null)" + + miaou-bash ./test/stub/scenario.bash $1 >/dev/null 2>_stderr 3>_miaou + mapfile -t stderr <_stderr + + last_error="${stderr[-1]}" regex="^(.*): line ([0-9]+): miaou_error: $2 ([0-9]+)" [[ "${last_error}" =~ $regex ]] && success=true - # if [[ $success == true && -n "${hint_message}" ]]; then - # : - # fi + if [[ $success == true && -n "${hint_message}" ]]; then + grep -q "${hint_message}" _miaou || success=false + fi + if [[ $success == true ]]; then echo -n . else @@ -58,7 +63,7 @@ fail_type exit EXIT fail_type command_not_found COMMAND_NOT_FOUND fail_type source_not_found SOURCE_NOT_FOUND fail_type file_not_found FILE_NOT_FOUND -fail_type child_error CHILD_ERROR '(hint: prefer source than subshell)' +fail_type child_error CHILD_ERROR '(hint: prefer source than child process)' failed=${#failures[@]} success=$((test_count - failed))