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 |
|
---|
33 | subunit_fail_test () {
|
---|
34 | # emit the current protocol fail-marker for test $1, and emit stdin as
|
---|
35 | # the error text.
|
---|
36 | # we use stdin because the failure message can be arbitrarily long, and this
|
---|
37 | # makes it convenient to write in scripts (using <<END syntax.
|
---|
38 | echo "failure: $1 ["
|
---|
39 | cat -
|
---|
40 | echo "]"
|
---|
41 | }
|
---|
42 |
|
---|
43 |
|
---|
44 | subunit_error_test () {
|
---|
45 | # emit the current protocol error-marker for test $1, and emit stdin as
|
---|
46 | # the error text.
|
---|
47 | # we use stdin because the failure message can be arbitrarily long, and this
|
---|
48 | # makes it convenient to write in scripts (using <<END syntax.
|
---|
49 | echo "error: $1 ["
|
---|
50 | cat -
|
---|
51 | echo "]"
|
---|
52 | }
|
---|
53 |
|
---|
54 | testit () {
|
---|
55 | name="$1"
|
---|
56 | shift
|
---|
57 | cmdline="$*"
|
---|
58 | subunit_start_test "$name"
|
---|
59 | output=`$cmdline 2>&1`
|
---|
60 | status=$?
|
---|
61 | if [ x$status = x0 ]; then
|
---|
62 | subunit_pass_test "$name"
|
---|
63 | else
|
---|
64 | echo "$output" | subunit_fail_test "$name"
|
---|
65 | fi
|
---|
66 | return $status
|
---|
67 | }
|
---|
68 |
|
---|
69 | testit_expect_failure () {
|
---|
70 | name="$1"
|
---|
71 | shift
|
---|
72 | cmdline="$*"
|
---|
73 | subunit_start_test "$name"
|
---|
74 | output=`$cmdline 2>&1`
|
---|
75 | status=$?
|
---|
76 | if [ x$status = x0 ]; then
|
---|
77 | echo "$output" | subunit_fail_test "$name"
|
---|
78 | else
|
---|
79 | subunit_pass_test "$name"
|
---|
80 | fi
|
---|
81 | return $status
|
---|
82 | }
|
---|