-
Notifications
You must be signed in to change notification settings - Fork 82
/
go-test-prettify
executable file
·74 lines (59 loc) · 1.18 KB
/
go-test-prettify
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
#
# Parse the output from `go test -v` and prints a summary at the end. Also only
# outputs errors by default unless -v is specified.
#
declare verbose=false
if [[ $1 == "-v"* ]]; then
verbose=true
fi
declare -i run=0
declare -i passed=0
declare -i failed=0
declare -i skipped=0
while IFS= read -r line; do
case $line in
"--- PASS:"*)
passed=$(($passed+1))
;;
"--- FAIL:"*)
failed=$(($failed+1))
# Output fail lines
if ! $verbose; then
echo "$line"
fi
;;
"--- SKIP:"*)
skipped=$(($skipped+1))
;;
# Skip output of "RUN" lines by default
"=== RUN"*)
run=$(($run+1))
;;
# Skip output of mock.go success lines (unicode char is the green tick)
*mock*$(echo -e "\xe2\x9c\x85")*)
;;
# Skip and ignore printing junk
PASS|FAIL|\?*)
;;
*)
# Output unknown lines
if ! $verbose; then
echo "$line"
fi
;;
esac
if $verbose; then
echo "$line"
fi
done
echo
echo "# tests: $run"
[ $passed -ne 0 ] && echo "# passed: $passed"
[ $failed -ne 0 ] && echo "# failed: $failed"
[ $skipped -ne 0 ] && echo "# skipped: $skipped"
echo
# Exit with non-zero code if there were test errors
if [ $failed -ne 0 ]; then
exit 1
fi