regex_time="[0-9]{2}-[0-9]{2}\s{1}[0-9]{2}:[0-9]{2}:[0-9]{2}"
regex_timezone="[\+-]{1}[0-9]{4}"
+for PARAM in always auto none never; do
+ for PRIO in info error; do
+ for OUTPUT in pipe tty; do
+ if [[ "$PARAM" == "always" ]]; then
+ COLOR_EXPECTED=1
+ elif [[ "$PARAM" == "never" ]]; then
+ COLOR_EXPECTED=0
+ elif [[ "$OUTPUT" == "tty" ]]; then
+ COLOR_EXPECTED=1
+ else
+ COLOR_EXPECTED=0
+ fi
+
+ if [[ "$PRIO" == "info" ]]; then
+ REGEX="s/^I\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
+ elif [[ "$COLOR_EXPECTED" -eq 0 ]]; then
+ REGEX="s/^E\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
+ else
+ REGEX="s/^~\[31;1mE\([0-9[:space:]]{5,}\) ~\[0m[[:print:]]*~\[31;1m \([[:print:]]*\)@~\[0m$/1/g"
+ fi
+
+ # -t 1 instead of | head -n 1 because the `script` command can't cope with SIGPIPE.
+ COMMAND="$cmd_prefix $format -t 1"
+
+ if [[ "$PARAM" == "none" ]]; then
+ LOG_DETAILS="testing if color output is correct (implicit --color=auto/$PRIO priority/$OUTPUT output)"
+ else
+ COMMAND="$COMMAND --color=$PARAM"
+ LOG_DETAILS="testing if color output is correct (--color=$PARAM/$PRIO priority/$OUTPUT output)"
+ fi
+
+ if [[ "$PRIO" == "info" ]]; then
+ COMMAND="$COMMAND '*:=I'"
+ else
+ COMMAND="$COMMAND '*:=E'"
+ fi
+
+ if [[ "$OUTPUT" == "tty" ]]; then
+ # This emulates a TTY. The sed call is because `script` likes to mess up the output for some reason.
+ COMMAND="script -qc\"$COMMAND\" /dev/null | sed 's/\r$//'"
+ fi
+
+ # `eval` is needed since `$COMMAND` may contain `"`
+ line=`eval $COMMAND | tr '\033\n' '~@'`
+ [[ `echo "$line" | sed -re "$REGEX"` == "1" ]] && ok || fail
+ done
+ done
+done
+# TODO: It would be cool to also test warning messages (which have a different color),
+# but this would require deeper changes to this script, which is already janky enough.
+
REGEX="s/^$regex_prio\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)$/1/g"
LOG_DETAILS="testing if \"$format\" print format works"
line=`$cmd_prefix $format | $cmd_postfix`