|
|
|
@ -2,23 +2,22 @@ |
|
|
|
|
|
|
|
# CONSTANTS |
|
|
|
|
|
|
|
TEST_COUNT=0 |
|
|
|
SUCCESS_COUNT=0 |
|
|
|
# functions |
|
|
|
|
|
|
|
function assert { |
|
|
|
((TEST_COUNT++)) |
|
|
|
((test_count++)) |
|
|
|
if ./poc ./test/stub/scenario.bash "$1" >/dev/null; then |
|
|
|
echo -n . |
|
|
|
((SUCCESS_COUNT++)) |
|
|
|
else |
|
|
|
(echo "error in: $1" && exit 1) |
|
|
|
echo -n F |
|
|
|
failures+=("$1") |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function fail_type { |
|
|
|
((TEST_COUNT++)) |
|
|
|
((test_count++)) |
|
|
|
local success regex hint_message |
|
|
|
success=false |
|
|
|
hint_message="${3:-}" |
|
|
|
@ -32,18 +31,22 @@ function fail_type { |
|
|
|
# : |
|
|
|
# fi |
|
|
|
if [[ $success == true ]]; then |
|
|
|
((SUCCESS_COUNT++)) |
|
|
|
echo -n . |
|
|
|
else |
|
|
|
echo "F error in: $1" && return 1 |
|
|
|
echo -n F |
|
|
|
failures+=("$1") |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
# main |
|
|
|
|
|
|
|
set -uo pipefail |
|
|
|
|
|
|
|
assert success |
|
|
|
test_count=0 |
|
|
|
failures=() |
|
|
|
|
|
|
|
assert success |
|
|
|
fail_type subshell_term SUBSHELL_ERROR |
|
|
|
fail_type unbound_variable 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 command_error COMMAND_ERROR |
|
|
|
|
|
|
|
failed=$((TEST_COUNT - SUCCESS_COUNT)) |
|
|
|
failed=$((test_count - ${#failures[@]})) |
|
|
|
success=$((test_count - failed)) |
|
|
|
|
|
|
|
echo |
|
|
|
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 |
|
|
|
else |
|
|
|
echo 100% passed! |
|
|
|
echo "100% passed, ${test_count} tests" |
|
|
|
fi |