-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmx-test.sh
executable file
·10597 lines (9694 loc) · 280 KB
/
mx-test.sh
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
#!/bin/sh -
#@ Synopsis: [OBJDIR=XY] ./mx-test.sh --check mailx-binary [:SKIPTESTNAME:]
#@ [OBJDIR=XY] ./mx-test.sh --run-test mailx-binary [:TESTNAME:]
#@ [./mx-test.sh # Note: performs hundreds of compilations!]
#@ --no-jobs can be used to prevent spawning concurrent tests.
#@ --no-colour or $MAILX_CC_TEST_NO_COLOUR for not trying to use colour
#@ (then grep for ^ERROR, for example).
#@ The last mode also reacts on $MAILX_CC_ALL_TESTS_DUMPERR, for even easier
#@ grep ^ERROR handling.
#@ And setting $MAILX_CC_TEST_NO_CLEANUP keeps all test data around, fwiw:
#@ this works with --run-test only.
#@ $JOBWAIT, $JOBMON and $SKIPTEST are taken from environment when found.
#
# Public Domain
: ${OBJDIR:=.obj}
# Instead of figuring out the environment in here, require a configured build
# system and include that! Our makefile and configure ensure that this test
# does not run in the configured, but the user environment nonetheless!
i=
while :; do
if [ -f ./mk-config.env ]; then
break
elif [ -f snailmail.jpg ] && [ -f "${OBJDIR}"/mk-config.env ]; then
i=`pwd`/ # not from environment, sic
cd "${OBJDIR}"
break
else
echo >&2 'S-nail/S-mailx is not configured.'
echo >&2 'This test script requires the shell environment that only the'
echo >&2 'configuration script can figure out, even if used to test'
echo >&2 'a different binary than the one that would be produced!'
echo >&2 '(The information will be in ${OBJDIR:=.obj}/mk-config.env.)'
echo >&2 'Hit RETURN to run "make config"'
read l
make config
fi
done
. ./mk-config.env
if [ -z "${MAILX__CC_TEST_RUNNING}" ]; then
MAILX__CC_TEST_RUNNING=1
export MAILX__CC_TEST_RUNNING
exec "${SHELL}" "${i}${0}" "${@}"
fi
# We need *stealthmua* regardless of $SOURCE_DATE_EPOCH, the program name as
# such is a compile-time variable
ARGS='-Sv15-compat -:/ -Sdotlock-disable -Smta=test -Smta-bcc-ok'
ARGS="${ARGS}"' -Smemdebug -Sstealthmua'
ARGS="${ARGS}"' -Smime-encoding=quoted-printable -Snosave'
ARGS="${ARGS}"' -Smailcap-disable -Smimetypes-load-control='
NOBATCH_ARGS="${ARGS}"' -Sexpandaddr'
ARGS="${ARGS}"' -Sexpandaddr=restrict -#'
ADDARG_UNI=-Sttycharset=UTF-8
CONF=../make.rc
BODY=./.cc-body.txt
MBOX=./.cc-test.mbox
ERR=./.cc-test.err # Covers some which cannot be checksummed; not quoted!
MAIL=/dev/null
#UTF8_LOCALE= HONOURS_READONLY= autodetected unless set
TMPDIR=`${pwd}`
# When testing mass mail/loops, maximum number of receivers/loops.
# TODO note we do not gracefully handle ARG_MAX excess yet!
# Those which use this have checksums for 2001 and 201.
# Some use the smaller automatically if +debug
LOOPS_BIG=2001 LOOPS_SMALL=201
LOOPS_MAX=$LOOPS_SMALL
# How long unless started tests get reaped (avoid endless looping)
: ${JOBWAIT:=42}
: ${JOBMON:=y}
: ${SKIPTEST:=}
# Note valgrind has problems with FDs in forked childs, which causes some tests
# to fail (the FD is rewound and thus will be dumped twice)
MEMTESTER=
#MEMTESTER='valgrind --leak-check=full --log-file=.vl-%p '
## -- >8 -- 8< -- ##
t_all() {
# Absolute Basics
jspawn X_Y_opt_input_go_stack
jspawn X_errexit
jspawn Y_errexit
jspawn S_freeze
jspawn f_batch_order
jspawn input_inject_semicolon_seq
jspawn wysh
jspawn commandalias # test now, save space later on!
jspawn posix_abbrev
jsync
# Basics
jspawn shcodec
jspawn ifelse
jspawn localopts
jspawn local
jspawn environ
jspawn macro_param_shift
jspawn addrcodec
jspawn csop
jspawn vexpr
jspawn call_ret
jspawn xcall
jspawn vpospar
jspawn atxplode
jspawn read
jspawn readsh
jspawn headerpick # so we have a notion that it works a bit
jsync
# Send/RFC absolute basics
jspawn can_send_rfc
jspawn reply
jspawn forward
jspawn resend
jsync
# VFS
jspawn copy
jspawn save
jspawn move
jspawn mbox
jspawn maildir
jsync
# MIME and RFC basics
jspawn mime_if_not_ascii
jspawn mime_encoding
jspawn xxxheads_rfc2047
jspawn iconv_mbyte_base64
jspawn iconv_mainbody
jspawn mime_force_sendout
jspawn binary_mainbody
jspawn C_opt_customhdr
jsync
# Operational basics with trivial tests
jspawn alias
jspawn charsetalias
jspawn shortcut
jspawn netrc
jsync
# Operational basics with easy tests
jspawn expandaddr # (after t_alias)
jspawn mta_aliases # (after t_expandaddr)
jspawn filetype
jspawn e_H_L_opts
jspawn q_t_etc_opts
jspawn message_injections
jspawn attachments
jspawn rfc2231 # (after attachments)
jspawn mime_types_load_control
jsync
# Around state machine, after basics
jspawn alternates
jspawn cmd_escapes
jspawn compose_edits
jspawn digmsg
jspawn on_main_loop_tick
jspawn on_program_exit
jsync
# Heavy use of/rely on state machine (behaviour) and basics
jspawn compose_hooks
jspawn mass_recipients
jspawn lreply_futh_rth_etc
jspawn pipe_handlers
jspawn mailcap
jsync
# Unclassified rest
jspawn top
jspawn s_mime
jspawn z
jsync
jsync 1
}
## Now it is getting really weird. You have been warned.
# Setup and support {{{
export ARGS ADDARG_UNI CONF BODY MBOX MAIL TMPDIR \
MAKE awk cat cksum rm sed grep
LC_ALL=C LANG=C
TZ=UTC
# Wed Oct 2 01:50:07 UTC 1996
SOURCE_DATE_EPOCH=844221007
export LC_ALL LANG TZ SOURCE_DATE_EPOCH
unset POSIXLY_CORRECT LOGNAME USER
# usage {{{
usage() {
${cat} >&2 <<'_EOT'
Synopsis: [OBJDIR=x] mx-test.sh [--no-jobs] --check mailx-binary [:SKIPTEST:]
Synopsis: [OBJDIR=x] mx-test.sh [--no-jobs] --run-test mailx-binary [:TEST:]
Synopsis: [OBJDIR=x] mx-test.sh [--no-jobs]
--check EXE [:SKIPTEST:] run test series, exit success or error.
[:SKIPTEST:]s (and $SKIPTEST=) will be excluded.
--run-test EXE [:TEST:] run all or only the given TESTs, and create
test output data files; if run in a git(1)
checkout with the [test-out] branch available,
it will also create file diff(1)erences
--no-jobs do not spawn multiple jobs simultaneously
(dependent on make(1) and sh(1), pass JOBMON=n, too)
--no-colour or $MAILX_CC_TEST_NO_COLOUR: no colour
(for example to: grep ^ERROR)
$MAILX_CC_ALL_TESTS_DUMPER in addition for even
easier grep ^ERROR handling
The last invocation style will compile and test as many different
configurations as possible.
EXE should be absolute or relative to $OBJDIR, which can be may be set to the
location of the built objects etc.
$MAILX_CC_TEST_NO_CLEANUP skips deletion of test data (works only with
one test, aka --run-test).
$JOBWAIT could denote a timeout, $JOBMON controls usage of "set -m".
_EOT
exit 1
}
CHECK= RUN_TEST= MAILX=
DEVELDIFF= DUMPERR= GIT_REPO=
MAXJOBS=1 NOCOLOUR= NOJOBS=
while [ ${#} -gt 0 ]; do
if [ "${1}" = --no-jobs ]; then
NOJOBS=y
shift
elif [ "${1}" = --no-colour ]; then
NOCOLOUR=y
shift
elif [ "${1}" = -h ] || [ "${1}" = --help ]; then
usage
exit 0
else
break
fi
done
if [ "${1}" = --check ]; then
CHECK=1 MAILX=${2}
[ -x "${MAILX}" ] || usage
shift 2
SKIPTEST="${@} ${SKIPTEST}"
[ -d ../.git ] && [ -z "${MAILX__CC_TEST_NO_DATA_FILES}" ] && GIT_REPO=1
echo 'Mode: --check, binary: '"${MAILX}"
elif [ "${1}" = --run-test ]; then
[ ${#} -ge 2 ] || usage
RUN_TEST=1 MAILX=${2}
[ -x "${MAILX}" ] || usage
shift 2
[ -d ../.git ] && GIT_REPO=1
echo 'Mode: --run-test, binary: '"${MAILX}"
else
[ ${#} -eq 0 ] || usage
echo 'Mode: full compile test, this will take a long time...'
MAILX__CC_TEST_NO_DATA_FILES=1
export MAILX__CC_TEST_NO_DATA_FILES
fi
# }}}
# Since we invoke $MAILX from within several directories we need a fully
# qualified path. Or at least something similar.
{ echo ${MAILX} | ${grep} -q ^/; } || MAILX="${TMPDIR}"/${MAILX}
RAWMAILX=${MAILX}
MAILX="${MEMTESTER}${MAILX}"
export RAWMAILX MAILX
# We want an UTF-8 locale, and HONOURS_READONLY {{{
if [ -n "${CHECK}${RUN_TEST}" ]; then
if [ -z "${UTF8_LOCALE}" ]; then
# Try ourselfs via nl_langinfo(CODESET) first (requires a new version)
if command -v "${RAWMAILX}" >/dev/null 2>&1 &&
("${RAWMAILX}" -:/ -Xxit) >/dev/null 2>&1; then
echo 'Trying to detect UTF-8 locale via '"${RAWMAILX}"
# C,POSIX last due to faulty localedef(1) result of GNU C lib 2.3[24]
# so here political friction for some decades, too
i=`</dev/null LC_ALL=de_DE.utf8 ${RAWMAILX} ${ARGS} -X '
\define cset_test {
\if "${ttycharset}" =%?case utf
\echo $LC_ALL
\xit 0
\end
\if "${#}" -gt 0
\wysh set LC_ALL=${1}
\shift
\xcall cset_test "${@}"
\end
\xit 1
}
\call cset_test \
de_DE.UTF-8 \
zh_CN.utf8 zh_CN.UTF-8 \
ru_RU.utf8 ru_RU.UTF-8 \
en_GB.utf8 en_GB.UTF-8 en_US.utf8 en_US.UTF-8 \
POSIX.utf8 POSIX.UTF-8 \
C.utf8 C.UTF-8
'`
[ $? -eq 0 ] && UTF8_LOCALE=$i
fi
if [ -z "${UTF8_LOCALE}" ] && (locale yesexpr) >/dev/null 2>&1; then
echo 'Trying to detect UTF-8 locale via locale -a'
UTF8_LOCALE=`locale -a | { m=
while read n; do
if { echo ${n} |
${grep} -i -e utf8 -e utf-8; } >/dev/null 2>&1; then
m=${n}
if { echo ${n} |
${grep} -e POSIX -e en_EN -e en_US; } \
>/dev/null 2>&1; then
break
fi
fi
done
echo ${m}
}`
fi
fi
if [ -n "${UTF8_LOCALE}" ]; then
echo 'Using Unicode locale '"${UTF8_LOCALE}"
else
echo 'No Unicode locale found, disabling Unicode tests'
fi
if [ -z "${HONOURS_READONLY}" ]; then
trap "${rm} -f ./.tisrdonly" EXIT
trap "exit 1" HUP INT TERM
printf '' > ./.tisrdonly
${chmod} 0444 ./.tisrdonly
if (printf 'no\n' > ./.tisrdonly) >/dev/null 2>&1 &&
test -s ./.tisrdonly; then
HONOURS_READONLY=
else
HONOURS_READONLY=yes
fi
${rm} -f ./.tisrdonly
trap '' EXIT HUP INT TERM
fi
fi
export UTF8_LOCALE HONOURS_READONLY
# }}}
TESTS_PERFORMED=0 TESTS_OK=0 TESTS_FAILED=0 TESTS_SKIPPED=0
JOBS=0 JOBLIST= JOBREAPER= JOBSYNC=
SUBSECOND_SLEEP=
( sleep .1 ) >/dev/null 2>&1 && SUBSECOND_SLEEP=y
COLOR_ERR_ON= COLOR_ERR_OFF= COLOR_DBGERR_ON= COLOR_DBGERR_OFF=
COLOR_WARN_ON= COLOR_WARN_OFF=
COLOR_OK_ON= COLOR_OK_OFF=
ESTAT=0
TEST_NAME=
trap "
jobreaper_stop
[ -z "${MAILX_CC_TEST_NO_CLEANUP}" ] &&
${rm} -rf ./t.*.d ./t.*.io ./t.*.result ./t.time.out
" EXIT
trap "exit 1" HUP INT QUIT TERM
# JOBS {{{
if [ -n "${NOJOBS}" ]; then
jobs_max() { :; }
else
jobs_max() {
# The user desired variant
if ( echo "${MAKEFLAGS}" | ${grep} -- -j ) >/dev/null 2>&1; then
i=`echo "${MAKEFLAGS}" |
${sed} -e 's/^.*-j[ ]*\([0-9]\{1,\}\).*$/\1/'`
if ( echo "${i}" | grep -q -e '^[0-9]\{1,\}$' ); then
printf 'Job number derived from MAKEFLAGS: %s\n' ${i}
MAXJOBS=${i}
[ "${MAXJOBS}" -eq 0 ] && MAXJOBS=1
return
fi
fi
# The actual hardware
printf 'all:\n' > t.mk.io
if ( ${MAKE} -j 10 -f t.mk.io ) >/dev/null 2>&1; then
if command -v nproc >/dev/null 2>&1; then
i=`nproc 2>/dev/null`
[ ${?} -eq 0 ] && MAXJOBS=${i}
else
i=`getconf _NPROCESSORS_ONLN 2>/dev/null`
j=${?}
if [ ${j} -ne 0 ]; then
i=`getconf NPROCESSORS_ONLN 2>/dev/null`
j=${?}
fi
if [ ${j} -ne 0 ]; then
# SunOS 5.9 ++
if command -v kstat >/dev/null 2>&1; then
i=`PERL5OPT= kstat -p cpu | ${awk} '
BEGIN{no=0; FS=":"}
{if($2 > no) max = $2; next}
END{print ++max}
' 2>/dev/null`
j=${?}
fi
fi
if [ ${j} -eq 0 ] && [ -n "${i}" ]; then
printf 'Job number derived from CPU number: %s\n' ${i}
MAXJOBS=${i}
fi
fi
[ "${MAXJOBS}" -eq 0 ] && MAXJOBS=1
fi
}
fi
jobreaper_start() {
case "${JOBMON}" in
[yY]*)
# There were problems when using monitor mode with mksh
i=`env -i ${SHELL} -c 'echo $KSH_VERSION'`
if [ -n "${i}" ]; then
if [ "${i}" != "${i#*MIRBSD}" ]; then
JOBMON=
fi
fi
if [ -n "${JOBMON}" ]; then
( set -m ) </dev/null >/dev/null 2>&1 || JOBMON=
else
printf >&2 '%s! $JOBMON: $SHELL %s incapable, disabled!%s\n' \
"${COLOR_ERR_ON}" "${SHELL}" "${COLOR_ERR_OFF}"
printf >&2 '%s! No process groups available, killed tests may '\
'leave process "zombies"!%s\n' \
"${COLOR_ERR_ON}" "${COLOR_ERR_OFF}"
fi
;;
*)
JOBMON=
;;
esac
}
jobreaper_stop() {
if [ ${JOBS} -gt 0 ]; then
echo 'Cleaning up running jobs'
[ -n "${JOBREAPER}" ] && kill -KILL ${JOBREAPER} >/dev/null 2>&1
jtimeout
wait ${JOBLIST}
JOBLIST=
fi
}
jspawn() {
if [ -n "${CHECK}" ] && [ -n "${SKIPTEST}" ]; then
i="${@}"
j="${1}"
k=
set -- ${SKIPTEST}
SKIPTEST=
while [ ${#} -gt 0 ]; do
if [ "${1}" != "${j}" ]; then
SKIPTEST="${SKIPTEST} ${1}"
elif [ -z "${k}" ]; then
k=y
t_echoskip ${1}
fi
shift
done
[ -n "${k}" ] && return
set -- "${i}"
fi
if [ ${MAXJOBS} -gt 1 ]; then
# We are spawning multiple jobs..
[ ${JOBS} -eq 0 ] && printf '...'
JOBS=`add ${JOBS} 1`
printf ' [%s=%s]' ${JOBS} "${1}"
else
JOBS=1
# Assume problems exist, do not let user keep hanging on terminal
if [ -n "${RUN_TEST}" ]; then
printf '... [%s]\n' "${1}"
fi
fi
[ -n "${JOBMON}" ] && set -m >/dev/null 2>&1
( # Place the job in its own directory to ease file management
trap '' EXIT HUP INT QUIT TERM USR1 USR2
${mkdir} t.${JOBS}.d && cd t.${JOBS}.d &&
eval t_${1} ${JOBS} ${1} &&
${rm} -f ../t.${JOBS}.id
) > t.${JOBS}.io </dev/null & # 2>&1 </dev/null &
i=${!}
[ -n "${JOBMON}" ] && set +m >/dev/null 2>&1
JOBLIST="${JOBLIST} ${i}"
printf '%s\n%s\n' ${i} ${1} > t.${JOBS}.id
# ..until we should sync or reach the maximum concurrent number
[ ${JOBS} -lt ${MAXJOBS} ] && return
jsync 1
}
jsync() {
if [ ${JOBS} -eq 0 ]; then
[ -n "${TEST_ANY}" ] && printf '\n'
TEST_ANY=
return
fi
[ -z "${JOBSYNC}" ] && [ ${#} -eq 0 ] && return
[ ${MAXJOBS} -ne 1 ] && printf ' .. waiting\n'
# Start an asynchronous notify process
${rm} -f ./t.time.out
(
sleep ${JOBWAIT} &
sleeper=${!}
trap "kill -TERM ${sleeper}; exit 1" HUP INT TERM
wait ${sleeper}
trap '' HUP INT TERM
printf '' > ./t.time.out
) </dev/null >/dev/null 2>&1 &
JOBREAPER=${!}
# Then loop a while, looking out for collecting tests
loops=0
while :; do
[ -f ./t.time.out ] && break
alldone=1
i=0
while [ ${i} -lt ${JOBS} ]; do
i=`add ${i} 1`
[ -f t.${i}.id ] || continue
alldone=
break
done
[ -n "${alldone}" ] && break
if [ -z "${SUBSECOND_SLEEP}" ]; then
loops=`add ${loops} 1`
[ ${loops} -lt 111 ] && continue
sleep 1 &
else
sleep .25 &
fi
wait ${!}
done
if [ -f ./t.time.out ]; then
${rm} -f ./t.time.out
jtimeout
else
kill -TERM ${JOBREAPER} >/dev/null 2>&1
fi
wait ${JOBREAPER}
JOBREAPER=
# Now collect the zombies
wait ${JOBLIST}
JOBLIST=
# Update global counters
i=0
while [ ${i} -lt ${JOBS} ]; do
i=`add ${i} 1`
[ -s t.${i}.io ] && ${cat} t.${i}.io
if [ -n "${DUMPERR}" ] && [ -s ./t.${i}.d/${ERR} ]; then
printf '%s [Debug/Devel: nullified errors]\n' "${COLOR_DBGERR_ON}"
while read l; do
printf ' %s\n' "${l}"
done < t.${i}.d/${ERR}
printf '%s' "${COLOR_DBGERR_OFF}"
fi
if [ -f t.${i}.id ]; then
{ read pid; read desc; } < t.${i}.id
desc=${desc#${desc%%[! ]*}}
desc=${desc%${desc##*[! ]}}
[ -s t.${i}.io ] && printf >&2 '\n'
printf >&2 '%s!! Timeout: reaped job %s [%s]%s\n' \
"${COLOR_ERR_ON}" ${i} "${desc}" "${COLOR_ERR_OFF}"
TESTS_FAILED=`add ${TESTS_FAILED} 1`
elif [ -s t.${i}.result ]; then
read es tp to tf ts < t.${i}.result
TESTS_PERFORMED=`add ${TESTS_PERFORMED} ${tp}`
TESTS_OK=`add ${TESTS_OK} ${to}`
TESTS_FAILED=`add ${TESTS_FAILED} ${tf}`
TESTS_SKIPPED=`add ${TESTS_SKIPPED} ${ts}`
[ "${es}" != 0 ] && ESTAT=${es}
else
TESTS_FAILED=`add ${TESTS_FAILED} 1`
ESTAT=1
fi
done
[ -z "${MAILX_CC_TEST_NO_CLEANUP}" ] &&
${rm} -rf ./t.*.d ./t.*.id ./t.*.io t.*.result ./t.time.out
JOBS=0
}
jtimeout() {
i=0
while [ ${i} -lt ${JOBS} ]; do
i=`add ${i} 1`
if [ -f t.${i}.id ] &&
read pid < t.${i}.id >/dev/null 2>&1 &&
kill -0 ${pid} >/dev/null 2>&1; then
j=${pid}
[ -n "${JOBMON}" ] && j=-${j}
kill -KILL ${j} >/dev/null 2>&1
else
${rm} -f t.${i}.id
fi
done
}
# }}}
# echoes, checks, etc. {{{
t_prolog() {
shift
ESTAT=0 TESTS_PERFORMED=0 TESTS_OK=0 TESTS_FAILED=0 TESTS_SKIPPED=0 \
TEST_NAME=${1} TEST_ANY=
printf '%s[%s]%s\n' "" "${TEST_NAME}" ""
}
t_epilog() {
[ -n "${TEST_ANY}" ] && printf '\n'
printf '%s %s %s %s %s\n' \
${ESTAT} \
${TESTS_PERFORMED} ${TESTS_OK} ${TESTS_FAILED} ${TESTS_SKIPPED} \
> ../t.${1}.result
}
t_echo() {
[ -n "${TEST_ANY}" ] && __i__=' ' || __i__=
printf "${__i__}"'%s' "${*}"
TEST_ANY=1
}
t_echook() {
[ -n "${TEST_ANY}" ] && __i__=' ' || __i__=
printf "${__i__}"'%s%s:ok%s' "${COLOR_OK_ON}" "${*}" "${COLOR_OK_OFF}"
TEST_ANY=1
}
t_echoerr() {
ESTAT=1
t_echo0err "${@}"
}
t_echo0err() {
[ -n "${TEST_ANY}" ] && __i__="\n" || __i__=
printf "${__i__}"'%sERROR: %s%s\n' \
"${COLOR_ERR_ON}" "${*}" "${COLOR_ERR_OFF}"
TEST_ANY=
}
t_echowarn() {
[ -n "${TEST_ANY}" ] && __i__=' ' || __i__=
printf "${__i__}"'%s%s%s' "${COLOR_WARN_ON}" "${*}" "${COLOR_WARN_OFF}"
TEST_ANY=1
}
t_echoskip() {
[ -n "${TEST_ANY}" ] && __i__=' ' || __i__=
printf "${__i__}"'%s%s[skip]%s' \
"${COLOR_WARN_ON}" "${*}" "${COLOR_WARN_OFF}"
TEST_ANY=1
TESTS_SKIPPED=`add ${TESTS_SKIPPED} 1`
}
check() {
restat=${?} tid=${1} eestat=${2} f=${3} s=${4} optmode=${5}
TESTS_PERFORMED=`add ${TESTS_PERFORMED} 1`
case "${optmode}" in
'') ;;
async)
[ "$eestat" = - ] || exit 200
while :; do
[ -f "${f}" ] && break
t_echowarn "[${tid}:async=wait]"
sleep 1 &
wait ${!}
done
;;
*) exit 222;;
esac
check__bad= check__runx=
if [ "${eestat}" != - ] && [ "${restat}" != "${eestat}" ]; then
ESTAT=1
t_echoerr "${tid}: bad-status: ${restat} != ${eestat}"
check__bad=1
fi
csum="`${cksum} < "${f}" | ${sed} -e 's/[ ]\{1,\}/ /g'`"
if [ "${csum}" = "${s}" ]; then
t_echook "${tid}"
check__runx=${DEVELDIFF}
else
ESTAT=1
t_echoerr "${tid}: checksum mismatch (got ${csum})"
check__bad=1 check__runx=1
fi
if [ -z "${check__bad}" ]; then
TESTS_OK=`add ${TESTS_OK} 1`
else
TESTS_FAILED=`add ${TESTS_FAILED} 1`
fi
if [ -n "${CHECK}${RUN_TEST}" ]; then
x="t.${TEST_NAME}-${tid}"
if [ -n "${RUN_TEST}" ] ||
[ -n "${check__runx}" -a -n "${GIT_REPO}" ]; then
${cp} -f "${f}" ../"${x}"
fi
if [ -n "${check__runx}" ] && [ -n "${GIT_REPO}" ] &&
command -v diff >/dev/null 2>&1; then
y=test-out
if (git rev-parse --verify $y) >/dev/null 2>&1; then :; else
y=refs/remotes/origin/test-out
(git rev-parse --verify $y) >/dev/null 2>&1 || y=
fi
if [ -n "${y}" ]; then
if GIT_CONFIG=/dev/null git show "${y}":"${x}" > \
../"${x}".old 2>/dev/null; then
diff -ru ../"${x}".old ../"${x}" > ../"${x}".diff
if [ ${?} -eq 0 ]; then
[ -z "${MAILX_CC_TEST_NO_CLEANUP}" ] &&
${rm} -f ../"${x}" ../"${x}".old ../"${x}".diff
elif [ -n "${MAILX_CC_ALL_TESTS_DUMPERR}" ]; then
while read l; do
printf 'ERROR-DIFF %s\n' "${l}"
done < ../"${x}".diff
fi
else
t_echo0err "${tid}: misses [test-out] template"
fi
fi
fi
fi
}
check_ex0() {
# $1=test name [$2=status]
__qm__=${?}
[ ${#} -gt 1 ] && __qm__=${2}
TESTS_PERFORMED=`add ${TESTS_PERFORMED} 1`
if [ ${__qm__} -ne 0 ]; then
ESTAT=1
t_echoerr "${1}: unexpected non-0 exit status: ${__qm__}"
TESTS_FAILED=`add ${TESTS_FAILED} 1`
else
t_echook "${1}"
TESTS_OK=`add ${TESTS_OK} 1`
fi
}
check_exn0() {
# $1=test name [$2=status]
__qm__=${?}
[ ${#} -gt 1 ] && __qm__=${2}
[ ${#} -gt 2 ] && __expect__=${3} || __expect__=
TESTS_PERFORMED=`add ${TESTS_PERFORMED} 1`
if [ ${__qm__} -eq 0 ]; then
ESTAT=1
t_echoerr "${1}: unexpected 0 exit status: ${__qm__}"
TESTS_FAILED=`add ${TESTS_FAILED} 1`
elif [ -n "${__expect__}" ] && [ ${__expect__} -ne ${__qm__} ]; then
ESTAT=1
t_echoerr "${1}: unexpected exit status: ${__qm__} != ${__expected__}"
TESTS_FAILED=`add ${TESTS_FAILED} 1`
else
t_echook "${1}"
TESTS_OK=`add ${TESTS_OK} 1`
fi
}
# }}}
color_init() {
[ -n "${NOCOLOUR}" ] && return
[ -n "${MAILX_CC_TEST_NO_COLOUR}" ] && return
# We do not want color for "make test > .LOG"!
if [ -t 1 ] && command -v tput >/dev/null 2>&1; then
{ sgr0=`tput sgr0`; } 2>/dev/null
[ $? -eq 0 ] || return
{ saf1=`tput setaf 1`; } 2>/dev/null
[ $? -eq 0 ] || return
{ saf2=`tput setaf 2`; } 2>/dev/null
[ $? -eq 0 ] || return
{ saf3=`tput setaf 3`; } 2>/dev/null
[ $? -eq 0 ] || return
{ saf5=`tput setaf 5`; } 2>/dev/null
[ $? -eq 0 ] || return
{ b=`tput bold`; } 2>/dev/null
[ $? -eq 0 ] || return
COLOR_ERR_ON=${saf1}${b} COLOR_ERR_OFF=${sgr0}
COLOR_DBGERR_ON=${saf5} COLOR_DBGERR_OFF=${sgr0}
COLOR_WARN_ON=${saf3}${b} COLOR_WARN_OFF=${sgr0}
COLOR_OK_ON=${saf2} COLOR_OK_OFF=${sgr0}
unset saf1 saf2 saf3 b
fi
}
if ( [ "$((1 + 1))" = 2 ] ) >/dev/null 2>&1; then
add() {
echo "$((${1} + ${2}))"
}
else
add() {
${awk} 'BEGIN{print '${1}' + '${2}'}'
}
fi
if ( [ "$((2 % 3))" = 2 ] ) >/dev/null 2>&1; then
modulo() {
echo "$((${1} % ${2}))"
}
else
modulo() {
${awk} 'BEGIN{print '${1}' % '${2}'}'
}
fi
have_feat() {
( "${RAWMAILX}" ${ARGS} -X'echo $features' -Xx |
${grep} ,+${1}, ) >/dev/null 2>&1
}
# }}}
# Absolute Basics {{{
t_X_Y_opt_input_go_stack() {
t_prolog "${@}"
${cat} <<- '__EOT' > "${BODY}"
echo 1
define mac0 {
echo mac0-1 via1 $0
}
call mac0
echo 2
source '\
echo "define mac1 {";\
echo " echo mac1-1 via1 \$0";\
echo " call mac0";\
echo " echo mac1-2";\
echo " call mac2";\
echo " echo mac1-3";\
echo "}";\
echo "echo 1-1";\
echo "define mac2 {";\
echo " echo mac2-1 via1 \$0";\
echo " call mac0";\
echo " echo mac2-2";\
echo "}";\
echo "echo 1-2";\
echo "call mac1";\
echo "echo 1-3";\
echo "source \"\
echo echo 1-1-1 via1 \$0;\
echo call mac0;\
echo echo 1-1-2;\
| \"";\
echo "echo 1-4";\
| '
echo 3
call mac2
echo 4
undefine *
__EOT
# The -X option supports multiline arguments, and those can internally use
# reverse solidus newline escaping. And all -X options are joined...
APO=\'
< "${BODY}" ${MAILX} ${ARGS} \
-X 'e\' \
-X ' c\' \
-X ' h\' \
-X ' o \' \
-X 1 \
-X'
define mac0 {
echo mac0-1 via2 $0
}
call mac0
echo 2
' \
-X'
source '${APO}'\
echo "define mac1 {";\
echo " echo mac1-1 via2 \$0";\
echo " call mac0";\
echo " echo mac1-2";\
echo " call mac2";\
echo " echo mac1-3";\
echo "}";\
echo "echo 1-1";\
echo "define mac2 {";\
echo " echo mac2-1 via2 \$0";\
echo " call mac0";\
echo " echo mac2-2";\
echo "}";\
echo "echo 1-2";\
echo "call mac1";\
echo "echo 1-3";\
echo "source \"\
echo echo 1-1-1 via2 \$0;\
echo call mac0;\
echo echo 1-1-2;\
| \"";\
echo "echo 1-4";\
| '${APO}'
echo 3
' \
-X'
call mac2
echo 4
undefine *
' > "${MBOX}"
check 1 0 "${MBOX}" '1786542668 416'
# The -Y option supports multiline arguments, and those can internally use
# reverse solidus newline escaping.
APO=\'
< "${BODY}" ${MAILX} ${ARGS} \
-X 'echo FIRST_X' \
-X 'echo SECOND_X' \
-Y 'e\' \
-Y ' c\' \
-Y ' h\' \
-Y ' o \' \
-Y 1 \
-Y'
define mac0 {
echo mac0-1 via2 $0
}
call mac0
echo 2
' \
-Y'
source '${APO}'\
echo "define mac1 {";\
echo " echo mac1-1 via2 \$0";\
echo " call mac0";\
echo " echo mac1-2";\
echo " call mac2";\
echo " echo mac1-3";\
echo "}";\
echo "echo 1-1";\
echo "define mac2 {";\
echo " echo mac2-1 via2 \$0";\
echo " call mac0";\
echo " echo mac2-2";\
echo "}";\
echo "echo 1-2";\
echo "call mac1";\
echo "echo 1-3";\
echo "source \"\
echo echo 1-1-1 via2 \$0;\
echo call mac0;\
echo echo 1-1-2;\
| \"";\
echo "echo 1-4";\
| '${APO}'
echo 3
' \
-Y'
call mac2
echo 4
undefine *
' \
-Y 'echo LAST_Y' > "${MBOX}"
check 2 0 "${MBOX}" '1845176711 440'
# Compose mode, too!