diff --git a/bin/miaou-bash b/bin/miaou-bash index 56b2e5a..a7eae70 100755 --- a/bin/miaou-bash +++ b/bin/miaou-bash @@ -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='^" # FIXME: raise issue 'commande introuvable NBSP' within fr.po! + miaou_debug "" 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 "" 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 "" - 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 "" else - regex="$MSG_SOURCE_NOT_FOUND_REGEX" - if [[ $failure_code -eq 1 ]] && [[ "$last_error" =~ $regex ]]; then + regex=$MSG_SOURCE_NOT_FOUND_REGEX + miaou_debug "" + if [[ $failure_code == 1 ]] && [[ "$last_error" =~ $regex ]]; then failure_type='SOURCE_NOT_FOUND' failure_payload="${BASH_REMATCH[3]}" failure_code=3 diff --git a/locales/fr.sh b/locales/fr.sh index 70199b7..4999f2b 100644 --- a/locales/fr.sh +++ b/locales/fr.sh @@ -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)$' diff --git a/test/miaou-bash.test.bash b/test/miaou-bash.test.bash index a1b524b..31136f4 100755 --- a/test/miaou-bash.test.bash +++ b/test/miaou-bash.test.bash @@ -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 }