100% tests
This commit is contained in:
+10
-10
@@ -20,10 +20,8 @@ function is_true {
|
|||||||
function miaou_debug {
|
function miaou_debug {
|
||||||
if is_true "${MIAOU_DEBUG}"; then
|
if is_true "${MIAOU_DEBUG}"; then
|
||||||
local saved_bash_rematch=("${BASH_REMATCH[@]}") # important when regex are used before calling miaou_debug
|
local saved_bash_rematch=("${BASH_REMATCH[@]}") # important when regex are used before calling miaou_debug
|
||||||
local i message="$*" padding=''
|
local regex i message="$*" padding='' compute_hierarchy=true
|
||||||
local compute_hierarchy=true
|
|
||||||
[[ ! -v miaou_debug_hierarchy ]] && miaou_debug_hierarchy=0
|
[[ ! -v miaou_debug_hierarchy ]] && miaou_debug_hierarchy=0
|
||||||
|
|
||||||
regex='^</' # starts with </
|
regex='^</' # starts with </
|
||||||
[[ $miaou_debug_hierarchy -gt 0 ]] &&
|
[[ $miaou_debug_hierarchy -gt 0 ]] &&
|
||||||
[[ "${message}" =~ $regex ]] &&
|
[[ "${message}" =~ $regex ]] &&
|
||||||
@@ -133,16 +131,16 @@ function on_error {
|
|||||||
if [[ "$MIAOU_LOCALE" == 'fr' ]]; then
|
if [[ "$MIAOU_LOCALE" == 'fr' ]]; then
|
||||||
NBSP=$'\xc2\xa0'
|
NBSP=$'\xc2\xa0'
|
||||||
last_error="${last_error//$NBSP/ }"
|
last_error="${last_error//$NBSP/ }"
|
||||||
miaou_debug "<strip_nbsp locale=$MIAOU_LOCALE/>" # FIXME: raise issue 'commande introuvable NBSP' within fr.po!
|
miaou_debug "<strip_nbsp locale=$MIAOU_LOCALE/>"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
regex="$MSG_COMMAND_NOT_FOUND_REGEX"
|
regex=$MSG_COMMAND_NOT_FOUND_REGEX
|
||||||
if [[ $failure_code == 127 && "$last_error" =~ $regex ]]; then
|
if [[ $failure_code == 127 && "$last_error" =~ $regex ]]; then
|
||||||
failure_type='COMMAND_NOT_FOUND'
|
failure_type='COMMAND_NOT_FOUND'
|
||||||
failure_payload="${BASH_REMATCH[3]}"
|
failure_payload="${BASH_REMATCH[3]}"
|
||||||
miaou_debug "<command_not_found payload=${failure_payload}/>"
|
miaou_debug "<command_not_found payload=${failure_payload}/>"
|
||||||
else
|
else
|
||||||
regex="$MSG_FILE_NOT_FOUND_REGEX"
|
regex=$MSG_FILE_NOT_FOUND_REGEX
|
||||||
if [[ $failure_code == 127 && "$last_error" =~ $regex ]]; then
|
if [[ $failure_code == 127 && "$last_error" =~ $regex ]]; then
|
||||||
failure_type='FILE_NOT_FOUND'
|
failure_type='FILE_NOT_FOUND'
|
||||||
failure_payload="${BASH_REMATCH[3]}"
|
failure_payload="${BASH_REMATCH[3]}"
|
||||||
@@ -495,9 +493,10 @@ function on_exit {
|
|||||||
elif [[ ! -v failure_type ]]; then
|
elif [[ ! -v failure_type ]]; then
|
||||||
if [[ ${#tmp_error[@]} -gt 0 ]]; then
|
if [[ ${#tmp_error[@]} -gt 0 ]]; then
|
||||||
last_error="${tmp_error[-1]}"
|
last_error="${tmp_error[-1]}"
|
||||||
|
|
||||||
miaou_debug "<investigate_tmp_error_pass2 last={$last_error}>"
|
miaou_debug "<investigate_tmp_error_pass2 last={$last_error}>"
|
||||||
regex="$MSG_UNBOUND_VARIABLE_REGEX"
|
regex=$MSG_UNBOUND_VARIABLE_REGEX
|
||||||
if [[ $failure_code -eq 1 ]] && [[ "$last_error" =~ $regex ]]; then
|
if [[ $failure_code == 1 ]] && [[ "$last_error" =~ $regex ]]; then
|
||||||
failure_type='UNBOUND_VARIABLE'
|
failure_type='UNBOUND_VARIABLE'
|
||||||
failure_payload="${BASH_REMATCH[3]}"
|
failure_payload="${BASH_REMATCH[3]}"
|
||||||
failure_code=2
|
failure_code=2
|
||||||
@@ -512,8 +511,9 @@ function on_exit {
|
|||||||
add_miaou_error "$source" "$line" "${failure_code}" "${failure_type}" "${failure_payload}"
|
add_miaou_error "$source" "$line" "${failure_code}" "${failure_type}" "${failure_payload}"
|
||||||
miaou_debug "<unbound_variable source=${source} line=${line} payload=${failure_payload}/>"
|
miaou_debug "<unbound_variable source=${source} line=${line} payload=${failure_payload}/>"
|
||||||
else
|
else
|
||||||
regex="$MSG_SOURCE_NOT_FOUND_REGEX"
|
regex=$MSG_SOURCE_NOT_FOUND_REGEX
|
||||||
if [[ $failure_code -eq 1 ]] && [[ "$last_error" =~ $regex ]]; then
|
miaou_debug "<try failure_code=$failure_code source_not_found=$regex/>"
|
||||||
|
if [[ $failure_code == 1 ]] && [[ "$last_error" =~ $regex ]]; then
|
||||||
failure_type='SOURCE_NOT_FOUND'
|
failure_type='SOURCE_NOT_FOUND'
|
||||||
failure_payload="${BASH_REMATCH[3]}"
|
failure_payload="${BASH_REMATCH[3]}"
|
||||||
failure_code=3
|
failure_code=3
|
||||||
|
|||||||
+2
-2
@@ -6,5 +6,5 @@ MSG_UNBOUND_VARIABLE_REGEX='^(.*): ligne ([0-9]+): (.*) : variable sans liaison$
|
|||||||
# extra ' ' + weird NBSP (removed programmatically) => raise issue fr.po too
|
# extra ' ' + weird NBSP (removed programmatically) => raise issue fr.po too
|
||||||
MSG_COMMAND_NOT_FOUND_REGEX='^(.*): ligne ([0-9]+): (.*) : commande introuvable$'
|
MSG_COMMAND_NOT_FOUND_REGEX='^(.*): ligne ([0-9]+): (.*) : commande introuvable$'
|
||||||
|
|
||||||
MSG_FILE_NOT_FOUND_REGEX='^(.*): ligne ([0-9]+): (.*): Aucun fichier ou dossier de ce nom$'
|
MSG_FILE_NOT_FOUND_REGEX='^(.*): ligne ([0-9]+): (.*): Aucun fichier ou dossier de ce (nom|type)$'
|
||||||
MSG_SOURCE_NOT_FOUND_REGEX='^(.*): ligne ([0-9]+): (.*): Aucun fichier ou dossier de ce nom$'
|
MSG_SOURCE_NOT_FOUND_REGEX='^(.*): ligne ([0-9]+): (.*): Aucun fichier ou dossier de ce (nom|type)$'
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ function fail_type {
|
|||||||
for gen_locale in "${GEN_LOCALES[@]}"; do
|
for gen_locale in "${GEN_LOCALES[@]}"; do
|
||||||
if [[ "$gen_locale" == "$TEST_LANG" ]]; then
|
if [[ "$gen_locale" == "$TEST_LANG" ]]; then
|
||||||
locale_found=true
|
locale_found=true
|
||||||
|
lang_options+=("LANG=$TEST_LANG")
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -136,18 +137,25 @@ function fail_type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fail_stderr_grep {
|
function fail_stderr_grep {
|
||||||
|
declare -a lang_options=()
|
||||||
|
if [[ -v TEST_LANG ]]; then
|
||||||
|
lang_options+=("LANG=$TEST_LANG")
|
||||||
|
fi
|
||||||
|
|
||||||
((test_count++))
|
((test_count++))
|
||||||
cmd="$MIAOU_BASH_DIR/test/stub/scenario.bash $1"
|
cmd="$MIAOU_BASH_DIR/test/stub/scenario.bash $1"
|
||||||
stderr_line="$2"
|
stderr_line="$2"
|
||||||
|
|
||||||
if ! $cmd 2>"$TMP_ERR" && grep -q "$stderr_line" "$TMP_ERR"; then
|
if ! eval "${lang_options[*]} $cmd" 2>"$TMP_ERR" 3>/dev/null && grep -q "$stderr_line" "$TMP_ERR"; then
|
||||||
print_passed
|
print_passed
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
print_failed
|
print_failed
|
||||||
failures+=("$cmd 2>&1 | grep -q \"$stderr_line\"")
|
# failures+=("$cmd 2>&1 | grep -q \"$stderr_line\"")
|
||||||
|
failures+=("${lang_options[*]} $cmd 2>&1 3>/dev/null | grep -q \"$stderr_line\"")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fail_stderr_count {
|
function fail_stderr_count {
|
||||||
@@ -289,6 +297,7 @@ time {
|
|||||||
fail_stderr_grep two_options 'ERROR: too many args 2, either single option or SCRIPT + args accepted!'
|
fail_stderr_grep two_options 'ERROR: too many args 2, either single option or SCRIPT + args accepted!'
|
||||||
fail_stderr_grep script_not_found "ERROR: script 'doesnt_exist' not found!"
|
fail_stderr_grep script_not_found "ERROR: script 'doesnt_exist' not found!"
|
||||||
fail_stderr_grep no_script 'ERROR: script expected!'
|
fail_stderr_grep no_script 'ERROR: script expected!'
|
||||||
|
TEST_LANG=zh_CN.UTF-8 fail_stderr_grep file_not_found FILE_NOT_FOUND
|
||||||
|
|
||||||
assert_locales_equally_populated en es fr
|
assert_locales_equally_populated en es fr
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user