100% tests
This commit is contained in:
+10
-10
@@ -20,10 +20,8 @@ function is_true {
|
||||
function miaou_debug {
|
||||
if is_true "${MIAOU_DEBUG}"; then
|
||||
local saved_bash_rematch=("${BASH_REMATCH[@]}") # important when regex are used before calling miaou_debug
|
||||
local i message="$*" padding=''
|
||||
local compute_hierarchy=true
|
||||
local regex i message="$*" padding='' compute_hierarchy=true
|
||||
[[ ! -v miaou_debug_hierarchy ]] && miaou_debug_hierarchy=0
|
||||
|
||||
regex='^</' # starts with </
|
||||
[[ $miaou_debug_hierarchy -gt 0 ]] &&
|
||||
[[ "${message}" =~ $regex ]] &&
|
||||
@@ -133,16 +131,16 @@ function on_error {
|
||||
if [[ "$MIAOU_LOCALE" == 'fr' ]]; then
|
||||
NBSP=$'\xc2\xa0'
|
||||
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
|
||||
|
||||
regex="$MSG_COMMAND_NOT_FOUND_REGEX"
|
||||
regex=$MSG_COMMAND_NOT_FOUND_REGEX
|
||||
if [[ $failure_code == 127 && "$last_error" =~ $regex ]]; then
|
||||
failure_type='COMMAND_NOT_FOUND'
|
||||
failure_payload="${BASH_REMATCH[3]}"
|
||||
miaou_debug "<command_not_found payload=${failure_payload}/>"
|
||||
else
|
||||
regex="$MSG_FILE_NOT_FOUND_REGEX"
|
||||
regex=$MSG_FILE_NOT_FOUND_REGEX
|
||||
if [[ $failure_code == 127 && "$last_error" =~ $regex ]]; then
|
||||
failure_type='FILE_NOT_FOUND'
|
||||
failure_payload="${BASH_REMATCH[3]}"
|
||||
@@ -495,9 +493,10 @@ function on_exit {
|
||||
elif [[ ! -v failure_type ]]; then
|
||||
if [[ ${#tmp_error[@]} -gt 0 ]]; then
|
||||
last_error="${tmp_error[-1]}"
|
||||
|
||||
miaou_debug "<investigate_tmp_error_pass2 last={$last_error}>"
|
||||
regex="$MSG_UNBOUND_VARIABLE_REGEX"
|
||||
if [[ $failure_code -eq 1 ]] && [[ "$last_error" =~ $regex ]]; then
|
||||
regex=$MSG_UNBOUND_VARIABLE_REGEX
|
||||
if [[ $failure_code == 1 ]] && [[ "$last_error" =~ $regex ]]; then
|
||||
failure_type='UNBOUND_VARIABLE'
|
||||
failure_payload="${BASH_REMATCH[3]}"
|
||||
failure_code=2
|
||||
@@ -512,8 +511,9 @@ function on_exit {
|
||||
add_miaou_error "$source" "$line" "${failure_code}" "${failure_type}" "${failure_payload}"
|
||||
miaou_debug "<unbound_variable source=${source} line=${line} payload=${failure_payload}/>"
|
||||
else
|
||||
regex="$MSG_SOURCE_NOT_FOUND_REGEX"
|
||||
if [[ $failure_code -eq 1 ]] && [[ "$last_error" =~ $regex ]]; then
|
||||
regex=$MSG_SOURCE_NOT_FOUND_REGEX
|
||||
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_payload="${BASH_REMATCH[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
|
||||
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_SOURCE_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|type)$'
|
||||
|
||||
@@ -104,6 +104,7 @@ function fail_type {
|
||||
for gen_locale in "${GEN_LOCALES[@]}"; do
|
||||
if [[ "$gen_locale" == "$TEST_LANG" ]]; then
|
||||
locale_found=true
|
||||
lang_options+=("LANG=$TEST_LANG")
|
||||
break
|
||||
fi
|
||||
done
|
||||
@@ -136,18 +137,25 @@ function fail_type {
|
||||
}
|
||||
|
||||
function fail_stderr_grep {
|
||||
declare -a lang_options=()
|
||||
if [[ -v TEST_LANG ]]; then
|
||||
lang_options+=("LANG=$TEST_LANG")
|
||||
fi
|
||||
|
||||
((test_count++))
|
||||
cmd="$MIAOU_BASH_DIR/test/stub/scenario.bash $1"
|
||||
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
|
||||
return
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
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 script_not_found "ERROR: script 'doesnt_exist' not found!"
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user