1 |
commit: d40c49ba860483959dea26c38df0fa5a326c2aca |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Mar 14 05:53:30 2015 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Mar 14 05:53:30 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=d40c49ba |
7 |
|
8 |
tests: clean up a bit |
9 |
|
10 |
The functions.sh messes with PATH, so mangle it after we load it. |
11 |
|
12 |
Pull out pass/fail so tests can use it directly. |
13 |
|
14 |
Clean up the style of testit to be more bashy and safe (quotes). |
15 |
|
16 |
tests/lib.sh | 42 +++++++++++++++++++++++++----------------- |
17 |
1 file changed, 25 insertions(+), 17 deletions(-) |
18 |
|
19 |
diff --git a/tests/lib.sh b/tests/lib.sh |
20 |
index 20f67bd..93943a1 100644 |
21 |
--- a/tests/lib.sh |
22 |
+++ b/tests/lib.sh |
23 |
@@ -4,33 +4,41 @@ top_srcdir=`cd "${srcdir}/../.." && pwd` |
24 |
builddir=${srcdir} |
25 |
top_builddir=${top_srcdir} |
26 |
|
27 |
+[ -e /etc/init.d/functions.sh ] && source /etc/init.d/functions.sh |
28 |
+ |
29 |
PATH=${top_builddir}:${PATH} |
30 |
unset ROOT # who knows! |
31 |
|
32 |
-[ -e /etc/init.d/functions.sh ] && source /etc/init.d/functions.sh |
33 |
- |
34 |
ret=0 |
35 |
|
36 |
+pass() { |
37 |
+ echo "${GOOD}PASS${NORMAL}: $*" |
38 |
+} |
39 |
+ |
40 |
+fail() { |
41 |
+ ret=1 |
42 |
+ echo "${BAD}FAIL${NORMAL}: $*" >&2 |
43 |
+} |
44 |
+ |
45 |
testit() { |
46 |
local tret=0 err |
47 |
case $# in |
48 |
- 1) |
49 |
- if [ -s $1 ] ; then |
50 |
- tret=1 |
51 |
- err=$(<$1) |
52 |
- fi |
53 |
- ;; |
54 |
- 2) |
55 |
- if ! err=`diff -u $1 $2` ; then |
56 |
- tret=1 |
57 |
- fi |
58 |
+ 1) |
59 |
+ if [[ -s $1 ]] ; then |
60 |
+ tret=1 |
61 |
+ err=$(<"$1") |
62 |
+ fi |
63 |
+ ;; |
64 |
+ 2) |
65 |
+ if ! err=$(diff -u "$1" "$2") ; then |
66 |
+ tret=1 |
67 |
+ fi |
68 |
esac |
69 |
- if [ ${tret} -eq 0 ] ; then |
70 |
- echo ${GOOD}PASS${NORMAL}: $1 |
71 |
+ if [[ ${tret} -eq 0 ]] ; then |
72 |
+ pass "$1" |
73 |
else |
74 |
- ret=1 |
75 |
- echo ${BAD}FAIL${NORMAL}: $1 |
76 |
+ fail "$1" |
77 |
echo "${err}" |
78 |
fi |
79 |
- rm -f $1 |
80 |
+ rm -f "$1" |
81 |
} |