Browse Source

100% passed + optional bypassed

main
pvincent 1 week ago
parent
commit
692cff2c15
  1. 73
      test/miaou-bash.test.bash

73
test/miaou-bash.test.bash

@ -61,18 +61,29 @@ function assert_grep {
function fail_type {
((test_count++))
local success regex hint_message cmd
local success regex hint_message cmd lang_options
success=false
hint_message="${3:-}"
[[ -v TEST_LANG ]] && cmd="LANG=$TEST_LANG " || cmd=''
lang_options=()
cmd="$MIAOU_BASH_DIR/test/stub/scenario.bash $1"
if [[ -v TEST_LANG ]]; then
LANG="$TEST_LANG" $cmd >/dev/null 2>"$TMP_ERR" 3>"$TMP_MIAOU"
else
$cmd >/dev/null 2>"$TMP_ERR" 3>"$TMP_MIAOU"
local locale_found=false
for gen_locale in "${GEN_LOCALES[@]}"; do
if [[ "$gen_locale" == "$TEST_LANG" ]]; then
locale_found=true
break
fi
done
if ! $locale_found; then
((test_bypassed++))
BYPASSED_LOCALES["$TEST_LANG"]=true
echo -n b
return
fi
fi
eval "${lang_options[*]} $cmd" >/dev/null 2>"$TMP_ERR" 3>"$TMP_MIAOU"
mapfile -t stderr <"$TMP_ERR"
last_error="${stderr[-1]}"
@ -88,11 +99,7 @@ function fail_type {
return
fi
echo -n F
if [[ -v TEST_LANG ]]; then
failures+=("LANG=$TEST_LANG $cmd")
else
failures+=("$cmd")
fi
failures+=("${lang_options[*]} $cmd")
return 1
}
@ -194,7 +201,12 @@ set -uo pipefail
[[ ! -v MIAOU_BASH_DIR ]] && >&2 echo MIAOU_BASH_DIR missing && builtin exit 1
test_count=0
test_bypassed=0
failures=()
declare -A BYPASSED_LOCALES=()
mapfile -t GEN_LOCALES < <(locale -a)
mkdir -p "$TMP_DIRECTORY"
TIMEFORMAT=$'\nelapsed: %Rs'
@ -208,25 +220,25 @@ time {
assert pipe1
assert pipe2
TEST_LANG=en_US.UTF-8 fail_type unbound_variable UNBOUND_VARIABLE
TEST_LANG=es_ES.UTF-8 fail_type unbound_variable UNBOUND_VARIABLE
TEST_LANG=fr_FR.UTF-8 fail_type unbound_variable UNBOUND_VARIABLE
TEST_LANG=en_US.utf8 fail_type unbound_variable UNBOUND_VARIABLE
TEST_LANG=es_ES.utf8 fail_type unbound_variable UNBOUND_VARIABLE
TEST_LANG=fr_FR.utf8 fail_type unbound_variable UNBOUND_VARIABLE
TEST_LANG=en_US.UTF-8 fail_type unbound_associative UNBOUND_VARIABLE
TEST_LANG=es_ES.UTF-8 fail_type unbound_associative UNBOUND_VARIABLE
TEST_LANG=fr_FR.UTF-8 fail_type unbound_associative UNBOUND_VARIABLE
TEST_LANG=en_US.utf8 fail_type unbound_associative UNBOUND_VARIABLE
TEST_LANG=es_ES.utf8 fail_type unbound_associative UNBOUND_VARIABLE
TEST_LANG=fr_FR.utf8 fail_type unbound_associative UNBOUND_VARIABLE
TEST_LANG=en_US.UTF-8 fail_type command_not_found COMMAND_NOT_FOUND
TEST_LANG=es_ES.UTF-8 fail_type command_not_found COMMAND_NOT_FOUND
TEST_LANG=fr_FR.UTF-8 fail_type command_not_found COMMAND_NOT_FOUND
TEST_LANG=en_US.utf8 fail_type command_not_found COMMAND_NOT_FOUND
TEST_LANG=es_ES.utf8 fail_type command_not_found COMMAND_NOT_FOUND
TEST_LANG=fr_FR.utf8 fail_type command_not_found COMMAND_NOT_FOUND
TEST_LANG=en_US.UTF-8 fail_type source_not_found SOURCE_NOT_FOUND
TEST_LANG=es_ES.UTF-8 fail_type source_not_found SOURCE_NOT_FOUND
TEST_LANG=fr_FR.UTF-8 fail_type source_not_found SOURCE_NOT_FOUND
TEST_LANG=en_US.utf8 fail_type source_not_found SOURCE_NOT_FOUND
TEST_LANG=es_ES.utf8 fail_type source_not_found SOURCE_NOT_FOUND
TEST_LANG=fr_FR.utf8 fail_type source_not_found SOURCE_NOT_FOUND
TEST_LANG=en_US.UTF-8 fail_type file_not_found FILE_NOT_FOUND
TEST_LANG=es_ES.UTF-8 fail_type file_not_found FILE_NOT_FOUND
TEST_LANG=fr_FR.UTF-8 fail_type file_not_found FILE_NOT_FOUND
TEST_LANG=en_US.utf8 fail_type file_not_found FILE_NOT_FOUND
TEST_LANG=es_ES.utf8 fail_type file_not_found FILE_NOT_FOUND
TEST_LANG=fr_FR.utf8 fail_type file_not_found FILE_NOT_FOUND
fail_type command_error COMMAND_ERROR
fail_type subshell_term SUBSHELL_ERROR
@ -251,14 +263,19 @@ time {
failed=${#failures[@]}
success=$((test_count - failed))
optional_bypassed=()
if [[ ${#BYPASSED_LOCALES[@]} -gt 0 ]]; then
optional_bypassed=(", $test_bypassed bypassed (missing locales: ${!BYPASSED_LOCALES[*]})")
fi
if [[ $failed -gt 0 ]]; then
ratio=$((100 * success / test_count))
echo "${ratio}% passed, ${test_count} tests, ${failed} failed!"
echo "${ratio}% passed, ${test_count} tests, ${failed} failed!${optional_bypassed[*]}"
echo failures:
for failure in "${failures[@]}"; do
echo -e "\t- $failure"
done
exit 1
else
echo "100% passed, ${test_count} tests"
echo "100% passed, ${test_count} tests${optional_bypassed[*]}"
fi
Loading…
Cancel
Save