#!/usr/bin/env bash # CONSTANTS # functions function assert { ((test_count++)) if ./poc ./test/stub/scenario.bash "$1" >/dev/null; then echo -n . else echo -n F failures+=("$1") return 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]+)" [[ "${last_error}" =~ $regex ]] && success=true # if [[ $success == true && -n "${hint_message}" ]]; then # : # fi if [[ $success == true ]]; then echo -n . else echo -n F failures+=("$1") return 1 fi } # main set -uo pipefail test_count=0 failures=() 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 last_false COMMAND_ERROR fail_type command_error COMMAND_ERROR fail_type subshell_term SUBSHELL_ERROR 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)' failed=${#failures[@]} success=$((test_count - failed)) echo if [[ $failed -gt 0 ]]; then ratio=$((100 * success / test_count)) echo "${ratio}% passed, ${test_count} tests, ${failed} failed!" echo failures: for failure in "${failures[@]}"; do echo -e "\t- $failure" done exit 1 else echo "100% passed, ${test_count} tests" fi