test 100%
This commit is contained in:
@@ -6,16 +6,31 @@ function assert {
|
||||
./test/stub/scenario.bash "$1" >/dev/null || (echo "error in: $1" && exit 1)
|
||||
}
|
||||
|
||||
function strip_ansi {
|
||||
echo "$1" | sed -E 's/\x1b\[[0-9;]*[a-zA-Z]//g'
|
||||
}
|
||||
|
||||
function fail_type {
|
||||
stderr=$(./test/stub/scenario.bash "$1" 2>&1 >/dev/null)
|
||||
code="$?"
|
||||
regex="TYPE: $2"
|
||||
[[ "$code" != 0 ]] && [[ "$stderr" =~ $regex ]] || (echo "error in: $1" && exit 1)
|
||||
local i line first error_start_above regex
|
||||
mapfile -t stderr <<<"$(./test/stub/scenario.bash "$1" 2>&1 >/dev/null)"
|
||||
# echo "stderr countains ${#stderr[@]}"
|
||||
error_start_above=false
|
||||
regex="║[[:blank:]]+([A-Z|_]+)"
|
||||
for i in "${stderr[@]}"; do
|
||||
line=$(strip_ansi "$i")
|
||||
first="${line:1:1}"
|
||||
[[ $first == ╔ ]] && error_start_above=true && continue
|
||||
if [[ "$error_start_above" == true ]]; then
|
||||
[[ $line =~ $regex ]] && [[ ${BASH_REMATCH[1]} == "$2" ]] && return 0
|
||||
echo "error in: $1" && return 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# main
|
||||
|
||||
set -euo pipefail
|
||||
assert success
|
||||
fail_type subshell_term 'SUBSHELL TERM'
|
||||
fail_type unbound_variable 'UNBOUND VARIABLE'
|
||||
fail_type false 'FALSE'
|
||||
fail_type subshell_term SUBSHELL_TERM
|
||||
fail_type unbound_variable UNBOUND_VARIABLE
|
||||
fail_type false FALSE
|
||||
echo 100% passed!
|
||||
|
||||
@@ -14,7 +14,9 @@ stack_functions=('f2' 'f1' '<main>')
|
||||
# tput rc
|
||||
# FG=RED style_ansi "\t║\n"
|
||||
# }
|
||||
|
||||
function strip_ansi {
|
||||
echo "$1" | sed -E 's/\x1b\[[0-9;]*[a-zA-Z]//g'
|
||||
}
|
||||
function ansi_block_error {
|
||||
BG=RED
|
||||
FG=BLACK
|
||||
@@ -26,7 +28,7 @@ function ansi_block_error {
|
||||
content=$(style_padding "$content")
|
||||
detail=$(BG=BLACK style_padding "$2")
|
||||
exit_code=$(FG=CYAN style_ansi " $3")
|
||||
BLOCK_CONTINUATION_COL=5 style_block "$content$detail$exit_code"
|
||||
BLOCK_CONTINUATION_COL=5 style_block "$content\t$detail$exit_code"
|
||||
ansi_reset
|
||||
FG=RED style_ansi " ║"
|
||||
echo
|
||||
@@ -59,5 +61,11 @@ function show_error {
|
||||
declare -F style_ansi >/dev/null || source "$MIAOU_BASH_DIR/lib/ansi.bash"
|
||||
|
||||
echo START
|
||||
|
||||
output=$(BG=RED style_ansi "╔")
|
||||
output=$(strip_ansi "$output")
|
||||
echo "$output"
|
||||
# echo "$output" | cat -v
|
||||
|
||||
# echo -n "standard flow:" && show_error
|
||||
echo -n "starting subshell: $(show_error)"
|
||||
# echo -n "starting subshell: $(show_error)"
|
||||
|
||||
Reference in New Issue
Block a user