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
+1 -1
View File
@@ -9,7 +9,7 @@ function onemore {
function do_next {
echo do_next
exit 10 # youpi
exit 13 # youpi
grep nope nope
echo $nope
command_not_found
+8 -2
View File
@@ -76,14 +76,20 @@ function do_success {
return
}
function do_exit_0 {
echo success
exit 0
echo SHOULD NOT APPEAR
}
function do_success_with_args {
echo "count args: $#"
}
function do_unbound_variable {
a=5
echo "a=${a}"
echo "b=${b}"
echo -n "content: "
echo -n "a=${a} b=${b}"
}
function do_source_not_found {