Sat Jun 11 09:37:16 2016 UTC ()
Updated pkg_regress to 0.3.

Changes since 0.2:

* provide usage message when called with invalid options
* moved do_test_default() from public API section in the source
* renamed private variables to not be in uppercase
* indented consistently
* replaced unnecessary ${VAR} with simple $VAR
* moved actual test execution into its own function
* when invoked with the -v option, announce which test will be run


(rillig)
diff -r1.13 -r1.14 pkgsrc/pkgtools/pkg_regress/Makefile
diff -r1.4 -r1.5 pkgsrc/pkgtools/pkg_regress/files/pkg_regress.sh

cvs diff -r1.13 -r1.14 pkgsrc/pkgtools/pkg_regress/Makefile (expand / switch to unified diff)

--- pkgsrc/pkgtools/pkg_regress/Makefile 2014/10/09 14:06:50 1.13
+++ pkgsrc/pkgtools/pkg_regress/Makefile 2016/06/11 09:37:16 1.14
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1# $NetBSD: Makefile,v 1.13 2014/10/09 14:06:50 wiz Exp $ 1# $NetBSD: Makefile,v 1.14 2016/06/11 09:37:16 rillig Exp $
2 2
3PKGNAME= pkg_regress-0.2 3PKGNAME= pkg_regress-0.3
4CATEGORIES= pkgtools 4CATEGORIES= pkgtools
5 5
6MAINTAINER= pkgsrc-users@NetBSD.org 6MAINTAINER= pkgsrc-users@NetBSD.org
7COMMENT= Run pkgsrc infrastructure regression test suite 7COMMENT= Run pkgsrc infrastructure regression test suite
8 8
9WRKSRC= ${WRKDIR} 9WRKSRC= ${WRKDIR}
10USE_LANGUAGES= # empty 10USE_LANGUAGES= # empty
11 11
12INSTALLATION_DIRS= sbin 12INSTALLATION_DIRS= sbin
13 13
14.include "../../mk/bsd.prefs.mk" 14.include "../../mk/bsd.prefs.mk"
15 15
16do-build: 16do-build:

cvs diff -r1.4 -r1.5 pkgsrc/pkgtools/pkg_regress/files/pkg_regress.sh (expand / switch to unified diff)

--- pkgsrc/pkgtools/pkg_regress/files/pkg_regress.sh 2006/07/10 12:44:19 1.4
+++ pkgsrc/pkgtools/pkg_regress/files/pkg_regress.sh 2016/06/11 09:37:16 1.5
@@ -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#
5set -e 5set -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
13do_setup() 13do_setup() {
14{ 
15 return 14 return
16} 15}
17 16
18do_cleanup() 17do_cleanup() {
19{ 
20 return 18 return
21} 19}
22 20
23do_test() 21do_test() {
24{ 
25 do_test_default 22 do_test_default
26} 23}
27 24
28do_test_default() 25check_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 
40check_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> 31do_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...
50regress_fail() { 41regress_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
59exit_status() 50exit_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
67output_require() 57output_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
77output_prohibit() 66output_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 75do_runtest() {
88# one test do not interfere with other tests. 76 cd "$1"
89runtest() { 
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.
 106runtest() {
 107 if [ "$verbose" = "yes" ]; then
 108 echo "Running $1"
 109 fi
128 110
129TEST_PASS=0 111 if (do_runtest "$1"); then
130TEST_FAIL=0 112 passed=`expr $passed + 1`
131TEST_FAILURES= 113 else
 114 failed=`expr $failed + 1`
 115 failed_names="$failed_names $1"
 116 fi
 117}
 118
 119verbose=no
 120passed=0
 121failed=0
 122failed_names=""
132 123
133cd $PKGSRCDIR/regress 124cd $PKGSRCDIR/regress
134 125
135case $1 in 126while [ $# -gt 0 ]; do
136 -v) TEST_VERBOSE=1 127 case "$1" in
137 shift ;; 128 -v) shift; verbose=yes;;
138esac 129 --) shift; break;;
139 130 -*) echo "usage: $0 [-v] [directory...]" 1>&2; exit 1 ;;
140if [ $# -ne 0 ] 131 *) break
141then 132 esac
142 TEST_LIST="$@" 133done
143else 134
144 TEST_LIST="*" 135if [ $# -eq 0 ]; then
 136 set -- *
145fi 137fi
146 138
147for dir in ${TEST_LIST} 139for dir in "$@"; do
148do 140 if [ -f $dir/spec ]; then
149 if [ -f $dir/spec ] 141 runtest $dir
150 then 142 fi
151 runtest $dir 
152 fi 
153done 143done
154 144
155if [ -n "${TEST_FAILURES}" ] 145if [ -n "$failed_names" ]; then
156then 146 echo "Tests failed:$failed_names"
157 echo "Tests failed: ${TEST_FAILURES}" 147 echo
158 echo 
159fi 148fi
160 149
161echo "Statistics:" 150echo "Statistics:"
162echo " $TEST_PASS passed, $TEST_FAIL failed" 151echo " $passed passed, $failed failed"