diff --git a/bin/miaou-bash b/bin/miaou-bash index 1bbc137..3062b6b 100755 --- a/bin/miaou-bash +++ b/bin/miaou-bash @@ -8,6 +8,10 @@ readonly MIAOU_BASH_ERROR MIAOU_BASH_DEBUG # FUNCTIONS +function is_true { + [[ "${1,,}" =~ ^(true|yes|1)$ ]] +} + # overridden function which permits backtracing of original `return` statement function false { >&2 echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} false" @@ -178,8 +182,7 @@ function on_exit { } function debug { - [[ "${MIAOU_BASH_DEBUG}" == true ]] && >/dev/tty echo "*********** DEBUG: $*" || - true + is_true "${MIAOU_BASH_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true } function dump_failure { @@ -206,9 +209,9 @@ function dump_failure { function dump_stderr { last_trim=${1:-false} mapfile -t tmp_error <"$MIAOU_BASH_ERROR" - $last_trim && unset 'tmp_error[-1]' && tmp_error=("${tmp_error[@]}") + is_true "$last_trim" && unset 'tmp_error[-1]' && tmp_error=("${tmp_error[@]}") if [[ "${#tmp_error[@]}" -gt 0 ]]; then - $MIAOU_BASH_DEBUG && >/dev/tty echo '---stderr---' + debug '---stderr---' for i in "${tmp_error[@]}"; do >&4 echo -e "$i" done diff --git a/test/miaou-bash.test.bash b/test/miaou-bash.test.bash index 5b36257..65b1c8d 100755 --- a/test/miaou-bash.test.bash +++ b/test/miaou-bash.test.bash @@ -1,3 +1,6 @@ #!/usr/bin/env bash +# do not use miaou-bash as the shebang +./test/stub/scenario.bash success >/dev/null [[ $(./test/stub/scenario.bash unbound_variable 2>&1 1>/dev/null) =~ 'TYPE: UNBOUND VARIABLE' ]] +[[ $(./test/stub/scenario.bash false 2>&1 1>/dev/null) =~ 'TYPE: FALSE' ]] diff --git a/test/stub/scenario.bash b/test/stub/scenario.bash index 4117235..526218b 100755 --- a/test/stub/scenario.bash +++ b/test/stub/scenario.bash @@ -30,7 +30,7 @@ function do_success { source "${MIAOU_BASH_DIR}/lib/ansi.bash" local content content=$(PADDING_LEFT=2 PADDING_RIGHT=6 style_padding 'this is success') - content=$(FG=PURPLE BG=GRAY style_ansi "$content") + content=$(FG=YELLOW BG=BLUE style_ansi "$content") FG=BLACK BG=RED PADDING=8 style_block "$content" }