From: Jiri J. <jja...@re...> - 2014-09-23 09:46:20
|
Signed-off-by: Jiri Jaburek <jja...@re...> --- audit-test/utils/envcheck | 13 +++++++------ audit-test/utils/run.bash | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/audit-test/utils/envcheck b/audit-test/utils/envcheck index 7c0e490..a09b60f 100755 --- a/audit-test/utils/envcheck +++ b/audit-test/utils/envcheck @@ -60,6 +60,7 @@ # $3 = optional cmd text to show instead of $1 # returns the command's exit code # and sets CHECK_FAILED var to nonempty value upon fail +incolor() { [ -t 1 -a "$(tput colors)" -ge 8 ]; } check() { [ $# -lt 1 ] && return 1 @@ -68,9 +69,9 @@ check() # echo initial msg if [ "$msg" ]; then - echo -ne "\e[1m$msg\e[0m ..." + incolor && echo -ne "\e[1m$msg\e[0m ..." || echo -n "$msg ..." else - echo -ne "> \e[1m$1\e[0m ..." + incolor && echo -ne "> \e[1m$1\e[0m ..." || echo -n "> $1 ..." fi # run cmd, capture stderr @@ -80,18 +81,18 @@ check() ret=$? if [ -z "$cmpret" ]; then # ignored - echo -e "\e[1;34mignored\e[0m" + incolor && echo -e "\e[1;34mignored\e[0m" || echo "ignored" elif [ "$cmpret" -eq $ret ]; then # pass - echo -e "\e[1;32mpassed\e[0m" + incolor && echo -e "\e[1;32mpassed\e[0m" || echo "passed" else if [ "$WARNONLY" ]; then # warn - echo -e "\e[1;33mwarn\e[0m" + incolor && echo -e "\e[1;33mwarn\e[0m" || echo "warn" [ "$out" ] && echo "$out" else # fail - echo -e "\e[1;31mfailed\e[0m" + incolor && echo -e "\e[1;31mfailed\e[0m" || echo "failed" [ "$out" ] && echo "$out" CHECK_FAILED=1 fi diff --git a/audit-test/utils/run.bash b/audit-test/utils/run.bash index aeba0a1..c3a709f 100755 --- a/audit-test/utils/run.bash +++ b/audit-test/utils/run.bash @@ -421,6 +421,9 @@ function parse_cmdline { true" eval -- "$conf" || die "Error reading config file: $opt_config" + # Don't use color on non-tty devices or terminals without color support + [ -t 1 -a "$(tput colors)" -ge 8 ] || colorize() { monoize "$@"; } + if [[ -n $* ]]; then # Additional cmdline indicates tests to run dmsg "Filtering TESTS by cmdline" -- 1.8.3.1 |