poc.test.bash 1

This commit is contained in:
pvincent
2026-07-29 00:12:35 +04:00
parent 347f6c60f5
commit 36c4906045
+19 -33
View File
@@ -19,38 +19,23 @@ function assert {
function fail_type { function fail_type {
((TEST_COUNT++)) ((TEST_COUNT++))
local i line first error_start_above regex hint_message local success regex hint_message
hint_message="${3:-}"
mapfile -t stderr <<<"$(./test/stub/scenario.bash "$1" 2>&1 >/dev/null)"
# echo "stderr countains ${#stderr[@]}"
error_start_above=false
success=false success=false
regex="║[[:blank:]]+([A-Z|_]+)" hint_message="${3:-}"
for i in "${!stderr[@]}"; do mapfile -t stderr <<<"$(./poc ./test/stub/scenario.bash "$1" 2>&1 >/dev/null 3>/dev/null)"
line=$(strip_ansi "${stderr[$i]}") last_error="${stderr[-1]}"
first="${line:1:1}"
[[ $first ==]] && error_start_above=true && continue
if [[ "$error_start_above" == true ]]; then
[[ $line =~ $regex ]] && [[ ${BASH_REMATCH[1]} == "$2" ]] && success=true
break
fi
done
if [[ $success == true && -n "${hint_message}" ]]; then regex="^(.*): line ([0-9]+): miaou_error: $2 ([0-9]+) payload: (.*)\$"
success=false [[ "${last_error}" =~ $regex ]] && success=true
regex="╟─⟶.*(\(.*\))$"
for j in $(seq "$((i + 1))" "$((${#stderr[@]} - 1))"); do # if [[ $success == true && -n "${hint_message}" ]]; then
line=$(strip_ansi "${stderr[$j]}") # :
if [[ $line =~ $regex ]]; then # fi
[[ "${BASH_REMATCH[1]}" == "${hint_message}" ]] && success=true
break
fi
done
fi
if [[ $success == true ]]; then if [[ $success == true ]]; then
((SUCCESS_COUNT++)) ((SUCCESS_COUNT++))
echo -n .
else else
echo "error in: $1" && return 1 echo "F error in: $1" && return 1
fi fi
} }
@@ -58,12 +43,13 @@ function fail_type {
set -uo pipefail set -uo pipefail
assert success assert success
# fail_type subshell_term SUBSHELL_TERM fail_type subshell_term SUBSHELL_ERROR
# fail_type unbound_variable UNBOUND_VARIABLE fail_type unbound_variable UNBOUND_VARIABLE
# fail_type false FALSE fail_type unbound_associative UNBOUND_VARIABLE
# fail_type return RETURN fail_type false FALSE
# fail_type command_not_found COMMAND_NOT_FOUND fail_type return RETURN
# fail_type exit EXIT fail_type exit EXIT
fail_type command_not_found COMMAND_NOT_FOUND
# fail_type source_not_found SOURCE_NOT_FOUND # fail_type source_not_found SOURCE_NOT_FOUND
# fail_type file_not_found FILE_NOT_FOUND # fail_type file_not_found FILE_NOT_FOUND
# fail_type subshell_error COMMAND_NOT_FOUND '(hint: prefer source than subshell)' # fail_type subshell_error COMMAND_NOT_FOUND '(hint: prefer source than subshell)'