Skip to content

Commit 7876394

Browse files
committed
Prettier output with unicode colored characters when in interactive mode.
Closes #25
1 parent ab6a884 commit 7876394

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

bash_unit

+31-7
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,30 @@ color() {
175175
if [ -t 1 ] ; then echo -en "$NOCOLOR" ; fi
176176
}
177177

178+
pretty_format() {
179+
local color="$1"
180+
local pretty_symbol="$2"
181+
local alt_symbol="$3"
182+
[ -t 1 ] && local term=true || local term=false
183+
(
184+
cat
185+
if $term
186+
then
187+
echo -en " $pretty_symbol "
188+
else
189+
[[ ! -z "$alt_symbol" ]] && echo -en " $alt_symbol "
190+
fi
191+
) | color "$color"
192+
}
193+
194+
pretty_success() {
195+
pretty_format "$GREEN" "\u2713" "$1"
196+
}
197+
198+
pretty_failure() {
199+
pretty_format "$RED" "\u2717" "$1"
200+
}
201+
178202
text_format() {
179203
notify_suite_starting() {
180204
test_file="$1"
@@ -185,11 +209,13 @@ text_format() {
185209
echo -n "Running $test... " | color "$BLUE"
186210
}
187211
notify_test_succeeded() {
188-
color "$GREEN" "SUCCESS"
212+
echo -n "SUCCESS" | pretty_success
213+
echo
189214
}
190215
notify_test_failed() {
191216
local message="$2"
192-
color "$RED" "FAILURE"
217+
echo -n "FAILURE" | pretty_failure
218+
echo
193219
[[ -z $message ]] || printf -- "$message\n"
194220
}
195221
notify_stdout() {
@@ -213,16 +239,14 @@ tap_format() {
213239
}
214240
notify_test_succeeded() {
215241
local test="$1"
216-
echo -n "ok" | color "$GREEN"
217-
echo -n ' - '
242+
echo -n "ok" | pretty_success -
218243
echo "$test" | color "$BLUE"
219244
}
220245
notify_test_failed() {
221246
local test="$1"
222247
local message="$2"
223-
echo -n "not ok" | color "$RED"
224-
echo -n " - "
225-
echo "$test"
248+
echo -n "not ok" | pretty_failure -
249+
echo "$test" | color "$BLUE"
226250
[[ -z $message ]] || printf -- "$message\n" | sed -u -e 's/^/# /'
227251
}
228252
notify_stdout() {

0 commit comments

Comments
 (0)