blob: 5815aabae56daca6733ff30c4ec16ed61cd133aa (
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
|
: ksh regression test harness :
USAGE_LICENSE="[-author?David Korn <dgk@research.att.com>][-author?Glenn Fowler <gsf@research.att.com>][-copyright?Copyright (c) 2000-2011 AT&T Intellectual Property][-license?http://www.opensource.org/licenses/cpl1.0.txt]"
command=shtests
setslocale='*@(locale).sh'
timesensitive='*@(options|sigchld|subshell).sh'
USAGE=$'
[-s8?
@(#)$Id: shtests (AT&T Research) 2011-08-08 $
]
'$USAGE_LICENSE$'
[+NAME?shtests - ksh regression test harness]
[+DESCRIPTION?\bshtests\b is the \bksh\b(1) regression test harness for
\b$SHELL\b or \bksh\b if \bSHELL\b is not defined and exported. If
none of the \b--posix --utf8 --compile\b options are specified then
all three are enabled.]
[+INPUT FILES?\bshtests\b regression test files are shell scripts that
run in an environment controlled by \bshtests\b. An identification
message is printed before and after each test on the standard output.
The default environment settings are:]
{
[+unset LANG]
[+unset LC_ALL]
[+LC_NUMERIC=C?\b.\b radix point assumed by all test scripts.]
[+VMALLOC_OPTIONS=abort?\bvmalloc\b(1) arena checking enabled
with \babort(2)\b on error.]
}
[c:compile?Run test scripts using \bshcomp\b(1).]
[d:debug?Enable \bshtests\b execution trace.]
[l:locale?Disable \b--utf8\b and run the \b--posix\b and \b--compile\b
tests, if enabled, in the locale of the caller. This may cause invalid
regressions, especially for locales where \b.\b is not the radix
point.]
[p:posix?Run the test scripts in the posix/C locale.]
[t!:time?Include the current date/time in the test identification
messages.]
[u:utf8?Run the test scripts in the ast-specific C.UTF-8 locale.]
[v!:vmalloc_options?Run tests with \bVMALLOC_OPTIONS=abort\b. Test
script names matching \b'$timesensitive$'\b are run with
\bVMALLOC_OPTIONS\b unset.]
[x:trace?Enable script execution trace.]
[ test.sh ... ] [ name=value ... ]
[+SEE ALSO?\bksh\b(1), \bregress\b(1), \brt\b(1)]
'
function usage
{
OPTIND=0
getopts -a $command "$USAGE" OPT '--??long'
exit 2
}
unset DISPLAY ENV FIGNORE HISTFILE
trap + PIPE # unadvertized -- set SIGPIPE to SIG_DFL #
integer compile=0 debug=0 locale=0 posix=0 time=1 utf8=0
typeset vmalloc_options=abort trace=
vmalloc_options= #XXX# until multi-region vmalloc trace fixed #XXX#
while getopts -a $command "$USAGE" OPT
do case $OPT in
c) if (( $OPTARG ))
then compile=2
else compile=0
fi
;;
d) debug=$OPTARG
;;
l) locale=$OPTARG
;;
p) posix=$OPTARG
;;
t) time=$OPTARG
;;
u) utf8=$OPTARG
;;
v) if (( OPTARG ))
then vmalloc_options=abort
else vmalloc_options=
fi
;;
x) trace=-x
;;
*) usage
;;
esac
done
shift $OPTIND-1
if (( debug )) || [[ $trace ]]
then export PS4=':$LINENO: '
if (( debug ))
then set -x
fi
fi
while [[ $1 == *=* ]]
do eval export "$1"
shift
done
if (( !compile && !posix && !utf8 ))
then compile=1
posix=1
utf8=1
fi
if (( locale ))
then utf8=0
if [[ $LC_ALL ]]
then export LANG=$LC_ALL
fi
else unset LANG LC_ALL
export LC_NUMERIC=C
fi
if [[ $VMALLOC_OPTIONS ]]
then vmalloc_options=$VMALLOC_OPTIONS
else VMALLOC_OPTIONS=$vmalloc_options
fi
[[ $VMALLOC_OPTIONS ]] || timesensitive=.
export PATH PWD SHCOMP SHELL VMALLOC_OPTIONS
PWD=$(pwd)
SHELL=${SHELL-ksh}
case $0 in
/*) d=$(dirname $0);;
*/*) d=$PWD/$(dirname $0);;
*) d=$PWD;;
esac
case $SHELL in
/*) ;;
*/*) SHELL=$d/$SHELL;;
*) SHELL=$(whence $SHELL);;
esac
PATH=/bin:/usr/bin
if [[ -d /usr/ucb ]]
then PATH=$PATH:/usr/ucb
fi
PATH=$PATH:$d
if [[ $INSTALLROOT && -r $INSTALLROOT/bin/.paths ]]
then PATH=$INSTALLROOT/bin:$PATH
fi
if [[ ${SHELL%/*} != $INSTALLROOT/bin ]]
then PATH=${SHELL%/*}:$PATH
fi
if [[ ! $SHCOMP ]]
then s=${SHELL:##*sh}
s=${SHELL:%/*}/shcomp$s
if [[ -x $s ]]
then SHCOMP=$s
elif [[ -x ${s%-g} ]]
then SHCOMP=${s%-g}
else SHCOMP=shcomp
fi
fi
if (( compile ))
then if whence $SHCOMP > /dev/null
then tmp=$(mktemp -dt) || { echo mktemp -dt failed >&2; exit 1; }
trap "cd /; rm -rf $tmp" EXIT
elif (( compile > 1 ))
then echo $0: --compile: $SHCOMP not found >&2
exit 1
else compile=0
fi
fi
typeset -A tests
for i in ${*-*.sh}
do if [[ ! -r $i ]]
then echo $0: $i: not found >&2
continue
fi
t=$(grep -c err_exit $i)
if (( t > 2 ))
then (( t = t - 2 ))
fi
tests[$i]=$t
T=test
if (( t != 1 ))
then T=${T}s
fi
u=${i##*/}
u=${u%.sh}
if [[ $i == $timesensitive ]]
then VMALLOC_OPTIONS=
fi
if (( posix || utf8 ))
then locales=
(( posix )) && locales+=" ${LANG:-C}"
[[ $utf8 == 0 || $i == $setslocale ]] || locales+=" C.UTF-8"
for lang in $locales
do o=$u
if [[ $lang == C ]]
then lang=
else o="$o($lang)"
lang=LANG=$lang
fi
echo test $o begins ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"}
E=error
if eval $lang \$SHELL \$trace \$i
then echo test $o passed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} "[ $t $T 0 ${E}s ]"
else e=$?
if (( e != 1 ))
then E=${E}s
fi
echo test $o failed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T $e $E ]"
fi
done
fi
if (( compile ))
then c=$tmp/shcomp-$u.ksh
o="$u(shcomp)"
echo test $o begins ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"}
E=error
if $SHCOMP $i > $c
then if $SHELL $trace $c
then echo test $o passed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} "[ $t $T 0 ${E}s ]"
else e=$?
if (( e != 1 ))
then E=${E}s
fi
echo test $o failed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T $e $E ]"
fi
else e=$?
t=1
T=test
echo test $o failed to compile ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T 1 $E ]"
fi
if [[ $i == $timesensitive ]]
then VMALLOC_OPTIONS=$vmalloc_options
fi
fi
done
|