miaou-bash replaced by poc

This commit is contained in:
pvincent
2026-07-29 23:29:20 +04:00
parent b44c523323
commit 062461e61e
6 changed files with 813 additions and 812 deletions
+83
View File
@@ -0,0 +1,83 @@
#!/usr/bin/env bash
# CONSTANTS
TEST_COUNT=0
SUCCESS_COUNT=0
# functions
function assert {
((TEST_COUNT++))
if ./test/stub/scenario.bash "$1" >/dev/null; then
((SUCCESS_COUNT++))
else
(echo "error in: $1" && exit 1)
fi
}
function strip_ansi {
echo "$1" | sed -E 's/\x1b\[[0-9;]*[a-zA-Z]//g'
}
function fail_type {
((TEST_COUNT++))
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[@]}"
error_start_above=false
success=false
regex="║[[:blank:]]+([A-Z|_]+)"
for i in "${!stderr[@]}"; do
line=$(strip_ansi "${stderr[$i]}")
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
success=false
regex="╟─⟶.*(\(.*\))$"
for j in $(seq "$((i + 1))" "$((${#stderr[@]} - 1))"); do
line=$(strip_ansi "${stderr[$j]}")
if [[ $line =~ $regex ]]; then
[[ "${BASH_REMATCH[1]}" == "${hint_message}" ]] && success=true
break
fi
done
fi
if [[ $success == true ]]; then
((SUCCESS_COUNT++))
else
echo "error in: $1" && return 1
fi
}
# main
set -uo pipefail
assert success
fail_type subshell_term SUBSHELL_TERM
fail_type unbound_variable UNBOUND_VARIABLE
fail_type false FALSE
fail_type return RETURN
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_error COMMAND_NOT_FOUND '(hint: prefer source than subshell)'
fail_type command_error COMMAND_ERROR
failed=$((TEST_COUNT - SUCCESS_COUNT))
if [[ $failed -gt 0 ]]; then
ratio=$((100 * SUCCESS_COUNT / TEST_COUNT))
echo "${ratio}% passed, $SUCCESS_COUNT succeeded, $failed failed!"
exit 1
else
echo 100% passed!
fi
+42 -47
View File
@@ -2,82 +2,77 @@
# CONSTANTS
TEST_COUNT=0
SUCCESS_COUNT=0
# functions
function assert {
((TEST_COUNT++))
if ./test/stub/scenario.bash "$1" >/dev/null; then
((SUCCESS_COUNT++))
((test_count++))
if miaou-bash ./test/stub/scenario.bash "$1" >/dev/null; then
echo -n .
else
(echo "error in: $1" && exit 1)
echo -n F
failures+=("$1")
return 1
fi
}
function strip_ansi {
echo "$1" | sed -E 's/\x1b\[[0-9;]*[a-zA-Z]//g'
}
function fail_type {
((TEST_COUNT++))
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[@]}"
error_start_above=false
((test_count++))
local success regex hint_message
success=false
regex="║[[:blank:]]+([A-Z|_]+)"
for i in "${!stderr[@]}"; do
line=$(strip_ansi "${stderr[$i]}")
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
hint_message="${3:-}"
# mapfile -t stderr <<<"$(source ./test/stub/scenario.bash "$1" 2>&1 >/dev/null 3>/dev/null)"
mapfile -t stderr <<<"$(miaou-bash ./test/stub/scenario.bash "$1" 2>&1 >/dev/null 3>/dev/null)"
last_error="${stderr[-1]}"
if [[ $success == true && -n "${hint_message}" ]]; then
success=false
regex="╟─⟶.*(\(.*\))$"
for j in $(seq "$((i + 1))" "$((${#stderr[@]} - 1))"); do
line=$(strip_ansi "${stderr[$j]}")
if [[ $line =~ $regex ]]; then
[[ "${BASH_REMATCH[1]}" == "${hint_message}" ]] && success=true
break
fi
done
fi
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 ]]; then
((SUCCESS_COUNT++))
echo -n .
else
echo "error in: $1" && return 1
echo -n F
failures+=("$1")
return 1
fi
}
# main
set -uo pipefail
test_count=0
failures=()
assert success
fail_type subshell_term SUBSHELL_TERM
fail_type subshell_term SUBSHELL_ERROR
fail_type unbound_variable UNBOUND_VARIABLE
fail_type unbound_associative UNBOUND_VARIABLE
fail_type false FALSE
fail_type return RETURN
fail_type command_not_found COMMAND_NOT_FOUND
fail_type last_false COMMAND_ERROR
fail_type command_error COMMAND_ERROR
fail_type subshell_term SUBSHELL_ERROR
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 subshell_error COMMAND_NOT_FOUND '(hint: prefer source than subshell)'
fail_type command_error COMMAND_ERROR
failed=$((TEST_COUNT - SUCCESS_COUNT))
failed=${#failures[@]}
success=$((test_count - failed))
echo
if [[ $failed -gt 0 ]]; then
ratio=$((100 * SUCCESS_COUNT / TEST_COUNT))
echo "${ratio}% passed, $SUCCESS_COUNT succeeded, $failed failed!"
ratio=$((100 * success / test_count))
echo "${ratio}% passed, ${test_count} tests, ${failed} failed!"
echo failures:
for failure in "${failures[@]}"; do
echo -e "\t- $failure"
done
exit 1
else
echo 100% passed!
echo "100% passed, ${test_count} tests"
fi
-77
View File
@@ -1,77 +0,0 @@
#!/usr/bin/env bash
# CONSTANTS
# functions
function assert {
((test_count++))
if ./poc ./test/stub/scenario.bash "$1" >/dev/null; then
echo -n .
else
echo -n F
failures+=("$1")
return 1
fi
}
function fail_type {
((test_count++))
local success regex hint_message
success=false
hint_message="${3:-}"
mapfile -t stderr <<<"$(./poc ./test/stub/scenario.bash "$1" 2>&1 >/dev/null 3>/dev/null)"
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 ]]; then
echo -n .
else
echo -n F
failures+=("$1")
return 1
fi
}
# main
set -uo pipefail
test_count=0
failures=()
assert success
fail_type subshell_term SUBSHELL_ERROR
fail_type unbound_variable UNBOUND_VARIABLE
fail_type unbound_associative UNBOUND_VARIABLE
fail_type false FALSE
fail_type last_false COMMAND_ERROR
fail_type command_error COMMAND_ERROR
fail_type subshell_term SUBSHELL_ERROR
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 subshell_error COMMAND_NOT_FOUND '(hint: prefer source than subshell)'
failed=${#failures[@]}
success=$((test_count - failed))
echo
if [[ $failed -gt 0 ]]; then
ratio=$((100 * success / test_count))
echo "${ratio}% passed, ${test_count} tests, ${failed} failed!"
echo failures:
for failure in "${failures[@]}"; do
echo -e "\t- $failure"
done
exit 1
else
echo "100% passed, ${test_count} tests"
fi