blob: 4af6c0c7d87586d80d6e35c50b8f0fdd32aaa1b1 (
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
|
#! @SH@
#
# $NetBSD: pkg_regress.sh,v 1.4 2006/07/10 12:44:19 rillig Exp $
#
set -e
: ${PKGSRCDIR="@PKGSRCDIR@"}
: ${TEST_EGREP="@EGREP@"}
: ${TEST_MAKE="@MAKE@"}
# hooks overridable by test spec file
do_setup()
{
return
}
do_cleanup()
{
return
}
do_test()
{
do_test_default
}
do_test_default()
{
# Run the test. We use an if statement to ensure that the script
# isn't terminated if it is executed with sh -e.
if ${TEST_MAKE} ${MAKEARGS_TEST} >${TEST_OUTFILE} 2>&1
then
TEST_EXITSTATUS=$?
else
TEST_EXITSTATUS=$?
fi
}
check_result()
{
return
}
#
# Internal helper routines
#
# regress_fail <msg>
regress_fail() {
echo "ERROR: $*" 1>&2
TEST_RESULT=1
}
# result checking routines
# Test exit status
exit_status()
{
[ "$1" -eq "${TEST_EXITSTATUS}" ] \
|| regress_fail "Expected exit code $1, but got ${TEST_EXITSTATUS}."
}
# Test positive match against output
output_require()
{
for re in "$@"; do
${TEST_EGREP} "${re}" < ${TEST_OUTFILE} >/dev/null \
|| regress_fail "Expected \"${re}\" in the output, but it is not there."
done
}
# Test negative match against output
output_prohibit()
{
for re in "$@"; do
if ${TEST_EGREP} "${re}" < ${TEST_OUTFILE} >/dev/null; then
regress_fail "Didn't expect \"${re}\" in the output, but found it."
fi
done
}
# runtest runs a test in a subshell, so that environment settings etc in
# one test do not interfere with other tests.
runtest() {
if (
cd $1
TEST_RESULT=0
TEST_EXITSTATUS=0
TEST_OUTFILE=`mktemp -t pkg_regress` || exit 1
. ./spec
do_setup
do_test
check_result
# Perform cleanup
do_cleanup
if [ -n "${MAKEARGS_CLEAN}" ]
then
${TEST_MAKE} ${MAKEARGS_CLEAN} >>${TEST_OUTFILE}
fi
if [ -n "${TEST_VERBOSE}" ]
then
cat ${TEST_OUTFILE}
fi
rm -f ${TEST_OUTFILE}
exit ${TEST_RESULT}
)
then
TEST_PASS=`expr ${TEST_PASS} + 1`
else
TEST_FAIL=`expr ${TEST_FAIL} + 1`
TEST_FAILURES="${TEST_FAILURES} $1"
fi
}
TEST_PASS=0
TEST_FAIL=0
TEST_FAILURES=
cd $PKGSRCDIR/regress
case $1 in
-v) TEST_VERBOSE=1
shift ;;
esac
if [ $# -ne 0 ]
then
TEST_LIST="$@"
else
TEST_LIST="*"
fi
for dir in ${TEST_LIST}
do
if [ -f $dir/spec ]
then
runtest $dir
fi
done
if [ -n "${TEST_FAILURES}" ]
then
echo "Tests failed: ${TEST_FAILURES}"
echo
fi
echo "Statistics:"
echo " $TEST_PASS passed, $TEST_FAIL failed"
|