miaou-bash.test.bash
This commit is contained in:
+2
-1
@@ -23,7 +23,7 @@ function on_return {
|
||||
function exit {
|
||||
code=${1:-0}
|
||||
# >&2 echo "${BASH_SOURCE[2]}: line ${BASH_LINENO[0]}: exit $@"
|
||||
>&2 echo "${BASH_SOURCE[2]}:${BASH_LINENO[0]} exit $code"
|
||||
>&2 echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} exit $code"
|
||||
debug "overridden exit $code"
|
||||
builtin exit "$code"
|
||||
}
|
||||
@@ -134,6 +134,7 @@ function on_exit {
|
||||
fi
|
||||
else
|
||||
failure_type='UNDEFINED'
|
||||
debug "last error=${last_error}"
|
||||
failure_payload="${last_error}"
|
||||
regex="^ .*:[0-9]* .*\$"
|
||||
if [[ "$last_error" =~ $regex ]]; then
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env miaou-bash
|
||||
|
||||
[[ $(./test/stub/scenario.bash unbound_variable 2>&1 1>/dev/null) =~ 'TYPE: UNBOUND VARIABLE' ]]
|
||||
@@ -52,13 +52,22 @@ function F3 {
|
||||
}
|
||||
|
||||
function usage {
|
||||
echo "USAGE: $0 <success|unbound-variable>"
|
||||
introspect_scenarii
|
||||
(
|
||||
IFS='|'
|
||||
echo "USAGE: $0 <${SCENARII[*]}>"
|
||||
)
|
||||
echo -e "\trun case scenario which performs various bash statements and mostly fails"
|
||||
echo -e "\tthese case scenarii helps testing the miaou-bash script"
|
||||
}
|
||||
|
||||
function do_success {
|
||||
echo SUCCESS
|
||||
echo -n 'SUCCESS args=['
|
||||
(
|
||||
IFS='|'
|
||||
echo -n "$*"
|
||||
)
|
||||
echo ']'
|
||||
}
|
||||
|
||||
function do_unbound_variable {
|
||||
@@ -68,35 +77,23 @@ function do_unbound_variable {
|
||||
}
|
||||
|
||||
function introspect_scenarii {
|
||||
mapfile -t SCENARII <<<"$(compgen -A function | grep ^do_)"
|
||||
mapfile -t SCENARII <<<"$(compgen -A function | grep ^do_ | sed 's/...//')"
|
||||
}
|
||||
function test_contain_item {
|
||||
local -n array=$1
|
||||
for item in "${array[@]}"; do [[ "$item" == "$2" ]] && return 0; done
|
||||
return 1
|
||||
}
|
||||
|
||||
# MAIN
|
||||
|
||||
[[ $# -eq 0 ]] && >&2 echo 'arg1 expected!' && usage && exit 1
|
||||
|
||||
scenario="$1"
|
||||
shift
|
||||
mapfile -t scenarii <<<"$(compgen -A function | grep ^do_)"
|
||||
|
||||
args=("$@")
|
||||
|
||||
echo "scenarii = ${scenarii[@]}"
|
||||
exit 0
|
||||
|
||||
echt "start of useless $0 $* ($# args)"
|
||||
if grep titi nope 2>/dev/null; then
|
||||
echo OK
|
||||
introspect_scenarii
|
||||
if test_contain_item SCENARII "$scenario"; then
|
||||
shift
|
||||
"do_${scenario}" "$@"
|
||||
else
|
||||
echo not found but ok
|
||||
(>&2 echo "scenario <${scenario}> not found!" && usage && exit 2)
|
||||
fi
|
||||
if grep titi "$BASEDIR/lib/utility.bash"; then
|
||||
echo OK
|
||||
else
|
||||
echo not found but ok
|
||||
fi
|
||||
echo question?:
|
||||
# read -r answer
|
||||
# echo "$answer"
|
||||
echo suite
|
||||
main
|
||||
echo end of useless
|
||||
Reference in New Issue
Block a user