Browse Source

miaou-bash.test.bash

main
pvincent 1 week ago
parent
commit
360fe2c134
  1. 3
      bin/miaou-bash
  2. 3
      test/miaou-bash.test.bash
  3. 49
      test/stub/scenario.bash

3
bin/miaou-bash

@ -23,7 +23,7 @@ function on_return {
function exit { function exit {
code=${1:-0} code=${1:-0}
# >&2 echo "${BASH_SOURCE[2]}: line ${BASH_LINENO[0]}: exit $@" # >&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" debug "overridden exit $code"
builtin exit "$code" builtin exit "$code"
} }
@ -134,6 +134,7 @@ function on_exit {
fi fi
else else
failure_type='UNDEFINED' failure_type='UNDEFINED'
debug "last error=${last_error}"
failure_payload="${last_error}" failure_payload="${last_error}"
regex="^ .*:[0-9]* .*\$" regex="^ .*:[0-9]* .*\$"
if [[ "$last_error" =~ $regex ]]; then if [[ "$last_error" =~ $regex ]]; then

3
test/miaou-bash.test.bash

@ -0,0 +1,3 @@
#!/usr/bin/env miaou-bash
[[ $(./test/stub/scenario.bash unbound_variable 2>&1 1>/dev/null) =~ 'TYPE: UNBOUND VARIABLE' ]]

49
test/stub/script.bash → test/stub/scenario.bash

@ -52,13 +52,22 @@ function F3 {
} }
function usage { 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 "\trun case scenario which performs various bash statements and mostly fails"
echo -e "\tthese case scenarii helps testing the miaou-bash script" echo -e "\tthese case scenarii helps testing the miaou-bash script"
} }
function do_success { function do_success {
echo SUCCESS
echo -n 'SUCCESS args=['
(
IFS='|'
echo -n "$*"
)
echo ']'
} }
function do_unbound_variable { function do_unbound_variable {
@ -68,35 +77,23 @@ function do_unbound_variable {
} }
function introspect_scenarii { 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 # MAIN
[[ $# -eq 0 ]] && >&2 echo 'arg1 expected!' && usage && exit 1 [[ $# -eq 0 ]] && >&2 echo 'arg1 expected!' && usage && exit 1
scenario="$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
else
echo not found but ok
fi
if grep titi "$BASEDIR/lib/utility.bash"; then
echo OK
introspect_scenarii
if test_contain_item SCENARII "$scenario"; then
shift
"do_${scenario}" "$@"
else else
echo not found but ok
(>&2 echo "scenario <${scenario}> not found!" && usage && exit 2)
fi fi
echo question?:
# read -r answer
# echo "$answer"
echo suite
main
echo end of useless
Loading…
Cancel
Save