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.

67 lines
1.5 KiB

#!/usr/bin/env bash
# CONSTANTS
TEST_COUNT=0
SUCCESS_COUNT=0
# functions
function assert {
((TEST_COUNT++))
if ./poc ./test/stub/scenario.bash "$1" >/dev/null; then
echo -n .
((SUCCESS_COUNT++))
else
(echo "error in: $1" && exit 1)
fi
}
function fail_type {
((TEST_COUNT++))
local success regex hint_message
success=false
hint_message="${3:-}"
mapfile -t stderr <<<"$(./poc ./test/stub/scenario.bash "$1" 2>&1 >/dev/null 3>/dev/null)"
last_error="${stderr[-1]}"
regex="^(.*): line ([0-9]+): miaou_error: $2 ([0-9]+) payload: (.*)\$"
[[ "${last_error}" =~ $regex ]] && success=true
# if [[ $success == true && -n "${hint_message}" ]]; then
# :
# fi
if [[ $success == true ]]; then
((SUCCESS_COUNT++))
echo -n .
else
echo "F error in: $1" && return 1
fi
}
# main
set -uo pipefail
assert success
fail_type subshell_term SUBSHELL_ERROR
fail_type unbound_variable UNBOUND_VARIABLE
fail_type unbound_associative UNBOUND_VARIABLE
fail_type false FALSE
fail_type return RETURN
fail_type exit EXIT
fail_type command_not_found COMMAND_NOT_FOUND
# fail_type source_not_found SOURCE_NOT_FOUND
# fail_type file_not_found FILE_NOT_FOUND
# fail_type subshell_error COMMAND_NOT_FOUND '(hint: prefer source than subshell)'
# fail_type command_error COMMAND_ERROR
failed=$((TEST_COUNT - SUCCESS_COUNT))
echo
if [[ $failed -gt 0 ]]; then
ratio=$((100 * SUCCESS_COUNT / TEST_COUNT))
echo "${ratio}% passed, $SUCCESS_COUNT succeeded, $failed failed!"
exit 1
else
echo 100% passed!
fi