]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
tap/awk: support colorized output
authorStefano Lattarini <stefano.lattarini@gmail.com>
Sun, 21 Aug 2011 18:09:34 +0000 (20:09 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Sun, 21 Aug 2011 21:43:43 +0000 (23:43 +0200)
* lib/tap-driver.sh: Pass definition of colors to the BEGIN block
of the awk script, using ...
($init_colors): ... this new variable, which supersedes ...
($red, $grn, $lgn, $blu, $mgn, $std): ... these variables, which
have been consequently removed.
($color_tests): We don't have to pass this anymore to the awk
script, so do not convert it to a numeric boolean.
(decorate_result): Implement for real.

With this change, the test 'tap-color.test' now passes.

ChangeLog
lib/tap-driver.sh

index e9509fdb80b1ce24839d24400e2d0d0b35f38b75..80889c9eadfd892dd2a1b3d886c69c1273ff6ceb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2011-08-21  Stefano Lattarini  <stefano.lattarini@gmail.com>
+
+       tap/awk: support colorized output
+       * lib/tap-driver.sh: Pass definition of colors to the BEGIN block
+       of the awk script, using ...
+       ($init_colors): ... this new variable, which supersedes ...
+       ($red, $grn, $lgn, $blu, $mgn, $std): ... these variables, which
+       have been consequently removed.
+       ($color_tests): We don't have to pass this anymore to the awk
+       script, so do not convert it to a numeric boolean.
+       (decorate_result): Implement for real.
+       With this change, the test 'tap-color.test' now passes.
+
 2011-08-21  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
        tap: real (but still incomplete) awk implementation of TAP driver
index dc19fa03b923df7e59d049d73a452c0106331954..28eacb7bee5dbcdcf4e297b0cc4eec2de8b0923b 100755 (executable)
@@ -97,20 +97,22 @@ case $expect_failure in
     *) expect_failure=0;;
 esac
 
-case $color_tests in
-  yes) color_tests=1;;
-    *) color_tests=0;;
-esac
-
 if test $color_tests = yes; then
-  red='\e[0;31m' # Red.
-  grn='\e[0;32m' # Green.
-  lgn='\e[1;32m' # Light green.
-  blu='\e[1;34m' # Blue.
-  mgn='\e[0;35m' # Magenta.
-  std='\e[m'     # No color.
+  init_colors='
+    color_map["red"]="\e[0;31m" # Red.
+    color_map["grn"]="\e[0;32m" # Green.
+    color_map["lgn"]="\e[1;32m" # Light green.
+    color_map["blu"]="\e[1;34m" # Blue.
+    color_map["mgn"]="\e[0;35m" # Magenta.
+    color_map["std"]="\e[m"     # No color.
+    color_for_result["ERROR"] = "mgn"
+    color_for_result["PASS"]  = "grn"
+    color_for_result["XPASS"] = "red"
+    color_for_result["FAIL"]  = "red"
+    color_for_result["XFAIL"] = "lgn"
+    color_for_result["SKIP"]  = "blu"'
 else
-  red= grn= lgn= blu= mgn= std=
+  init_colors=''
 fi
 
 {
@@ -125,7 +127,6 @@ fi
         -v test_script_name="$test_name" \
         -v log_file="$log_file" \
         -v trs_file="$trs_file" \
-        -v color_tests="$color_tests" \
         -v expect_failure="$expect_failure" \
         -v merge="$merge" \
         -v ignore_exit="$ignore_exit" \
@@ -232,7 +233,12 @@ function stringify_result_obj(obj)
 
 function decorate_result(result)
 {
-  return result # TODO!
+  color_name = color_for_result[result]
+  if (color_name)
+    return color_map[color_name] "" result "" color_map["std"]
+  # If we are not using colorized output, or if we do not know how
+  # to colorize the given result, we should return it unchanged.
+  return result
 }
 
 function report(result, details)
@@ -432,6 +438,8 @@ function write_test_results()
 
 BEGIN {
 
+  '"$init_colors"'
+
   # Properly initialized once the TAP plan is seen.
   planned_tests = 0