@@ -25,6 +25,11 @@ __ztr_clear() { # Clear counts.
2525 typeset -gir ZTR_COUNT_SKIP ZTR_COUNT_FAIL ZTR_COUNT_PASS
2626}
2727
28+ __ztr_get_use_color () {
29+ # succeeds if NO_COLOR has not been declared
30+ ! typeset -p NO_COLOR 2> /dev/null | grep -q ' ^'
31+ }
32+
2833__ztr_debugger () { # Print name of caller function.
2934 emulate -LR zsh
3035
@@ -42,16 +47,21 @@ __ztr_init() { # Set variables.
4247 emulate -LR zsh
4348 __ztr_debugger
4449
50+ if __ztr_get_use_color; then
51+ ' builtin' ' autoload' -U colors && colors
52+ fi
53+
4554 # -g
4655 typeset -g fail_color pass_color skip_color
4756
48- # if NO_COLOR has not been declared
49- if ! typeset -p NO_COLOR 2> /dev/null | grep -q ' ^' ; then
50- ' builtin' ' autoload' -U colors && colors
51- fail_color=" $fg [red]"
52- pass_color=" $fg [green]"
53- skip_color=" $fg [yellow]"
54- fi
57+ # -gAr
58+ typeset -gA +r __ztr_colors && \
59+ __ztr_colors=(
60+ [fail]=red
61+ [pass]=green
62+ [skip]=yellow
63+ ) && \
64+ typeset -gAr __ztr_colors
5565
5666 # -gi
5767 typeset -gi ZTR_DEBUG > /dev/null && \
@@ -84,13 +94,18 @@ __ztr_test() { # Test <arg> [<name> [<notes>]]. Pretty-print result and notes un
8494 emulate -LR zsh
8595 __ztr_debugger
8696
87- local notes result arg
97+ local arg fail_color pass_color notes result
8898 local -i exit_code
8999
90100 arg=$1
91101 name=$2
92102 notes=$3
93103
104+ if __ztr_get_use_color; then
105+ fail_color=" $fg [$__ztr_colors [fail]]"
106+ pass_color=" $fg [$__ztr_colors [pass]]"
107+ fi
108+
94109 eval $arg & > /dev/null
95110
96111 exit_code=$?
@@ -120,12 +135,16 @@ __ztr_skip() { # Skip <arg>.
120135 emulate -LR zsh
121136 __ztr_debugger
122137
123- local arg name notes
138+ local arg name notes skip_color
124139
125- arg=$1
140+ arg=$1
126141 name=$2
127142 notes=$3
128143
144+ if __ztr_get_use_color; then
145+ skip_color=" $fg [$__ztr_colors [skip]]"
146+ fi
147+
129148 typeset -gi +r ZTR_COUNT_SKIP
130149 (( ZTR_COUNT_SKIP++ ))
131150 typeset -gir ZTR_COUNT_SKIP
@@ -139,10 +158,16 @@ __ztr_summary() { # Pretty-print summary of counts.
139158 emulate -LR zsh
140159 __ztr_debugger
141160
142- local rate_fail rate_pass
161+ local fail_color pass_color rate_fail rate_pass skip_color
143162 local -i total
144163
145- total=$(( ZTR_COUNT_FAIL + ZTR_COUNT_PASS + ZTR_COUNT_SKIP ))
164+ if __ztr_get_use_color; then
165+ fail_color=" $fg [$__ztr_colors [fail]]"
166+ pass_color=" $fg [$__ztr_colors [pass]]"
167+ skip_color=" $fg [$__ztr_colors [skip]]"
168+ fi
169+
170+ total=$(( ZTR_COUNT_FAIL + ZTR_COUNT_PASS + ZTR_COUNT_SKIP ))
146171
147172 if (( total )) ; then
148173 (( ZTR_COUNT_FAIL )) && (( rate_fail= ZTR_COUNT_FAIL* 100 / total ))
0 commit comments