jsonfmt.py: Don't sort the JSON, use the new -s/--sort option for that
[sunny256-utils.git] / Lib / std / Genlog
blob84ae660b816dad6e082f2af32f4bf5c9219e89b5
1 #!/bin/sh
3 #=======================================================================
4 # Genlog
5 # File ID: STDuuidDTS
7 # Run all tests, update files in log/ of that directory and display the
8 # results.
10 # Author: Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later.
12 #=======================================================================
14 progname=Genlog
15 VERSION=0.6.0
17 if test "$1" = "--version"; then
18 echo $progname $VERSION
19 exit 0
22 if test -z "$1" -o "$1" = "-h" -o "$1" = "--help"; then
23 cat <<END
25 Run all tests, update files in log/ of that directory and display the
26 results.
28 The exit value is a bitwise OR:
30 Bit 0 set: One or more tests failed
31 Bit 1 set: Bail out detected (one or more test scripts aborted)
33 That is:
35 0: Everything ok
36 1: One or more tests failed
37 2: One or more scripts aborted
38 3: Tests failed and scripts aborted
40 Lines starting with "# NOTICE:" are displayed during the run. They don't
41 affect the exit value, so they can for example be used to inform the
42 user that tests have been skipped.
44 Usage: $progname testname [options] [testname [...]]
46 Options:
48 -h, --help
49 Show this help.
50 --version
51 Print version information.
53 END
54 exit 0
57 [ -z "$1" ] && {
58 echo "Syntax: $0 testname [options] [testname [...]]" >&2
59 exit 1
62 mkdir -p log
63 maxlen=0
64 retval=0
65 tot_bailout=0
66 tot_ok=0
67 tot_not_ok=0
68 opt_str=
70 while printf "%s" "$1" | grep -q ^-; do
71 opt_str="$opt_str $1"
72 shift
73 done
75 for gf in "$@"; do
76 currlen=`echo -n $gf | wc -c`
77 [ $currlen -gt $maxlen ] && maxlen=$currlen
78 done
80 for gf in "$@"; do
81 testname=$gf
82 printf "%${maxlen}s: " $testname
83 ./$testname $opt_str 2>&1 |
84 perl -pe 's/^((not )?ok)( \d+ )- /$1 - /;' >log/$testname.log
85 not_ok_count=$(grep -a "^not ok" log/$testname.log | wc -l | tr -d ' ')
86 if [ $not_ok_count -gt 0 ]; then
87 not_ok_str=", $not_ok_count not ok"
88 retval=$(($retval | 1))
89 else
90 unset not_ok_str
92 ok_count=$(grep -a "^ok" log/$testname.log | wc -l)
93 printf "%3u ok%s\\n" $ok_count "$not_ok_str"
94 tot_ok=$(($tot_ok + $ok_count))
95 tot_not_ok=$(($tot_not_ok + $not_ok_count))
96 grep -a -q "^not ok" log/$testname.log && {
97 echo
98 grep -a "^not ok" log/$testname.log
99 echo
101 grep -a "^Bail out" log/$testname.log && retval=$(($retval | 2))
102 tot_bailout=$((
103 $tot_bailout + $(grep -a "^Bail out" log/$testname.log | wc -l)
105 grep -a "^# NOTICE:" log/$testname.log
106 done
107 echo
108 unset tot_not_ok_str
109 if test $tot_not_ok -gt 0; then
110 tot_not_ok_str=", $tot_not_ok not ok ($tot_not_ok/$((
111 $tot_ok + $tot_not_ok
112 )) FAIL)"
114 printf "%${maxlen}s: %u ok%s\n" "total" "$tot_ok" "$tot_not_ok_str"
115 if test $tot_bailout -gt 0; then
116 printf "%${maxlen}s: %u\n" "bailout" "$tot_bailout"
119 exit $retval