From 4d458a8be62f79d7a931e7ee95da3438ca07b15e Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 20 Mar 2019 18:30:01 -0400 Subject: tests: Make the output more colorful and nicer --- tests.sh | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/tests.sh b/tests.sh index a219812..3d2ac43 100755 --- a/tests.sh +++ b/tests.sh @@ -2078,8 +2078,18 @@ function test_L_unique_depth() { bfs_diff -L loops/deeply/nested -unique -depth } -if [ -t 1 -a ! "$VERBOSE" ]; then - in_place=yes +EOL='\n' +if [ -t 1 ]; then + RED='\033[01;31m' + GRN='\033[01;32m' + YLW='\033[01;33m' + RST='\033[0m' + if [ ! "$VERBOSE" ]; then + BOL='\r\033[K' + # Put the cursor at the last column, then write a space so the next + # character will wrap + EOL="\\033[$(tput cols)G " + fi fi passed=0 @@ -2088,11 +2098,7 @@ failed=0 for test in ${!run_*}; do test=${test#run_} - if [ "$in_place" ]; then - printf '\r\033[J%s' "$test" - else - echo "$test" - fi + printf "${BOL}${YLW}%s${RST}${EOL}" "$test" ("$test" "$dir") status=$? @@ -2101,22 +2107,14 @@ for test in ${!run_*}; do ((++passed)) else ((++failed)) - if [ "$in_place" ]; then - printf '\r\033[J%s\n' "$test failed!" - else - echo "$test failed!" - fi + printf "${BOL}${RED}%s failed!${RST}\n" "$test" fi done -if [ "$in_place" ]; then - printf '\r\033[J' -fi - if [ $passed -gt 0 ]; then - echo "tests passed: $passed" + printf "${BOL}${GRN}tests passed: %d${RST}\n" "$passed" fi if [ $failed -gt 0 ]; then - echo "tests failed: $failed" + printf "${BOL}${RED}tests failed: %s${RST}\n" "$failed" exit 1 fi -- cgit v1.2.3