1 | #
|
---|
2 | # subunit.sh: shell functions to report test status via the subunit protocol.
|
---|
3 | # Copyright (C) 2006 Robert Collins <robertc@robertcollins.net>
|
---|
4 | # Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
|
---|
5 | #
|
---|
6 | # This program is free software; you can redistribute it and/or modify
|
---|
7 | # it under the terms of the GNU General Public License as published by
|
---|
8 | # the Free Software Foundation; either version 2 of the License, or
|
---|
9 | # (at your option) any later version.
|
---|
10 | #
|
---|
11 | # This program is distributed in the hope that it will be useful,
|
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | # GNU General Public License for more details.
|
---|
15 | #
|
---|
16 | # You should have received a copy of the GNU General Public License
|
---|
17 | # along with this program; if not, write to the Free Software
|
---|
18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
19 | #
|
---|
20 |
|
---|
21 | subunit_start_test () {
|
---|
22 | # emit the current protocol start-marker for test $1
|
---|
23 | echo "test: $1"
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 | subunit_pass_test () {
|
---|
28 | # emit the current protocol test passed marker for test $1
|
---|
29 | echo "success: $1"
|
---|
30 | }
|
---|
31 |
|
---|
32 | # This is just a hack as we have some broken scripts
|
---|
33 | # which use "exit $failed", without initializing failed.
|
---|
34 | failed=0
|
---|
35 |
|
---|
36 | subunit_fail_test () {
|
---|
37 | # emit the current protocol fail-marker for test $1, and emit stdin as
|
---|
38 | # the error text.
|
---|
39 | # we use stdin because the failure message can be arbitrarily long, and this
|
---|
40 | # makes it convenient to write in scripts (using <<END syntax.
|
---|
41 | echo "failure: $1 ["
|
---|
42 | cat -
|
---|
43 | echo "]"
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | subunit_error_test () {
|
---|
48 | # emit the current protocol error-marker for test $1, and emit stdin as
|
---|
49 | # the error text.
|
---|
50 | # we use stdin because the failure message can be arbitrarily long, and this
|
---|
51 | # makes it convenient to write in scripts (using <<END syntax.
|
---|
52 | echo "error: $1 ["
|
---|
53 | cat -
|
---|
54 | echo "]"
|
---|
55 | }
|
---|
56 |
|
---|
57 | testit () {
|
---|
58 | name="$1"
|
---|
59 | shift
|
---|
60 | cmdline="$*"
|
---|
61 | subunit_start_test "$name"
|
---|
62 | output=`$cmdline 2>&1`
|
---|
63 | status=$?
|
---|
64 | if [ x$status = x0 ]; then
|
---|
65 | subunit_pass_test "$name"
|
---|
66 | else
|
---|
67 | echo "$output" | subunit_fail_test "$name"
|
---|
68 | fi
|
---|
69 | return $status
|
---|
70 | }
|
---|
71 |
|
---|
72 | testit_expect_failure () {
|
---|
73 | name="$1"
|
---|
74 | shift
|
---|
75 | cmdline="$*"
|
---|
76 | subunit_start_test "$name"
|
---|
77 | output=`$cmdline 2>&1`
|
---|
78 | status=$?
|
---|
79 | if [ x$status = x0 ]; then
|
---|
80 | echo "$output" | subunit_fail_test "$name"
|
---|
81 | else
|
---|
82 | subunit_pass_test "$name"
|
---|
83 | fi
|
---|
84 | return $status
|
---|
85 | }
|
---|
86 |
|
---|
87 | testok () {
|
---|
88 | name=`basename $1`
|
---|
89 | shift
|
---|
90 | failed=$2
|
---|
91 | shift
|
---|
92 |
|
---|
93 | exit $failed
|
---|
94 | }
|
---|
95 |
|
---|
96 | # work out the top level source directory
|
---|
97 | if [ -d source4 ]; then
|
---|
98 | SRCDIR="."
|
---|
99 | else
|
---|
100 | SRCDIR=".."
|
---|
101 | fi
|
---|
102 | export SRCDIR
|
---|