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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
|
########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1994-2012 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> #
# #
########################################################################
: regress - run regression tests in command.tst
command=regress
case $(getopts '[-][123:xyz]' opt --xyz 2>/dev/null; echo 0$opt) in
0123) USAGE=$'
[-?
@(#)$Id: regress (AT&T Research) 2012-02-02 $
]
'$USAGE_LICENSE$'
[+NAME?regress - run regression tests]
[+DESCRIPTION?\bregress\b runs the tests in \aunit\a, or
\aunit\a\b.tst\b if \aunit\a does not exist. If \acommand\a is omitted
then it is assumed to be the base name of \aunit\a. All testing is done
in the temporary directory \aunit\a\b.tmp\b.]
[+?Default test output lists the \anumber\a and \adescription\a for
each active \bTEST\b group and the \anumber\a:\aline\a for each
individual \bEXEC\b test. Each test that fails results in a diagnostic
that contains the word \bFAILED\b; no other diagnostics contain this
word.]
[b:ignore-space?Ignore space differences when comparing expected
output.]
[i:pipe-input?Repeat each test with the standard input redirected through a
pipe.]
[k:keep?Enable \bcore\b dumps, exit after the first test that fails,
and do not remove the temporary directory \aunit\a\b.tmp\b.]
[l:local-fs?Force \aunit\a\b.tmp\b to be in a local filesystem.]
[o:pipe-output?Repeat each test with the standard output redirected through
a pipe.]
[p:pipe-io?Repeat each test with the standard input and standard output
redirected through pipes.]
[q:quiet?Output information on \bFAILED\b tests only.]
[r!:regular?Run each test with the standard input and standard output
redirected through regular files.]
[t:test?Run only tests matching \apattern\a. Tests are numbered and
consist of at least two digits (0 filled if necessary.) Tests matching
\b+(0)\b are always run.]:[pattern]
[x:trace?Enable debug tracing.]
[v:verbose?List differences between actual (<) and expected (>) output,
errors and exit codes. Also disable long output line truncation.]
unit [ command [ arg ... ] ]
[+INPUT FILES?The regression test file \aunit\a\b.tst\b is a \bksh\b(1)
script that is executed in an environment with the following functions
defined:]
{
[+BODY \b{ ... }?Defines the test body; used for complex tests.]
[+CD \b\adirectory\a?Create and change to working directory for
one test.]
[+CLEANUP \b\astatus\a?Called at exit time to remove the
temporary directory \aunit\a\b.tmp\b, list the tests totals via
\bTALLY\b, and exit with status \astatus\a.]
[+COMMAND \b\aarg\a ...?Runs the current command under test with
\aarg\a ... appended to the default args.]
[+CONTINUE?The background job must be running.]
[+COPY \b\afrom to\a?Copy file \afrom\a to \ato\a. \afrom\a may
be a regular file or \bINPUT\b, \bOUTPUT\b or \bERROR\b. Post
test comparisons are still done for \afrom\a.]
[+DIAGNOSTICS \b[ \b1\b | \b0\b | \apattern\a ]]?No argument or an
argument of \b1\b declares that diagnostics are to expected for
the remainder of the current \bTEST\b; \b0\b reverts to the default
state that diagnostics are not expected; otherwise the argument
is a \bksh\b(1) pattern that must match the non-empty contents
of the standard error.]
[+DO \b\astatement\a?Defines additional statements to be executed
for the current test. \astatement\a may be a { ... } group.]
[+EMPTY \bINPUT|OUTPUT|ERROR|SAME?The corresponding file is
expected to be empty.]
[+ERROR \b[ \b-e\b \afilter\a ]] [ \b-n\b ]] \afile\a | - \adata\a ...?The
standard error is expected to match either the contents
of \afile\a or the line \adata\a. \bERROR -n\b does not
append a newline to \adata\a. \afilter\a is a shell command
or pipeline that reads standard input and writes standard
output that is applied to ERROR before comparison with the
expected contents.]
[+EXEC \b[ \aarg\a ... ]]?Runs the command under test with
optional arguments. \bINPUT\b, \bOUTPUT\b, \bERROR\b, \bEXIT\b
and \bSAME\b calls following this \bEXEC\b up until the next
\bEXEC\b or the end of the script provide details for the
expected results. If no arguments are specified then the
arguments from the previious \bEXEC\b in the current \bTEST\b
group are used, or no arguments if this is the first \bEXEC\b
in the group.]
[+EXIT \b\astatus\a?The command exit status is expected to match
the pattern \astatus\a.]
[+EXITED?The background job must have exited.]
[+EXPORT \b[-]] \aname\a=\avalue\a ...?Export environment
variables for one test.]
[+FATAL \b\amessage\a ...?\amessage\a is printed on the standard
error and \bregress\b exits with status \b1\b.]
[+FIFO \bINPUT|OUTPUT|ERROR\b [ \b-n\b ]] \afile\a | - \adata\a ...?The
\bIO\B file is a fifo.]
[+IF \b\acommand\a [\anote\a]]?If the \bsh\b(1) \acommand\a exits
0 then tests until the next \bELIF\b, \bELSE\b or \bFI\b are
enabled. Otherwise those tests are skipped. \bIF\b ... \bFI\b
may be nested, but must not cross \bTEST\b boundaries. \anote\a
is listed on the standard error if the correspoding test block
is enabled; \bIF\b, \bELIF\b, \bELSE\b may nave a \anote\a
operand.]
[+IGNORE \b\afile\a ...?\afile\a is ignored for subsequent result
comparisons. \afile\a may be \bOUTPUT\b or \bERROR\b.]
[+IGNORESPACE?Ignore space differences when comparing expected
output.]
[+INCLUDE \b\afile\a ...?One or more \afile\a operands are read
via the \bksh\b(1) \b.\b(1) command. \bVIEW\b is used to locate
the files.]
[+INFO \b\adescription\a?\adescription\a is printed on the
standard error.]
[+INITIALIZE?Called by \bregress\b to initialize a each
\bTEST\b group.]
[+INPUT \b[ \b-e\b \afilter\a ]] [ \b-n\b ]] \afile\a | - \adata\a ...?The
standard input is set to either the contents of \afile\a
or the line \adata\a. \bINPUT -n\b does not append a newline
to \adata\a. \afilter\a is a shell command or pipeline that
reads standard input and writes standard output that is
applied to OUTPUT before comparison with the expected contents.]
[+INTRO?Called by \bregress\b to introduce all \bTEST\b
groups.]
[+IO \b[ \bFIFO\b | \bPIPE\b ]] \bINPUT|OUTPUT|ERROR\b [ \b-e\b \afilter\a ]] [ \b-n\b ]] \afile\a | - \adata\a ...?Internal
support for the \bINPUT\b, \bOUTPUT\b and \bERROR\b functions.]
[+JOB \b\aop\a [ ... ]]?Like \bEXEC\b except the command is run
as a background job for the duration of the group or until it
is killed via \bKILL\b.]
[+KEEP \b\apattern\a ...?The temporary directory is cleared for
each test. Files matching \apattern\a are retained between
tests.]
[+KILL \b[ \asignal\a ]]?Kill the background job with \asignal\a
[ \bSIGKILL\b ]].]
[+MOVE \b\afrom to\a?Rename file \afrom\a to \ato\a. \afrom\a may
be a regular file or \bINPUT\b, \bOUTPUT\b or \bERROR\b. Post
test comparisons are ignored for \afrom\a.]
[+NOTE \b\acomment\a?\acomment\a is added to the current test
trace output.]
[+OUTPUT \b[ \b-e\b \afilter\a ]] [ \b-n\b ]] \afile\a | - \adata\a ...?The
standard output is expected to match either the contents
of \afile\a or the line \adata\a. \bOUTPUT -n\b does not
append a newline to \adata\a. \afilter\a is a shell command
or pipeline that reads standard input and writes standard
output that is applied to ERROR before comparison with the
expected contents.]
[+PIPE \bINPUT|OUTPUT|ERROR\b [ \b-n\b ]] \afile\a | - \adata\a ...?The
\bIO\B file is a pipe.]
[+PROG \b\acommand\a [ \aarg\a ... ]]?\acommand\a is run with
optional arguments.]
[+REMOVE \b\afile\a ...?\afile\a ... are removed after the
current test is done.]
[+RUN?Called by \bregress\b to run the current test.]
[+SAME \b\anew old\a?\anew\a is expected to be the same as
\aold\a after the current test completes.]
[+SET \b[\bno\b]]\aname\a[=\avalue\a]]?Set the command line
option --\aname\a. The setting is in effect for all tests until
the next explicit \bSET\b.]
[+TALLY?Called by \bregress\b display the \bTEST\b results.]
[+TEST \b\anumber\a [ \adescription\a ... ]]?Define a new test
group labelled \anumber\a with optional \adescripion\a.]
[+TITLE \b[+]] \atext\a?Set the \bTEST\b output title to
\atext\a. If \b+\b is specified then \atext\a is appended to
the default title. The default title is the test file base
name, and, if different from the test file base name, the test
unit base name.]
[+TWD \b[ \adir\a ... ]]?Set the temporary test dir to \adir\a.
The default is \aunit\a\b.tmp\b, where \aunit\a is the test
input file sans directory and suffix. If \adir\a matches \b/*\b
then it is the directory name; if \adir\a is non-null then the
prefix \b${TMPDIR:-/tmp}\b is added; otherwise if \adir\a is
omitted then
\b${TMPDIR:-/tmp}/tst-\b\aunit\a-$$-$RANDOM.\b\aunit\a is
used.]
[+UMASK \b[ \amask\a ]]?Run subsequent tests with \bumask\b(1)
\amask\a. If \amask\a is omitted then the original \bumask\b is
used.]
[+UNIT \b\acommand\a [ \aarg\a ... ]]?Define the command and
optional default arguments to be tested. \bUNIT\b explicitly
overrides the default command name derived from the test script
file name. A \acommand\a operand with optional arguments
overrides the \bUNIT\b \acommand\a and arguments, with the
exception that if the \bUNIT\b \acommand\a is \b-\b or \b+\b
the \bUNIT\b arguments are appended to the operand or default
unit command and arguments.]
[+VIEW \b\avar\a [ \afile\a ]]?\avar\a is set to the full
pathname of \avar\a [ \afile\a ]] in the current \b$VPATH\b
view if defined.]
}
[+SEE ALSO?\bnmake\b(1), \bksh\b(1)]
'
;;
*) USAGE='ko:[[no]name[=value]]t:[test]v unit [path [arg ...]]'
;;
esac
function FATAL # message
{
print -r -u2 "$command: $*"
GROUP=FINI
exit 1
}
function EMPTY
{
typeset i
typeset -n ARRAY=$1
for i in ${!ARRAY[@]}
do unset ARRAY[$i]
done
}
function INITIALIZE # void
{
typeset i j
cd "$TWD"
case $KEEP in
"") RM *
;;
*) for i in *
do case $i in
!($KEEP)) j="$j $i" ;;
esac
done
case $j in
?*) RM $j ;;
esac
;;
esac
: >INPUT >OUTPUT.ex >ERROR.ex
BODY=""
COPY=""
DIAGNOSTICS=""
DONE=""
ERROR=""
EXIT=0
IGNORE=""
INIT=""
INPUT=""
MOVE=""
OUTPUT=""
EMPTY FILE
EMPTY FILTER
EMPTY SAME
EMPTY TYPE
}
function INTRO
{
typeset base command
if [[ ! $TEST_quiet ]]
then base=${REGRESS##*/}
base=${base%.tst}
command=${COMMAND##*/}
command=${command%' '*}
set -- $TITLE
TITLE=
case $1 in
''|+) if [[ $command == $base ]]
then TITLE=$COMMAND
else TITLE="$COMMAND, $base"
fi
if (( $# ))
then shift
fi
;;
esac
while (( $# ))
do if [[ $TITLE ]]
then TITLE="$TITLE, $1"
else TITLE="$1"
fi
shift
done
print -u2 "TEST $TITLE"
fi
}
function TALLY # extra message text
{
typeset msg
case $GROUP in
INIT) ;;
*) msg="TEST $TITLE, $TESTS test"
case $TESTS in
1) ;;
*) msg=${msg}s ;;
esac
msg="$msg, $ERRORS error"
case $ERRORS in
1) ;;
*) msg=${msg}s ;;
esac
if (( $# ))
then msg="$msg, $*"
fi
print -u2 "$msg"
GROUP=INIT
TESTS=0
ERRORS=0
;;
esac
}
function TITLE # text
{
TITLE=$@
}
function UNWIND
{
while (( COND > 1 ))
do print -r -u2 "$command: line $LINE: no matching FI for IF on line ${COND_LINE[COND]}"
(( COND-- ))
done
if (( COND > 0 ))
then (( COND = 0 ))
FATAL "line $LINE: no matching FI for IF on line ${COND_LINE[COND+1]}"
fi
if [[ $JOBPID ]]
then if [[ $JOBPID != 0 ]]
then kill -KILL $JOBPID 2>/dev/null
wait
fi
JOBPID=
fi
JOBSTATUS=
JOBOP=
wait
}
function CLEANUP # status
{
typeset note
if [[ $GROUP != INIT ]]
then if [[ ! $TEST_keep ]]
then cd $SOURCE
if [[ $TEST_local ]]
then RM ${TEST_local}
fi
RM "$TWD"
fi
if (( $1 )) && [[ $GROUP != FINI ]]
then note=terminated
fi
fi
TALLY $note
[[ $TEST_keep ]] || UNWIND
exit $1
}
function RUN # [ op ]
{
typeset i r=1
[[ $UMASK != $UMASK_ORIG ]] && umask $UMASK_ORIG
#print -u2 AHA#$LINENO $0 GROUP=$GROUP ITEM=$ITEM FLUSHED=$FLUSHED JOBOP=$JOBOP
case $GROUP in
INIT) RM "$TWD"
if [[ $TEST_local ]]
then TEST_local=${TMPDIR:-/tmp}/rt-$$/${TWD##*/}
mkdir -p "$TEST_local" && ln -s "$TEST_local" "$TWD" || FATAL "$TWD": cannot create directory
TEST_local=${TEST_local%/*}
else mkdir "$TWD" || FATAL "$TWD": cannot create directory
fi
cd "$TWD"
TWD=$PWD
: > rmu
if rm -u rmu >/dev/null 2>&1
then TEST_rmu=-u
else rm rmu
fi
if [[ $UNIT ]]
then set -- "${ARGV[@]}"
case $1 in
""|[-+]*)
UNIT $UNIT "${ARGV[@]}"
;;
*) UNIT "${ARGV[@]}"
;;
esac
fi
INTRO
;;
FINI) ;;
$TEST_select)
if [[ $ITEM == $FLUSHED ]]
then return 0
fi
FLUSHED=$ITEM
if (( COND_SKIP[COND] ))
then return 1
fi
((COUNT++))
if (( $ITEM <= $LASTITEM ))
then LABEL=$TEST#$COUNT
else LASTITEM=$ITEM
LABEL=$TEST:$ITEM
fi
TEST_file=""
exec >/dev/null
for i in $INPUT
do case " $OUTPUT " in
*" $i "*)
if [[ -f $i.sav ]]
then cp $i.sav $i
COMPARE="$COMPARE $i"
elif [[ -f $i ]]
then cp $i $i.sav
COMPARE="$COMPARE $i"
fi
;;
esac
done
for i in $OUTPUT
do case " $COMPARE " in
*" $i "*)
;;
*) COMPARE="$COMPARE $i"
;;
esac
done
for i in $INIT
do $i $TEST INIT
done
#print -u2 AHA#$LINENO $0 GROUP=$GROUP ITEM=$ITEM JOBOP=$JOBOP JOBPID=$JOBPID JOBSTATUS=$JOBSTATUS
if [[ $JOBPID != 0 && ( $JOBPID || $JOBSTATUS ) ]]
then if [[ ! $TEST_quiet ]]
then print -nu2 "$LABEL"
fi
RESULTS
elif [[ $BODY ]]
then SHOW=$NOTE
if [[ ! $TEST_quiet ]]
then print -r -u2 " $SHOW"
fi
for i in $BODY
do $i $TEST BODY
done
else SHOW=
if [[ ${TYPE[INPUT]} == PIPE ]]
then if [[ ${TYPE[OUTPUT]} == PIPE ]]
then if [[ ! $TEST_quiet ]]
then print -nu2 "$LABEL"
fi
cat <$TWD/INPUT | COMMAND "${ARGS[@]}" | cat >$TWD/OUTPUT
RESULTS 'pipe input'
else if [[ ! $TEST_quiet ]]
then print -nu2 "$LABEL"
fi
cat <$TWD/INPUT | COMMAND "${ARGS[@]}" >$TWD/OUTPUT
RESULTS 'pipe io'
fi
elif [[ ${TYPE[OUTPUT]} == PIPE ]]
then if [[ ! $TEST_quiet ]]
then print -nu2 "$LABEL"
fi
COMMAND "${ARGS[@]}" <$TWD/INPUT | cat >$TWD/OUTPUT
RESULTS 'pipe output'
else if [[ $TEST_regular ]]
then if [[ ! $TEST_quiet ]]
then print -nu2 "$LABEL"
fi
if [[ ${TYPE[INPUT]} == FIFO ]]
then COMMAND "${ARGS[@]}" >$TWD/OUTPUT
else COMMAND "${ARGS[@]}" <$TWD/INPUT >$TWD/OUTPUT
fi
RESULTS
fi
if [[ $TEST_pipe_input ]]
then if [[ ! $TEST_quiet ]]
then print -nu2 "$LABEL"
fi
(trap '' PIPE; cat <$TWD/INPUT 2>/dev/null; exit 0) | COMMAND "${ARGS[@]}" >$TWD/OUTPUT
STATUS=$?
RESULTS 'pipe input'
fi
if [[ $TEST_pipe_output ]]
then if [[ ! $TEST_quiet ]]
then print -nu2 "$LABEL"
fi
COMMAND "${ARGS[@]}" <$TWD/INPUT | cat >$TWD/OUTPUT
STATUS=$?
RESULTS 'pipe output'
fi
if [[ $TEST_pipe_io ]]
then if [[ ! $TEST_quiet ]]
then print -nu2 "$LABEL"
fi
(trap '' PIPE; cat <$TWD/INPUT 2>/dev/null; exit 0) | COMMAND "${ARGS[@]}" | cat >$TWD/OUTPUT
STATUS=$?
RESULTS 'pipe io'
fi
fi
set -- $COPY
COPY=""
while :
do case $# in
0|1) break ;;
*) cp $1 $2 ;;
esac
shift 2
done
set -- $MOVE
MOVE=""
while (( $# > 1 ))
do mv $1 $2
shift 2
done
fi
for i in $DONE
do $i $TEST DONE $STATUS
done
COMPARE=""
r=0
;;
esac
if [[ $COMMAND_ORIG ]]
then COMMAND=$COMMAND_ORIG
COMMAND_ORIG=
ARGS=(${ARGS_ORIG[@]})
fi
return $r
}
function DO # cmd ...
{
[[ $GROUP == $TEST_select ]] || return 1
(( COND_SKIP[COND] )) && return 1
[[ $UMASK != $UMASK_ORIG ]] && umask $UMASK
return 0
}
function UNIT # cmd arg ...
{
typeset cmd=$1
case $cmd in
[-+]) shift
if (( UNIT_READONLY ))
then COMMAND="$COMMAND $*"
else #BUG# ARGV=("${ARGV[@]}" "$@")
set -- "${ARGV[@]}" "$@"
ARGV=("$@")
fi
return
;;
esac
(( UNIT_READONLY )) && return
if [[ $UNIT ]] && (( $# <= 1 ))
then set -- "${ARGV[@]}"
case $1 in
"") set -- "$cmd" ;;
[-+]*) set -- "$cmd" "${ARGV[@]}" ;;
*) cmd=$1 ;;
esac
fi
UNIT=
COMMAND=$cmd
shift
typeset cmd=$(whence $COMMAND)
if [[ ! $cmd ]]
then FATAL $COMMAND: not found
elif [[ ! $cmd ]]
then FATAL $cmd: not found
fi
case $# in
0) ;;
*) COMMAND="$COMMAND $*" ;;
esac
}
function TWD # [ dir ]
{
case $1 in
'') TWD=${TWD##*/}; TWD=${TMPDIR:-/tmp}/tst-${TWD%.*}-$$-$RANDOM ;;
/*) TWD=$1 ;;
*) TWD=${TMPDIR:-/tmp}/$1 ;;
esac
}
function TEST # number description arg ...
{
RUN
LINE=$TESTLINE
UNWIND
COUNT=0
LASTITEM=0
case $1 in
-) ((LAST++)); TEST=$LAST ;;
+([0123456789])) LAST=$1 TEST=$1 ;;
*) LAST=0${1/[!0123456789]/} TEST=$1 ;;
esac
NOTE=
if [[ ! $TEST_quiet && $TEST == $TEST_select ]] && (( ! COND_SKIP[COND] ))
then print -r -u2 "$TEST $2"
fi
unset ARGS
unset EXPORT
EXPORTS=0
TEST_file=""
if [[ $TEST != ${GROUP}* ]]
then GROUP=${TEST%%+([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ])}
if [[ $GROUP == $TEST_select ]] && (( ! COND_SKIP[COND] ))
then INITIALIZE
fi
fi
((SUBTESTS=0))
[[ $TEST == $TEST_select ]] && (( ! COND_SKIP[COND] ))
}
function EXEC # arg ...
{
if [[ $GROUP != $TEST_select ]] || (( COND_SKIP[COND] ))
then return
fi
if ((SUBTESTS++))
then RUN
fi
case $# in
0) set -- "${ARGS[@]}" ;;
esac
ITEM=$LINE
NOTE="$(print -r -f '%q ' -- $COMMAND_ORIG "$@")${JOBPID:+&}"
ARGS=("$@")
}
function JOB # arg ...
{
JOBPID=0
EXEC "$@"
}
function CONTINUE
{
RUN || return
JOBOP=CONTINUE
ITEM=$LINE
NOTE="$(print -r -f '%q ' -- $JOBOP)"
#print -u2 AHA#$LINENO JOBOP=$JOBOP ITEM=$ITEM NOTE=$NOTE
}
function EXITED
{
RUN || return
JOBOP=EXITED
ITEM=$LINE
NOTE="$(print -r -f '%q ' -- $JOBOP)"
#print -u2 AHA#$LINENO JOBOP=$JOBOP ITEM=$ITEM NOTE=$NOTE
}
function KILL # [ signal ]
{
RUN || return
JOBOP=$2
[[ $JOBOP ]] || JOBOP=KILL
ITEM=$LINE
NOTE="$(print -r -f '%q ' -- $JOBOP)"
}
function CD
{
RUN
if [[ $GROUP == $TEST_select ]] && (( ! COND_SKIP[COND] ))
then mkdir -p "$@" && cd "$@" || FATAL cannot initialize working directory "$@"
fi
}
function EXPORT
{
typeset x n v
if [[ $GROUP == INIT ]]
then for x
do n=${x%%=*}
v=${x#*=}
ENVIRON[ENVIRONS++]=$n="'$v'"
done
else RUN
if [[ $GROUP != $TEST_select ]] || (( COND_SKIP[COND] ))
then return
fi
for x
do n=${x%%=*}
v=${x#*=}
EXPORT[EXPORTS++]=$n="'$v'"
done
fi
}
function FLUSH
{
if [[ $GROUP != $TEST_select ]] || (( COND_SKIP[COND] ))
then return
fi
if ((SUBTESTS++))
then RUN
fi
}
function PROG # cmd arg ...
{
typeset command args
if [[ $GROUP != $TEST_select ]] || (( COND_SKIP[COND] ))
then return
fi
ITEM=$LINE
NOTE="$(print -r -f '%q ' -- "$@")"
COMMAND_ORIG=$COMMAND
COMMAND=$1
shift
ARGS_ORIG=(${ARGS[@]})
ARGS=("$@")
}
function NOTE # description
{
NOTE=$*
}
function IO # [ PIPE ] INPUT|OUTPUT|ERROR [-f*|-n] file|- data ...
{
typeset op i v f file type x
if [[ $GROUP != $TEST_select ]] || (( COND_SKIP[COND] ))
then return
fi
[[ $UMASK != $UMASK_ORIG ]] && umask $UMASK_ORIG
while :
do case $1 in
FIFO|PIPE) type=$1; shift ;;
*) break ;;
esac
done
op=$1
shift
[[ $type ]] && TYPE[$op]=$type
FILTER[$op]=
file=$TWD/$op
while :
do case $1 in
-x) x=1
shift
;;
-e) (( $# > 1 )) && shift
FILTER[$op]=$1
shift
;;
-e*) FILTER[$op]=${1#-e}
shift
;;
-f*|-n) f=$1
shift
;;
*) break
;;
esac
done
case $# in
0) ;;
*) case $1 in
-) ;;
*) file=$1
eval i='$'$op
case " $i " in
*" $file "*)
;;
*) eval $op='"$'$op' $file"'
;;
esac
;;
esac
shift
;;
esac
case " $IGNORE " in
*" $file "*)
for i in $IGNORE
do case $i in
$file) ;;
*) v="$v $i" ;;
esac
done
IGNORE=$v
;;
esac
FILE[$op]=$file
case $op in
OUTPUT|ERROR)
file=$file.ex
if [[ $file != /* ]]
then file=$TWD/$file
fi
;;
esac
#unset SAME[$op]
SAME[$op]=
if [[ $file == /* ]]
then RM $file.sav
else RM $TWD/$file.sav
fi
if [[ $file == */* ]]
then mkdir -p ${file%/*}
fi
if [[ $file != */ ]]
then if [[ $type == FIFO ]]
then rm -f $file
mkfifo $file
fi
if [[ ${TYPE[$op]} != FIFO ]]
then if [[ $JOBOP ]]
then case $#:$f in
0:) ;;
*:-f) printf -- "$@" ;;
*:-f*) printf -- "${f#-f}""$@" ;;
*) print $f -r -- "$@" ;;
esac >> $file
else case $#:$f in
0:) ;;
*:-f) printf -- "$@" ;;
*:-f*) printf -- "${f#-f}""$@" ;;
*) print $f -r -- "$@" ;;
esac > $file
fi
elif [[ $#:$f != 0: ]]
then case $#:$f in
*:-f) printf -- "$@" ;;
*:-f*) printf -- "${f#-f}""$@" ;;
*) print $f -r -- "$@" ;;
esac >> $file &
fi
if [[ $x ]]
then chmod +x $file
fi
fi
}
function INPUT # file|- data ...
{
IO $0 "$@"
}
function COPY # from to
{
if [[ $GROUP != $TEST_select ]] || (( COND_SKIP[COND] ))
then return
fi
COPY="$COPY $@"
}
function MOVE # from to
{
typeset f
if [[ $GROUP != $TEST_select ]] || (( COND_SKIP[COND] ))
then return
fi
for f
do case $f in
INPUT|OUTPUT|ERROR)
f=$TWD/$f
;;
/*) ;;
*) f=$PWD/$f
;;
esac
MOVE="$MOVE $f"
done
}
function SAME # new old
{
typeset i file v
if [[ $GROUP != $TEST_select ]] || (( COND_SKIP[COND] ))
then return
fi
case $# in
2) case $1 in
INPUT) cat $2 > $1; return ;;
esac
SAME[$1]=$2
file=$1
COMPARE="$COMPARE $1"
;;
3) SAME[$2]=$3
file=$2
eval i='$'$1
case " $i " in
*" $2 "*)
;;
*) eval $1='"$'$1' $2"'
;;
esac
COMPARE="$COMPARE $2"
;;
esac
case " $IGNORE " in
*" $file "*)
for i in $IGNORE
do case $i in
$file) ;;
*) v="$v $i" ;;
esac
done
IGNORE=$v
;;
esac
}
function OUTPUT # file|- data ...
{
IO $0 "$@"
}
function ERROR # file|- data ...
{
IO $0 "$@"
}
function RM # rm(1) args
{
if [[ ! $TEST_rmu ]]
then chmod -R u+rwx "$@" >/dev/null 2>&1
fi
rm $TEST_rmu $TEST_rmflags "$@"
}
function REMOVE # file ...
{
typeset i
for i
do RM $i $i.sav
done
}
function IGNORE # file ...
{
typeset i
for i
do case $i in
INPUT|OUTPUT|ERROR)
i=$TWD/$i
;;
esac
case " $IGNORE " in
*" $i "*)
;;
*) IGNORE="$IGNORE $i"
;;
esac
done
}
function KEEP # pattern ...
{
typeset i
for i
do case $KEEP in
"") KEEP="$i" ;;
*) KEEP="$KEEP|$i" ;;
esac
done
}
function DIAGNOSTICS # [ 1 | 0 ]
{
case $#:$1 in
0:|1:1) DIAGNOSTICS=1
EXIT='*'
;;
1:|1:0) DIAGNOSTICS=""
EXIT=0
;;
*) DIAGNOSTICS=$1
EXIT='*'
;;
esac
}
function IGNORESPACE
{
: ${IGNORESPACE=-b}
}
function EXIT # status
{
EXIT=$1
}
function INFO # info description
{
typeset -R15 info=$1
if [[ ! $1 ]]
then info=no
fi
shift
if [[ ! $TEST_quiet ]]
then print -r -u2 "$info " "$@"
fi
}
function COMMAND # arg ...
{
typeset input
((TESTS++))
case " ${ENVIRON[*]} ${EXPORT[*]}" in
*' 'LC_ALL=*)
;;
*' 'LC_+([A-Z])=*)
EXPORT[EXPORTS++]="LC_ALL="
;;
esac
if [[ $TEST_keep ]]
then (
PS4=''
set -x
print -r -- "${ENVIRON[@]}" "${EXPORT[@]}" "PATH=$PATH" $COMMAND "$@"
) 2>&1 >/dev/null |
sed -e 's,^print -r -- ,,' -e 's,$, "$@",' >$TWD/COMMAND
chmod +x $TWD/COMMAND
fi
if [[ $UMASK != $UMASK_ORIG ]]
then : >$TWD/ERROR
umask $UMASK
fi
if [[ ${TYPE[INPUT]} == FIFO && ${FILE[INPUT]} == */INPUT ]]
then input="< ${FILE[INPUT]}"
fi
if [[ $TEST_trace ]]
then set +x
eval print -u2 "$PS4" "${ENVIRON[@]}" "${EXPORT[@]}" PATH='$PATH' '$'COMMAND '"$@"' '$input' '"2>$TWD/ERROR"' '"${JOBPID:+&}"'
fi
eval "${ENVIRON[@]}" "${EXPORT[@]}" PATH='$PATH' '$'COMMAND '"$@"' $input "2>$TWD/ERROR" "${JOBPID:+&}"
STATUS=$?
[[ $TEST_trace ]] && set -x
if [[ $JOBPID ]]
then JOBPID=$!
fi
[[ $UMASK != $UMASK_ORIG ]] && umask $UMASK_ORIG
return $STATUS
}
function RESULTS # pipe*
{
typeset i j k s failed ignore io op
if [[ $1 ]]
then io="$1 "
fi
[[ $JOBOP || $JOBPID || $JOBSTATUS ]] && sleep 1
for i in $COMPARE $TWD/OUTPUT $TWD/ERROR
do case " $IGNORE $ignore $MOVE " in
*" $i "*) continue ;;
esac
ignore="$ignore $i"
op=${i##*/}
if [[ ${FILTER[$op]} ]]
then eval "{ ${FILTER[$op]} ;} < $i > $i.fi"
mv $i.fi $i
fi
j=${SAME[$op]}
if [[ ! $j ]]
then if [[ $i == /* ]]
then k=$i
else k=$TWD/$i
fi
for s in ex sav err
do [[ -f $k.$s ]] && break
done
j=$k.$s
fi
if [[ "$DIAGNOSTICS" && $i == */ERROR ]]
then if [[ $STATUS == 0 && ! -s $TWD/ERROR || $DIAGNOSTICS != 1 && $(<$i) != $DIAGNOSTICS ]]
then failed=$failed${failed:+,}DIAGNOSTICS
if [[ $TEST_verbose && $DIAGNOSTICS != 1 ]]
then print -u2 " ===" "diagnostic pattern '$DIAGNOSTICS' did not match" ${i#$TWD/} "==="
cat $i >&2
fi
fi
continue
fi
diff $IGNORESPACE $i $j >$i.diff 2>&1
if [[ -s $i.diff ]]
then failed=$failed${failed:+,}${i#$TWD/}
if [[ $TEST_verbose ]]
then print -u2 " ===" diff $IGNORESPACE ${i#$TWD/} "<actual >expected ==="
cat $i.diff >&2
fi
fi
done
if [[ $JOBOP ]]
then if [[ $JOBPID ]] && ! kill -0 $JOBPID 2>/dev/null
then wait $JOBPID
JOBSTATUS=$?
JOBPID=
fi
#print -u2 AHA#$LINENO JOBOP=$JOBOP JOBPID=$JOBPID JOBSTATUS=$JOBSTATUS
case $JOBOP in
CONTINUE)
if [[ ! $JOBPID ]]
then failed=$failed${failed:+,}EXITED
fi
;;
EXITED) if [[ $JOBPID ]]
then failed=$failed${failed:+,}RUNNING
fi
;;
*) if [[ ! $JOBPID ]]
then failed=$failed${failed:+,}EXITED
fi
if ! kill -$JOBOP $JOBPID 2>/dev/null
then failed=$failed${failed:+,}KILL-$JOBOP
fi
;;
esac
JOBOP=
fi
if [[ ! $failed && $STATUS != $EXIT ]]
then failed="exit code $EXIT expected -- got $STATUS"
fi
if [[ $failed ]]
then ((ERRORS++))
if [[ ! $TEST_quiet ]]
then SHOW="FAILED ${io}[ $failed ] $NOTE"
print -r -u2 " $SHOW"
fi
if [[ $TEST_keep ]]
then GROUP=FINI
exit
fi
elif [[ ! $TEST_quiet ]]
then SHOW=$NOTE
print -r -u2 " $SHOW"
fi
}
function SET # [no]name[=value]
{
typeset i r
if [[ $TEST ]]
then RUN
fi
for i
do if [[ $i == - ]]
then r=1
elif [[ $i == + ]]
then r=
else if [[ $i == no?* ]]
then i=${i#no}
v=
elif [[ $i == *=* ]]
then v=${i#*=}
if [[ $v == 0 ]]
then v=
fi
i=${i%%=*}
else v=1
fi
i=${i//-/_}
if [[ $r ]]
then READONLY[$i]=1
elif [[ ${READONLY[$i]} ]]
then continue
fi
eval TEST_$i=$v
fi
done
}
function VIEW # var [ file ]
{
nameref var=$1
typeset i bwd file pwd view root offset
if [[ $var ]]
then return 0
fi
case $# in
1) file=$1 ;;
*) file=$2 ;;
esac
pwd=${TWD%/*}
bwd=${PMP%/*}
if [[ -r $file ]]
then if [[ ! -d $file ]]
then var=$PWD/$file
return 0
fi
for i in $file/*
do if [[ -r $i ]]
then var=$PWD/$file
return 0
fi
break
done
fi
for view in ${VIEWS[@]}
do case $view in
/*) ;;
*) view=$pwd/$view ;;
esac
case $offset in
'') case $pwd in
$view/*) offset=${pwd#$view} ;;
*) offset=${bwd#$view} ;;
esac
;;
esac
if [[ -r $view$offset/$file ]]
then if [[ ! -d $view$offset/$file ]]
then var=$view$offset/$file
return 0
fi
for i in $view$offset/$file/*
do if [[ -f $i ]]
then var=$view$offset/$file
return 0
fi
break
done
fi
done
var=
return 1
}
function INCLUDE # file ...
{
typeset f v x
for f
do if VIEW v $f || [[ $PREFIX && $f != /* ]] && VIEW v $PREFIX$f
then x=$x$'\n'". $v"
else FATAL $f: not found
fi
done
[[ $x ]] && trap "$x" 0
}
function UMASK # [ mask ]
{
if (( $# ))
then UMASK=$1
else UMASK=$UMASK_ORIG
fi
}
function PIPE # INPUT|OUTPUT|ERROR file|- data ...
{
IO $0 "$@"
}
function FIFO # INPUT|OUTPUT|ERROR file|- data ...
{
IO $0 "$@"
}
function IF # command(s) [note]
{
[[ $GROUP == $TEST_select ]] || return
RUN
(( COND++ ))
COND_LINE[COND]=$LINE
if (( COND > 1 && COND_SKIP[COND-1] ))
then (( COND_KEPT[COND] = 1 ))
(( COND_SKIP[COND] = 1 ))
elif eval "{ $1 ;} >/dev/null 2>&1"
then (( COND_KEPT[COND] = 1 ))
(( COND_SKIP[COND] = 0 ))
[[ $2 && ! $TEST_quiet ]] && print -u2 "NOTE $2"
else (( COND_KEPT[COND] = 0 ))
(( COND_SKIP[COND] = 1 ))
fi
}
function ELIF # command(s) [note]
{
[[ $GROUP == $TEST_select ]] || return
RUN
if (( COND <= 0 ))
then FATAL line $LINE: no matching IF for ELIF
fi
if (( COND_KEPT[COND] ))
then (( COND_SKIP[COND] = 0 ))
elif eval "$* > /dev/null 2>&1"
then (( COND_KEPT[COND] = 1 ))
(( COND_SKIP[COND] = 0 ))
[[ $2 && ! $TEST_quiet ]] && print -u2 "NOTE $2"
else (( COND_SKIP[COND] = 1 ))
fi
}
function ELSE # [note]
{
[[ $GROUP == $TEST_select ]] || return
RUN
if (( COND <= 0 ))
then FATAL line $LINE: no matching IF for ELSE
fi
if (( COND_KEPT[COND] ))
then (( COND_SKIP[COND] = 1 ))
else (( COND_KEPT[COND] = 1 ))
(( COND_SKIP[COND] = 0 ))
[[ $1 && ! $TEST_quiet ]] && print -u2 "NOTE $1"
fi
}
function FI
{
[[ $GROUP == $TEST_select ]] || return
RUN
if (( COND <= 0 ))
then FATAL line $LINE: no matching IF for FI on line $LINE
fi
(( ! COND_KEPT[COND] )) && [[ $1 && ! $TEST_quiet ]] && print -u2 "NOTE $1"
(( COND-- ))
}
# main
integer ERRORS=0 ENVIRONS=0 EXPORTS=0 TESTS=0 SUBTESTS=0 LINE=0 TESTLINE=0
integer ITEM=0 LASTITEM=0 COND=0 UNIT_READONLY=0 COUNT
typeset ARGS COMMAND COPY DIAGNOSTICS ERROR EXEC FLUSHED=0 GROUP=INIT
typeset IGNORE INPUT KEEP OUTPUT TEST SOURCE MOVE NOTE UMASK UMASK_ORIG
typeset ARGS_ORIG COMMAND_ORIG TITLE UNIT ARGV PREFIX OFFSET IGNORESPACE
typeset COMPARE MAIN JOBPID='' JOBSTATUS=''
typeset TEST_file TEST_keep TEST_pipe_input TEST_pipe_io TEST_pipe_output TEST_local
typeset TEST_quiet TEST_regular=1 TEST_rmflags='-rf --' TEST_rmu TEST_select
typeset -A SAME VIEWS FILE TYPE READONLY FILTER
typeset -a COND_LINE COND_SKIP COND_KEPT ENVIRON EXPORT
typeset -Z LAST=00
unset FIGNORE
while getopts -a $command "$USAGE" OPT
do case $OPT in
b) (( $OPTARG )) && IGNORESPACE=-b
;;
i) SET - pipe-input=$OPTARG
;;
k) SET - keep=$OPTARG
;;
l) SET - local
;;
o) SET - pipe-output=$OPTARG
;;
p) SET - pipe-io=$OPTARG
;;
q) SET - quiet=$OPTARG
;;
r) SET - regular=$OPTARG
;;
t) if [[ $TEST_select ]]
then TEST_select="$TEST_select|${OPTARG//,/\|}"
else TEST_select="${OPTARG//,/\|}"
fi
;;
x) SET - trace=$OPTARG
;;
v) SET - verbose=$OPTARG
;;
*) GROUP=FINI
exit 2
;;
esac
done
shift $OPTIND-1
case $# in
0) FATAL test unit name omitted ;;
esac
export COLUMNS=80
SOURCE=$PWD
PATH=$SOURCE:${PATH#?(.):}
PATH=${PATH%%:?(.)}:/usr/5bin:/bin:/usr/bin
UNIT=$1
shift
if [[ -f $UNIT && ! -x $UNIT ]]
then REGRESS=$UNIT
else REGRESS=${UNIT%.tst}
REGRESS=$REGRESS.tst
[[ -f $REGRESS ]] || FATAL $REGRESS: regression tests not found
fi
UNIT=${UNIT##*/}
UNIT=${UNIT%.tst}
MAIN=$UNIT
if [[ $VPATH ]]
then set -A VIEWS ${VPATH//:/' '}
OFFSET=${SOURCE#${VIEWS[0]}}
if [[ $OFFSET ]]
then OFFSET=${OFFSET#/}/
fi
fi
if [[ $REGRESS == */* ]]
then PREFIX=${REGRESS%/*}
if [[ ${#VIEWS[@]} ]]
then for i in ${VIEWS[@]}
do PREFIX=${PREFIX#$i/}
done
fi
PREFIX=${PREFIX#$OFFSET}
if [[ $PREFIX ]]
then PREFIX=$PREFIX/
fi
fi
TWD=$PWD/$UNIT.tmp
PMP=$(pwd -P)/$UNIT.tmp
UMASK_ORIG=$(umask)
UMASK=$UMASK_ORIG
ARGV=("$@")
if [[ ${ARGV[0]} && ${ARGV[0]} != [-+]* ]]
then UNIT "${ARGV[@]}"
UNIT_READONLY=1
fi
trap 'code=$?; CLEANUP $code' EXIT
if [[ ! $TEST_select ]]
then TEST_select="[0123456789]*"
fi
TEST_select="@($TEST_select|+(0))"
if [[ $TEST_trace ]]
then export PS4=':$LINENO: '
typeset -ft $(typeset +f)
set -x
fi
if [[ $TEST_verbose ]]
then typeset SHOW
else typeset -L70 SHOW
fi
if [[ ! $TEST_keep ]] && (ulimit -c 0) >/dev/null 2>&1
then ulimit -c 0
fi
set --pipefail
# some last minute shenanigans
alias BODY='BODY=BODY; function BODY'
alias CONTINUE='LINE=$LINENO; CONTINUE'
alias DO='(( $ITEM != $FLUSHED )) && RUN DO; DO &&'
alias DONE='DONE=DONE; function DONE'
alias EXEC='LINE=$LINENO; EXEC'
alias EXITED='LINE=$LINENO; EXITED'
alias INIT='INIT=INIT; function INIT'
alias JOB='LINE=$LINENO; JOB'
alias KILL='LINE=$LINENO; KILL'
alias PROG='LINE=$LINENO; FLUSH; PROG'
alias TEST='TESTLINE=$LINENO; TEST'
alias IF='LINE=$LINENO; FLUSH; IF'
alias ELIF='LINE=$LINENO; FLUSH; ELIF'
alias ELSE='LINE=$LINENO; FLUSH; ELSE'
alias FI='LINE=$LINENO; FLUSH; FI'
# do the tests
. $REGRESS
RUN
GROUP=FINI
|