commit:     d40c49ba860483959dea26c38df0fa5a326c2aca
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sat Mar 14 05:53:30 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sat Mar 14 05:53:30 2015 +0000
URL:        https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=d40c49ba

tests: clean up a bit

The functions.sh messes with PATH, so mangle it after we load it.

Pull out pass/fail so tests can use it directly.

Clean up the style of testit to be more bashy and safe (quotes).

 tests/lib.sh | 42 +++++++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 17 deletions(-)

diff --git a/tests/lib.sh b/tests/lib.sh
index 20f67bd..93943a1 100644
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -4,33 +4,41 @@ top_srcdir=`cd "${srcdir}/../.." && pwd`
 builddir=${srcdir}
 top_builddir=${top_srcdir}
 
+[ -e /etc/init.d/functions.sh ] && source /etc/init.d/functions.sh
+
 PATH=${top_builddir}:${PATH}
 unset ROOT # who knows!
 
-[ -e /etc/init.d/functions.sh ] && source /etc/init.d/functions.sh
-
 ret=0
 
+pass() {
+       echo "${GOOD}PASS${NORMAL}: $*"
+}
+
+fail() {
+       ret=1
+       echo "${BAD}FAIL${NORMAL}: $*" >&2
+}
+
 testit() {
        local tret=0 err
        case $# in
-               1)
-                       if [ -s $1 ] ; then
-                               tret=1
-                               err=$(<$1)
-                       fi
-                       ;;
-               2)
-                       if ! err=`diff -u $1 $2` ; then
-                               tret=1
-                       fi
+       1)
+               if [[ -s $1 ]] ; then
+                       tret=1
+                       err=$(<"$1")
+               fi
+               ;;
+       2)
+               if ! err=$(diff -u "$1" "$2") ; then
+                       tret=1
+               fi
        esac
-       if [ ${tret} -eq 0 ] ; then
-               echo ${GOOD}PASS${NORMAL}: $1
+       if [[ ${tret} -eq 0 ]] ; then
+               pass "$1"
        else
-               ret=1
-               echo ${BAD}FAIL${NORMAL}: $1
+               fail "$1"
                echo "${err}"
        fi
-       rm -f $1
+       rm -f "$1"
 }

Reply via email to