summaryrefslogtreecommitdiff
path: root/src/cmd/INIT/rt.sh
blob: 2b8b8408b9a82cf1ab15cbd3f491191d553c5ee8 (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
########################################################################
#                                                                      #
#               This software is part of the ast package               #
#          Copyright (c) 1994-2011 AT&T Intellectual Property          #
#                      and is licensed under the                       #
#                 Eclipse Public License, Version 1.0                  #
#                    by AT&T Intellectual Property                     #
#                                                                      #
#                A copy of the License is available at                 #
#          http://www.eclipse.org/org/documents/epl-v10.html           #
#         (with md5 checksum b35adb5213ca9657e911e9befb180842)         #
#                                                                      #
#              Information and Software Systems Research               #
#                            AT&T Research                             #
#                           Florham Park NJ                            #
#                                                                      #
#                 Glenn Fowler <gsf@research.att.com>                  #
#                                                                      #
########################################################################
: rt - nmake test output filter

command=rt
flags='--silent --keepgoing'
failed=0
heading=1
verbose=0

case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
0123)	ARGV0="-a $command"
	USAGE=$'
[-?
@(#)$Id: rt (AT&T Research) 2010-07-27 $
]
'$USAGE_LICENSE$'
[+NAME?rt - run "nmake test" and filter output]
[+DESCRIPTION?\brt\b runs \vnmake test\v and filters the regression
	test output to contain only test summary lines. If no \atest\a
	operands are specified then \btest\b is assumed. If \b-\b is
	specified then the \afile\a operands, or the standard input
	if no \afile\a operands are specified, are filtered instead
	of the output from \bnmake\b.]
[f:failed?Only list failed test results.]
[h!:heading?Enable per-file heading when more than one \afile\a operand
	follows \b-\b.]
[v:verbose?Run with \vREGRESSFLAGS=-v\v.]

[ test ... | - [ file ... ] ]

[+SEE ALSO?\bnmake\b(1), \bregress\b(1)]
[+CAVEATS?\brt\b guesses the regression test output style. Garbled
	output indicates a bad guess.]
'
	;;
*)	ARGV0=""
	USAGE="fhv"
	;;
esac

function usage
{
	OPTIND=0
	getopts $ARGV0 "$USAGE" OPT '-?'
	exit 2
}

while	getopts $ARGV0 "$USAGE" OPT
do	case $OPT in
	f)	failed=1 ;;
	h)	heading=0 ;;
	v)	(( verbose=$OPTARG )) && flags="$flags REGRESSFLAGS=-v" ;;
	esac
done
shift `expr $OPTIND - 1`

ifs=${IFS:-$' \t\n'}
set -o noglob
component=
dots='............................................'
bad=' ***'
style=unknown
integer tests errors signals lineno=0 skip=0
typeset -l lower

function results # tests errors signals
{
	integer t=$1 e=$2 s=$3
	typeset label note
	if	[[ $style != unknown ]] && (( errors >= 0 ))
	then	style=unknown
		if	(( !failed || errors ))
		then	if	(( failed ))
			then	print -r -n -- "$unit"
			fi
			if	(( t >= 0 ))
			then	if	(( t == 1))
				then	label="test "
				else	label=tests
				fi
				printf $'%s%5d %s' "$prefix" "$t" "$label"
				prefix=
			else	prefix="$prefix..........."
			fi
			if	(( s ))
			then	label=signal
				(( e=s ))
			else	label=error
			fi
			if	(( e != 1))
			then	label=${label}s
			fi
			if	(( e == 1 ))
			then	note=" $bad"
			elif	(( e > 1 ))
			then	note=$bad
			fi
			printf $'%s%5d %s%s\n' "$prefix" "$e" "$label" "$note"
		fi
	fi
}

function unit
{
	typeset x
	if	[[ $component ]]
	then	x=${component##*/}
		if	[[ " $x " != *' '$unit' '* && " $unit " != *' '$x' '* ]]
		then	if	[[ $component == cmd/?*lib/* ]]
			then	unit="$unit $x"
			else	unit="$x $unit"
			fi
		fi
	fi
	unit="$unit ${dots:1:${#dots}-${#unit}}"
	if	[[ $1 ]]
	then	unit="$unit..........."
	fi
	if	(( ! failed ))
	then	print -r -n -- "$unit"
	fi
}

if	[[ $1 == - ]]
then	shift
	if	(( $# <= 1 ))
	then	heading=0
	fi
	if	(( heading ))
	then	for i
		do	print test heading $i
			cat -- "$i"
		done
	else	cat "$@"
	fi
else	if	[[ $1 == *=* ]]
	then	set test "$@"
	elif	(( ! $# ))
	then	set test
	fi
	nmake "$@" $flags 2>&1
fi |
while	read -r line
do	set '' $line
	shift
	case $line in
	TEST[' 	']*', '*' error'*)
		IFS=${IFS}","
		set '' $line
		IFS=$ifs
		set '' $*
		while	:
		do	case $2 in
			'')	break
				;;
			error|errors)
				errors=$1
				break
				;;
			test|tests)
				tests=$1
				;;
			esac
			shift
		done
		results $tests $errors
		continue
		;;
	TEST[' 	']*)
		results $tests $errors
		IFS=${IFS}","
		set '' $line
		IFS=$ifs
		set '' $*
		unit=${3##*/}
		case $4 in
		[a-zA-Z]*)	unit="$unit $4" ;;
		esac
		unit
		prefix=
		errors=0
		signals=0
		style=regress
		continue
		;;
	'pathname and options of item under test')
		read -r line || break
		results $tests $errors $signals
		set '' $line
		unit=${2##*/}
		unit
		tests=0
		errors=0
		signals=0
		style=script
		continue
		;;
	'test heading '*)
		if	(( heading ))
		then	if	(( heading > 1 ))
			then	print
			else	heading=2
			fi
			set '' $line
			shift 3
			print -r -- "==> $* <=="
		fi
		continue
		;;
	'test '*' begins at '????-??-??+??:??:??|'test '*' begins at '*' '*' '*' '*' '*)
		results $tests $errors $signals
		unit=${2##*/}
		unit=${unit%.sh}
		unit
		prefix=
		tests=-1
		errors=0
		signals=0
		style=shell
		continue
		;;
	'test '*' at '????-??-??+??:??:??' [ '*' ]'|'test '*' at '*' '*' '*' '*' '*)
		case $line in
		*' [ '*test*error*' ]')
			while	:
			do	case $1 in
				'[')	tests=$2
					errors=$4
					if	(( errors > 256 ))
					then	(( signals++ ))
					fi
					break
					;;
				esac
				shift
			done
			;;
		*' [ '*test*signal*' ]')
			while	:
			do	case $1 in
				'[')	tests=$2
					signals=$4
					if	(( signals ))
					then	(( errors++ ))
					fi
					break
					;;
				esac
				shift
			done
			;;
		*)	if	[[ $3 != passed ]]
			then	(( errors )) || (( errors++ ))
			fi
			;;
		esac
		results $tests $errors $signals
		continue
		;;
	'## ---'*(-)'--- ##')
		(( ++lineno > skip )) || continue
		read -r line || break
		lower=$line
		set '' $lower
		case $lower in
		'##'*'test suite:'*'##')
			results $tests $errors $signals
			set -- ${lower//*suite:}
			set -- ${*//[.#]/}
			unit=$*
			if	[[ $unit == *' tests' ]]
			then	unit=${unit/' tests'/}
			fi
			main=$unit
			prefix=
			tests=0
			errors=0
			signals=0
			category=
			style=autotest
			(( skip = lineno + 1 ))
			unit
			continue
			;;
		esac
		;;
	+(-))	case $style in
		regress)	continue ;;
		esac
		(( ++lineno > skip )) || continue
		read -r line || break
		set '' $line
		case $line in
		'Running tests for '*)
			results $tests $errors $signals
			shift 4
			unit=
			while	(( $# ))
			do	if	[[ $1 == on ]]
				then	break
				fi
				if	[[ $unit ]]
				then	unit="$unit "
				fi
				unit=$unit${1##*/}
				shift
			done
			main=$unit
			prefix=
			tests=-1
			errors=-1
			category=
			style=perl
			(( skip = lineno + 1 ))
			continue
			;;
		*' : '*)results $tests $errors $signals
			unit=${2##*/}
			unit=${unit%.sh}
			unit
			prefix=
			tests=0
			errors=0
			signals=0
			style=timing
			(( skip = lineno + 1 ))
			continue
			;;
		esac
		;;
	+([0-9])*([a-zA-Z0-9])' '*)
		case $style in
		script)	case $line in
			*FAILED*|*failed*)
				(( errors++ ))
				;;
			*)	(( tests++ ))
				;;
			esac
			;;
		esac
		;;
	make:*|'make ['*']:'*)
		case $line in
		*': warning:'*|*'making test'*|*'action'?(s)' failed'*|*': *** '*)
			;;
		*)	results $tests $errors $signals
			print -r -u2 -- "$line"
			;;
		esac
		continue
		;;
	+([/a-zA-Z_0-9]):)
		component=${line%:}
		;;
	'')	continue
		;;
	esac
	case $style in
	autotest)
		case $line in
		+([0-9]):*ok)
			(( tests++ ))
			;;
		+([0-9]):*FAILED*)
			(( tests++ ))
			(( errors++ ))
			if	(( $verbose ))
			then	if	[[ ! $prefix ]]
				then	prefix=$unit
					print
				fi
				print -r -- "	${line//*'FAILED '/}"
			fi
			;;
		esac
		continue
		;;
	perl)	case $line in
		*'........ '*)
			if	[[ $1 == */* ]]
			then	cat=${1%%/*}
				if	[[ $cat != $category ]]
				then	results $tests $errors $signals
					category=$cat
					unit="$main $category"
					unit
					prefix=
					tests=0
					errors=0
					signals=0
				fi
				(( tests++ ))
				case $line in
				*' ok')	;;
				*)	(( errors++ ))
					if	(( $verbose ))
					then	if	[[ ! $prefix ]]
						then	prefix=$unit
							print
						fi
						print -r -- "$line"
					fi
					;;
				esac
			else	results $tests $errors $signals
				case $line in
				*' ok')	errors=0 ;;
				*)	errors=1 ;;
				esac
				unit="$main $1"
				unit
				if	(( $verbose && errors ))
				then	prefix=$unit
					print
					shift 2
					print -r -- "$@"
				else	prefix=
				fi
				results $tests $errors $signals
				tests=-1
				errors=-1
				category=
			fi
			style=perl
			;;
		esac
		continue
		;;
	esac
	case $line in
	*FAILED*|*failed*)
		(( errors++ ))
		;;
	*)	case $style in
		regress)case $line in
			['<>']*);;
			*)	continue ;;
			esac
			;;
		script)	continue
			;;
		shell)	((errors++ ))
			;;
		timing)	(( tests++ ))
			continue
			;;
		unknown)continue
			;;
		esac
		;;
	esac
	if	(( $verbose ))
	then	if	[[ ! $prefix ]]
		then	prefix=$unit
			print
		fi
		print -r -- "$line"
	fi
done
results $tests $errors $signals