| @@ -1,162 +1,151 @@ | | | @@ -1,162 +1,151 @@ |
1 | #! @SH@ | | 1 | #! @SH@ |
2 | # | | 2 | # |
3 | # $NetBSD: pkg_regress.sh,v 1.4 2006/07/10 12:44:19 rillig Exp $ | | 3 | # $NetBSD: pkg_regress.sh,v 1.5 2016/06/11 09:37:16 rillig Exp $ |
4 | # | | 4 | # |
5 | set -e | | 5 | set -e |
6 | | | 6 | |
7 | : ${PKGSRCDIR="@PKGSRCDIR@"} | | 7 | : ${PKGSRCDIR="@PKGSRCDIR@"} |
8 | : ${TEST_EGREP="@EGREP@"} | | 8 | : ${TEST_EGREP="@EGREP@"} |
9 | : ${TEST_MAKE="@MAKE@"} | | 9 | : ${TEST_MAKE="@MAKE@"} |
10 | | | 10 | |
11 | # hooks overridable by test spec file | | 11 | # hooks overridable by test spec file |
12 | | | 12 | |
13 | do_setup() | | 13 | do_setup() { |
14 | { | | | |
15 | return | | 14 | return |
16 | } | | 15 | } |
17 | | | 16 | |
18 | do_cleanup() | | 17 | do_cleanup() { |
19 | { | | | |
20 | return | | 18 | return |
21 | } | | 19 | } |
22 | | | 20 | |
23 | do_test() | | 21 | do_test() { |
24 | { | | | |
25 | do_test_default | | 22 | do_test_default |
26 | } | | 23 | } |
27 | | | 24 | |
28 | do_test_default() | | 25 | check_result() { |
29 | { | | | |
30 | # Run the test. We use an if statement to ensure that the script | | | |
31 | # isn't terminated if it is executed with sh -e. | | | |
32 | if ${TEST_MAKE} ${MAKEARGS_TEST} >${TEST_OUTFILE} 2>&1 | | | |
33 | then | | | |
34 | TEST_EXITSTATUS=$? | | | |
35 | else | | | |
36 | TEST_EXITSTATUS=$? | | | |
37 | fi | | | |
38 | } | | | |
39 | | | | |
40 | check_result() | | | |
41 | { | | | |
42 | return | | 26 | return |
43 | } | | 27 | } |
44 | | | 28 | |
45 | # | | 29 | # Internal helper functions |
46 | # Internal helper routines | | | |
47 | # | | | |
48 | | | 30 | |
49 | # regress_fail <msg> | | 31 | do_test_default() { |
| | | 32 | # The if is necessary to prevent sh -e from exiting. |
| | | 33 | if $TEST_MAKE $MAKEARGS_TEST >$TEST_OUTFILE 2>&1; then |
| | | 34 | TEST_EXITSTATUS=$? |
| | | 35 | else |
| | | 36 | TEST_EXITSTATUS=$? |
| | | 37 | fi |
| | | 38 | } |
| | | 39 | |
| | | 40 | # usage: regress_fail msg... |
50 | regress_fail() { | | 41 | regress_fail() { |
51 | | | 42 | |
52 | echo "ERROR: $*" 1>&2 | | 43 | echo "ERROR: $*" 1>&2 |
53 | TEST_RESULT=1 | | 44 | TEST_RESULT=1 |
54 | } | | 45 | } |
55 | | | 46 | |
56 | # result checking routines | | 47 | # result checking routines |
57 | | | 48 | |
58 | # Test exit status | | 49 | # Text exit status |
59 | exit_status() | | 50 | exit_status() { |
60 | { | | | |
61 | | | 51 | |
62 | [ "$1" -eq "${TEST_EXITSTATUS}" ] \ | | 52 | [ "$1" -eq "$TEST_EXITSTATUS" ] \ |
63 | || regress_fail "Expected exit code $1, but got ${TEST_EXITSTATUS}." | | 53 | || regress_fail "Expected exit code $1, but got $TEST_EXITSTATUS." |
64 | } | | 54 | } |
65 | | | 55 | |
66 | # Test positive match against output | | 56 | # Test positive match against output |
67 | output_require() | | 57 | output_require() { |
68 | { | | | |
69 | | | 58 | |
70 | for re in "$@"; do | | 59 | for re in "$@"; do |
71 | ${TEST_EGREP} "${re}" < ${TEST_OUTFILE} >/dev/null \ | | 60 | $TEST_EGREP "$re" < $TEST_OUTFILE >/dev/null \ |
72 | || regress_fail "Expected \"${re}\" in the output, but it is not there." | | 61 | || regress_fail "Expected \"$re\" in the output, but it is not there." |
73 | done | | 62 | done |
74 | } | | 63 | } |
75 | | | 64 | |
76 | # Test negative match against output | | 65 | # Test negative match against output |
77 | output_prohibit() | | 66 | output_prohibit() { |
78 | { | | | |
79 | | | 67 | |
80 | for re in "$@"; do | | 68 | for re in "$@"; do |
81 | if ${TEST_EGREP} "${re}" < ${TEST_OUTFILE} >/dev/null; then | | 69 | if $TEST_EGREP "$re" < $TEST_OUTFILE >/dev/null; then |
82 | regress_fail "Didn't expect \"${re}\" in the output, but found it." | | 70 | regress_fail "Didn't expect \"$re\" in the output, but found it." |
83 | fi | | 71 | fi |
84 | done | | 72 | done |
85 | } | | 73 | } |
86 | | | 74 | |
87 | # runtest runs a test in a subshell, so that environment settings etc in | | 75 | do_runtest() { |
88 | # one test do not interfere with other tests. | | 76 | cd "$1" |
89 | runtest() { | | | |
90 | if ( | | | |
91 | cd $1 | | | |
92 | TEST_RESULT=0 | | 77 | TEST_RESULT=0 |
93 | TEST_EXITSTATUS=0 | | 78 | TEST_EXITSTATUS=0 |
94 | TEST_OUTFILE=`mktemp -t pkg_regress` || exit 1 | | 79 | TEST_OUTFILE=`mktemp -t pkg_regress` || exit 1 |
95 | . ./spec | | 80 | . ./spec |
96 | | | 81 | |
97 | do_setup | | 82 | do_setup |
98 | | | 83 | |
99 | do_test | | 84 | do_test |
100 | | | 85 | |
101 | check_result | | 86 | check_result |
102 | | | 87 | |
103 | # Perform cleanup | | 88 | # Perform cleanup |
104 | | | 89 | |
105 | do_cleanup | | 90 | do_cleanup |
106 | | | 91 | |
107 | if [ -n "${MAKEARGS_CLEAN}" ] | | 92 | if [ -n "$MAKEARGS_CLEAN" ]; then |
108 | then | | 93 | $TEST_MAKE $MAKEARGS_CLEAN >>$TEST_OUTFILE |
109 | ${TEST_MAKE} ${MAKEARGS_CLEAN} >>${TEST_OUTFILE} | | | |
110 | fi | | 94 | fi |
111 | | | 95 | |
112 | if [ -n "${TEST_VERBOSE}" ] | | 96 | if [ "$verbose" = "yes" ]; then |
113 | then | | 97 | cat $TEST_OUTFILE |
114 | cat ${TEST_OUTFILE} | | | |
115 | fi | | 98 | fi |
116 | | | 99 | |
117 | rm -f ${TEST_OUTFILE} | | 100 | rm -f $TEST_OUTFILE |
118 | exit ${TEST_RESULT} | | 101 | exit $TEST_RESULT |
119 | ) | | | |
120 | then | | | |
121 | TEST_PASS=`expr ${TEST_PASS} + 1` | | | |
122 | else | | | |
123 | TEST_FAIL=`expr ${TEST_FAIL} + 1` | | | |
124 | TEST_FAILURES="${TEST_FAILURES} $1" | | | |
125 | fi | | | |
126 | } | | 102 | } |
127 | | | 103 | |
| | | 104 | # runtest runs a test in a subshell, so that environment settings etc in |
| | | 105 | # one test do not interfere with other tests. |
| | | 106 | runtest() { |
| | | 107 | if [ "$verbose" = "yes" ]; then |
| | | 108 | echo "Running $1" |
| | | 109 | fi |
128 | | | 110 | |
129 | TEST_PASS=0 | | 111 | if (do_runtest "$1"); then |
130 | TEST_FAIL=0 | | 112 | passed=`expr $passed + 1` |
131 | TEST_FAILURES= | | 113 | else |
| | | 114 | failed=`expr $failed + 1` |
| | | 115 | failed_names="$failed_names $1" |
| | | 116 | fi |
| | | 117 | } |
| | | 118 | |
| | | 119 | verbose=no |
| | | 120 | passed=0 |
| | | 121 | failed=0 |
| | | 122 | failed_names="" |
132 | | | 123 | |
133 | cd $PKGSRCDIR/regress | | 124 | cd $PKGSRCDIR/regress |
134 | | | 125 | |
135 | case $1 in | | 126 | while [ $# -gt 0 ]; do |
136 | -v) TEST_VERBOSE=1 | | 127 | case "$1" in |
137 | shift ;; | | 128 | -v) shift; verbose=yes;; |
138 | esac | | 129 | --) shift; break;; |
139 | | | 130 | -*) echo "usage: $0 [-v] [directory...]" 1>&2; exit 1 ;; |
140 | if [ $# -ne 0 ] | | 131 | *) break |
141 | then | | 132 | esac |
142 | TEST_LIST="$@" | | 133 | done |
143 | else | | 134 | |
144 | TEST_LIST="*" | | 135 | if [ $# -eq 0 ]; then |
| | | 136 | set -- * |
145 | fi | | 137 | fi |
146 | | | 138 | |
147 | for dir in ${TEST_LIST} | | 139 | for dir in "$@"; do |
148 | do | | 140 | if [ -f $dir/spec ]; then |
149 | if [ -f $dir/spec ] | | 141 | runtest $dir |
150 | then | | 142 | fi |
151 | runtest $dir | | | |
152 | fi | | | |
153 | done | | 143 | done |
154 | | | 144 | |
155 | if [ -n "${TEST_FAILURES}" ] | | 145 | if [ -n "$failed_names" ]; then |
156 | then | | 146 | echo "Tests failed:$failed_names" |
157 | echo "Tests failed: ${TEST_FAILURES}" | | 147 | echo |
158 | echo | | | |
159 | fi | | 148 | fi |
160 | | | 149 | |
161 | echo "Statistics:" | | 150 | echo "Statistics:" |
162 | echo " $TEST_PASS passed, $TEST_FAIL failed" | | 151 | echo " $passed passed, $failed failed" |