pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkg_regress Updated pkg_regress to 0.3.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/c07358d156bb
branches:  trunk
changeset: 348251:c07358d156bb
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Jun 11 09:37:16 2016 +0000

description:
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

diffstat:

 pkgtools/pkg_regress/Makefile             |    4 +-
 pkgtools/pkg_regress/files/pkg_regress.sh |  151 +++++++++++++----------------
 2 files changed, 72 insertions(+), 83 deletions(-)

diffs (237 lines):

diff -r 0621898ea296 -r c07358d156bb pkgtools/pkg_regress/Makefile
--- a/pkgtools/pkg_regress/Makefile     Sat Jun 11 06:29:41 2016 +0000
+++ b/pkgtools/pkg_regress/Makefile     Sat Jun 11 09:37:16 2016 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.13 2014/10/09 14:06:50 wiz Exp $
+# $NetBSD: Makefile,v 1.14 2016/06/11 09:37:16 rillig Exp $
 
-PKGNAME=       pkg_regress-0.2
+PKGNAME=       pkg_regress-0.3
 CATEGORIES=    pkgtools
 
 MAINTAINER=    pkgsrc-users%NetBSD.org@localhost
diff -r 0621898ea296 -r c07358d156bb pkgtools/pkg_regress/files/pkg_regress.sh
--- a/pkgtools/pkg_regress/files/pkg_regress.sh Sat Jun 11 06:29:41 2016 +0000
+++ b/pkgtools/pkg_regress/files/pkg_regress.sh Sat Jun 11 09:37:16 2016 +0000
@@ -1,6 +1,6 @@
 #! @SH@
 #
-# $NetBSD: pkg_regress.sh,v 1.4 2006/07/10 12:44:19 rillig Exp $
+# $NetBSD: pkg_regress.sh,v 1.5 2016/06/11 09:37:16 rillig Exp $
 #
 set -e
 
@@ -10,43 +10,34 @@
 
 # hooks overridable by test spec file
 
-do_setup()
-{
+do_setup() {
        return
 }
 
-do_cleanup()
-{
+do_cleanup() {
        return
 }
 
-do_test()
-{
+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=$?
+check_result() {
+       return
+}
+
+# Internal helper functions
+
+do_test_default() {
+       # The if is necessary to prevent sh -e from exiting.
+       if $TEST_MAKE $MAKEARGS_TEST >$TEST_OUTFILE 2>&1; then
+               TEST_EXITSTATUS=$?
        else
-           TEST_EXITSTATUS=$?
+               TEST_EXITSTATUS=$?
        fi
 }
 
-check_result()
-{
-       return
-}
-
-#
-# Internal helper routines
-#
-
-# regress_fail <msg>
+# usage: regress_fail msg...
 regress_fail() {
 
        echo "ERROR: $*" 1>&2
@@ -55,40 +46,34 @@
 
 # result checking routines
 
-# Test exit status
-exit_status()
-{
+# Text exit status
+exit_status() {
 
-       [ "$1" -eq "${TEST_EXITSTATUS}" ] \
-       || regress_fail "Expected exit code $1, but got ${TEST_EXITSTATUS}."
+       [ "$1" -eq "$TEST_EXITSTATUS" ] \
+       || regress_fail "Expected exit code $1, but got $TEST_EXITSTATUS."
 }
 
 # Test positive match against output
-output_require()
-{
+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."
+               $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()
-{
+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."
+               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
+do_runtest() {
+       cd "$1"
        TEST_RESULT=0
        TEST_EXITSTATUS=0
        TEST_OUTFILE=`mktemp -t pkg_regress` || exit 1
@@ -104,59 +89,63 @@
 
        do_cleanup
 
-       if [ -n "${MAKEARGS_CLEAN}" ]
-       then
-           ${TEST_MAKE} ${MAKEARGS_CLEAN} >>${TEST_OUTFILE}
+       if [ -n "$MAKEARGS_CLEAN" ]; then
+               $TEST_MAKE $MAKEARGS_CLEAN >>$TEST_OUTFILE
        fi
 
-       if [ -n "${TEST_VERBOSE}" ]
-       then
-           cat ${TEST_OUTFILE}
+       if [ "$verbose" = "yes" ]; 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
+       rm -f $TEST_OUTFILE
+       exit $TEST_RESULT
 }
 
+# runtest runs a test in a subshell, so that environment settings etc in
+# one test do not interfere with other tests.
+runtest() {
+       if [ "$verbose" = "yes" ]; then
+               echo "Running $1"
+       fi
 
-TEST_PASS=0
-TEST_FAIL=0
-TEST_FAILURES=
+       if (do_runtest "$1"); then
+               passed=`expr $passed + 1`
+       else
+               failed=`expr $failed + 1`
+               failed_names="$failed_names $1"
+       fi
+}
+
+verbose=no
+passed=0
+failed=0
+failed_names=""
 
 cd $PKGSRCDIR/regress
 
-case $1 in
-    -v) TEST_VERBOSE=1
-       shift ;;
-esac
+while [ $# -gt 0 ]; do
+       case "$1" in
+       -v) shift; verbose=yes;;
+       --) shift; break;;
+       -*) echo "usage: $0 [-v] [directory...]" 1>&2; exit 1 ;;
+       *) break
+       esac
+done
 
-if [ $# -ne 0 ]
-then
-    TEST_LIST="$@"
-else
-    TEST_LIST="*"
+if [ $# -eq 0 ]; then
+       set -- *
 fi
 
-for dir in ${TEST_LIST}
-do
-    if [ -f $dir/spec ]
-    then
-       runtest $dir
-    fi
+for dir in "$@"; do
+       if [ -f $dir/spec ]; then
+               runtest $dir
+       fi
 done
 
-if [ -n "${TEST_FAILURES}" ]
-then
-    echo "Tests failed: ${TEST_FAILURES}"
-    echo
+if [ -n "$failed_names" ]; then
+       echo "Tests failed:$failed_names"
+       echo
 fi
 
 echo "Statistics:"
-echo "  $TEST_PASS passed, $TEST_FAIL failed"
+echo "  $passed passed, $failed failed"



Home | Main Index | Thread Index | Old Index