Browse Source

improved test.poc.bash

main
pvincent 2 weeks ago
parent
commit
8733eb995f
  1. 34
      test/poc.test.bash

34
test/poc.test.bash

@ -2,23 +2,22 @@
# CONSTANTS # CONSTANTS
TEST_COUNT=0
SUCCESS_COUNT=0
# functions # functions
function assert { function assert {
((TEST_COUNT++))
((test_count++))
if ./poc ./test/stub/scenario.bash "$1" >/dev/null; then if ./poc ./test/stub/scenario.bash "$1" >/dev/null; then
echo -n . echo -n .
((SUCCESS_COUNT++))
else else
(echo "error in: $1" && exit 1)
echo -n F
failures+=("$1")
return 1
fi fi
} }
function fail_type { function fail_type {
((TEST_COUNT++))
((test_count++))
local success regex hint_message local success regex hint_message
success=false success=false
hint_message="${3:-}" hint_message="${3:-}"
@ -32,18 +31,22 @@ function fail_type {
# : # :
# fi # fi
if [[ $success == true ]]; then if [[ $success == true ]]; then
((SUCCESS_COUNT++))
echo -n . echo -n .
else else
echo "F error in: $1" && return 1
echo -n F
failures+=("$1")
return 1
fi fi
} }
# main # main
set -uo pipefail set -uo pipefail
assert success
test_count=0
failures=()
assert success
fail_type subshell_term SUBSHELL_ERROR fail_type subshell_term SUBSHELL_ERROR
fail_type unbound_variable UNBOUND_VARIABLE fail_type unbound_variable UNBOUND_VARIABLE
fail_type unbound_associative UNBOUND_VARIABLE fail_type unbound_associative UNBOUND_VARIABLE
@ -57,13 +60,18 @@ fail_type command_not_found COMMAND_NOT_FOUND
# fail_type subshell_error COMMAND_NOT_FOUND '(hint: prefer source than subshell)' # fail_type subshell_error COMMAND_NOT_FOUND '(hint: prefer source than subshell)'
# fail_type command_error COMMAND_ERROR # fail_type command_error COMMAND_ERROR
failed=$((TEST_COUNT - SUCCESS_COUNT))
failed=$((test_count - ${#failures[@]}))
success=$((test_count - failed))
echo echo
if [[ $failed -gt 0 ]]; then if [[ $failed -gt 0 ]]; then
ratio=$((100 * SUCCESS_COUNT / TEST_COUNT))
echo "${ratio}% passed, $SUCCESS_COUNT succeeded, $failed failed!"
ratio=$((100 * success / test_count))
echo "${ratio}% passed, $success succeeded, $failed failed!"
echo failures:
for failure in "${failures[@]}"; do
echo -e "\t- $failure"
done
exit 1 exit 1
else else
echo 100% passed!
echo "100% passed, ${test_count} tests"
fi fi
Loading…
Cancel
Save