MIAOU-BASH is a collection of settings and helpers for leveraging BASH. Developer-friendly, it may be used as solo package with or without the miaou project.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

36 lines
939 B

#!/usr/bin/env bash
# functions
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 {
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
echo 100% passed!