highlighting in the console

One of the unit testing tools (Testeez, to be more precise) is a bit too verbose. It displays not only the failed tests, but also the passed tests. When the number of the tests is big, it's hard to find the failed one. Therefore, I decided to highlight them in red.

Surprisingly, it wasn't very hard. The third search in Google was something like "console ESC color", I found "colour ls mini howto" and borrowed the code.

For Testeez it looks so:


... | sed $'s/^\(;; \)\(FAILED!\)/\\1\033[40;31;1m\\2\033[0m/' \
    | sed $'s/^\(;; [0-9]\+\. \)\(.*\)$/\\1\033[40;34;1m\\2\033[0m/'

It highlights the "failed" messages in red, and the titles of the tests in blue. Here is a "screenshot":


;;; BEGIN "Foo Station" TESTS

;; 1. Put two and two together
(+ 2 2)
;; ==> 4
;; Passed.

;; DEFINE: Bar function
(define bar (lambda (x) (+ x 42)))

;; 2. Bar scene
(bar 69)
;; ==> 111
;; FAILED!  Expected:
;;     0

;; 3. Full circle
(* (bar -21) 2)
;; ==> 42
;; Passed.

;; 4. Multiple
(values (+ 2 2) (string #\h #\i) (char-upcase #\p))
;; ==> 4
;;     "hi"
;;     #\P
;; Passed.

;;; END "Foo Station" TESTS: FAILED
;;;     (Total: 4  Passed: 3  Failed: 1)

12 Februrary 2007, update

I also added highlighting of the "Failed: X" if X > 0. Addition to the command line:


... | sed $'s/\(Failed: [1-9][0-9]*\))/\033[40;31;1m\\1\033[0m)/'
Categories:

Updated: