test elapsed time

This commit is contained in:
pvincent
2026-08-01 11:59:01 +04:00
parent 2e595ef217
commit eb06c0e061
5 changed files with 78 additions and 65 deletions
+27 -22
View File
@@ -6,13 +6,15 @@
function assert {
((test_count++))
if miaou-bash ./test/stub/scenario.bash "$1" >/dev/null; then
echo -n .
else
echo -n F
failures+=("$1")
return 1
if miaou-bash ./test/stub/scenario.bash "$1" >/dev/null 2>/dev/null 3>_miaou; then
if [[ -s _miaou ]]; then
echo -n .
return
fi
fi
echo -n F
failures+=("$1")
return 1
}
# assert performing '$1:script' successfully + output must contain '$2:content'
@@ -71,32 +73,35 @@ set -uo pipefail
test_count=0
failures=()
assert success
assert_grep success_with_args 'count args: 2' -- 'A B' C
TIMEFORMAT=$'\nelapsed: %Rs'
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 child_error CHILD_ERROR 'prefer source than child process'
time {
assert success
assert exit_0
assert_grep success_with_args 'count args: 2' -- 'A B' C
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 child_error CHILD_ERROR 'prefer source than child process'
}
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"
echo -e "\t- $failure => replay: ./test/stub/scenario.bash $failure"
done
exit 1
else