ansi colors
This commit is contained in:
+51
-19
@@ -8,15 +8,47 @@ TMP_ERR="$TMP_DIRECTORY/_stderr"
|
||||
TMP_MIAOU="$TMP_DIRECTORY/_miaou"
|
||||
readonly TMP_DIRECTORY TMP_OUT TMP_ERR TMP_MIAOU
|
||||
|
||||
source "$MIAOU_BASH_DIR"/lib/ansi.bash # ANSI associative array
|
||||
|
||||
# functions
|
||||
|
||||
function ansi_code {
|
||||
local code
|
||||
for code in "$@"; do
|
||||
if [[ -v ANSI[$code] ]]; then
|
||||
echo -ne "\e[${ANSI[$code]}m"
|
||||
else
|
||||
>&2 echo "unknown ansi key: <$code>"
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function print_passed {
|
||||
ansi_code FG_GREEN
|
||||
echo -en '.'
|
||||
ansi_code RESET
|
||||
}
|
||||
|
||||
function print_bypassed {
|
||||
ansi_code FG_YELLOW
|
||||
echo -en 'b'
|
||||
ansi_code RESET
|
||||
}
|
||||
|
||||
function print_failed {
|
||||
ansi_code FG_RED
|
||||
echo -en 'F'
|
||||
ansi_code RESET
|
||||
}
|
||||
|
||||
function assert_tty {
|
||||
((test_count++))
|
||||
if [[ -w /dev/tty ]]; then
|
||||
echo -n .
|
||||
print_passed
|
||||
return
|
||||
fi
|
||||
echo -n F
|
||||
print_failed
|
||||
failures+=("test -w /dev/tty")
|
||||
return 1
|
||||
}
|
||||
@@ -26,11 +58,11 @@ function assert {
|
||||
cmd="$MIAOU_BASH_DIR/test/stub/scenario.bash $1"
|
||||
if $cmd >/dev/null 2>/dev/null 3>"$TMP_MIAOU"; then
|
||||
if [[ -s "$TMP_MIAOU" ]]; then
|
||||
echo -n .
|
||||
print_passed
|
||||
return
|
||||
fi
|
||||
fi
|
||||
echo -n F
|
||||
print_failed
|
||||
failures+=("$cmd")
|
||||
return 1
|
||||
}
|
||||
@@ -48,11 +80,11 @@ function assert_grep {
|
||||
cmd="$MIAOU_BASH_DIR/test/stub/scenario.bash $script"
|
||||
if $cmd "${extra_args[@]}" >"$TMP_OUT" 2>/dev/null 3>/dev/null; then
|
||||
if grep -q "$content" "$TMP_OUT"; then
|
||||
echo -n .
|
||||
print_passed
|
||||
return
|
||||
fi
|
||||
fi
|
||||
echo -n F
|
||||
print_failed
|
||||
#TODO: quote extra_args
|
||||
for i in "${extra_args[@]}"; do safe_args+=$(printf '%q ' "$i"); done
|
||||
failures+=("$cmd $safe_args")
|
||||
@@ -78,7 +110,7 @@ function fail_type {
|
||||
if ! $locale_found; then
|
||||
((test_bypassed++))
|
||||
BYPASSED_LOCALES["$TEST_LANG"]=true
|
||||
echo -n b
|
||||
print_bypassed
|
||||
return
|
||||
fi
|
||||
fi
|
||||
@@ -95,10 +127,10 @@ function fail_type {
|
||||
fi
|
||||
|
||||
if [[ $success == true ]]; then
|
||||
echo -n .
|
||||
print_passed
|
||||
return
|
||||
fi
|
||||
echo -n F
|
||||
print_failed
|
||||
failures+=("${lang_options[*]} $cmd")
|
||||
return 1
|
||||
}
|
||||
@@ -109,11 +141,11 @@ function fail_stderr_grep {
|
||||
stderr_line="$2"
|
||||
|
||||
if ! $cmd 2>"$TMP_ERR" && grep -q "$stderr_line" "$TMP_ERR"; then
|
||||
echo -n .
|
||||
print_passed
|
||||
return
|
||||
fi
|
||||
|
||||
echo -n F
|
||||
print_failed
|
||||
failures+=("$cmd 2>&1 | grep -q \"$stderr_line\"")
|
||||
return 1
|
||||
}
|
||||
@@ -126,12 +158,12 @@ function fail_stderr_count {
|
||||
if ! $cmd >/dev/null 2>"$TMP_ERR" 3>/dev/null; then
|
||||
mapfile -t stderr <"$TMP_ERR"
|
||||
if [[ "${#stderr[@]}" == "$count" ]]; then
|
||||
echo -n .
|
||||
print_passed
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -n F
|
||||
print_failed
|
||||
failures+=("$cmd 2>$TMP_ERR")
|
||||
return 1
|
||||
}
|
||||
@@ -144,12 +176,12 @@ function fail_miaou_count {
|
||||
if ! $cmd >/dev/null 2>/dev/null 3>"$TMP_MIAOU"; then
|
||||
mapfile -t miaou <"$TMP_MIAOU"
|
||||
if [[ "${#miaou[@]}" == "$count" ]]; then
|
||||
echo -n .
|
||||
print_passed
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -n F
|
||||
print_failed
|
||||
failures+=("$cmd 3>$TMP_MIAOU")
|
||||
return 1
|
||||
}
|
||||
@@ -159,7 +191,7 @@ function assert_locales_equally_populated {
|
||||
local locales_dir="$MIAOU_BASH_DIR"/locales
|
||||
local main_locale_file="$locales_dir"/"$1".sh
|
||||
if [[ ! -f $main_locale_file ]]; then
|
||||
echo -n F
|
||||
print_failed
|
||||
failures+=("missing locale file: $main_locale_file for locale: $1")
|
||||
return 1
|
||||
fi
|
||||
@@ -169,7 +201,7 @@ function assert_locales_equally_populated {
|
||||
for extra in "$@"; do
|
||||
extra_locale_file="$locales_dir"/"$extra".sh
|
||||
if [[ ! -f $extra_locale_file ]]; then
|
||||
echo -n F
|
||||
print_failed
|
||||
failures+=("missing locale file: $extra_locale_file for locale: $extra")
|
||||
return 1
|
||||
fi
|
||||
@@ -181,7 +213,7 @@ function assert_locales_equally_populated {
|
||||
if [[ ${#difference[@]} -gt 0 ]]; then
|
||||
variable_name=$(echo "${difference[1]}" | cut -d' ' -f2)
|
||||
change_type="${difference[0]}"
|
||||
echo -n F
|
||||
print_failed
|
||||
if [[ "$change_type" =~ d ]]; then
|
||||
failures+=("locale=$extra (in $extra_locale_file) misses variable (to add): ${variable_name}")
|
||||
else
|
||||
@@ -191,7 +223,7 @@ function assert_locales_equally_populated {
|
||||
fi
|
||||
done
|
||||
fi
|
||||
echo -n .
|
||||
print_passed
|
||||
}
|
||||
|
||||
# main
|
||||
|
||||
Reference in New Issue
Block a user