tests/dbcheck: Add a test for two live objects, with a dangling forward link
[sfrench/samba-autobuild/.git] / testprogs / blackbox / subunit.sh
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 timestamp() {
22   # mark the start time. With Gnu date, you get nanoseconds from %N
23   # (here truncated to microseconds with %6N), but not on BSDs,
24   # Solaris, etc, which will apparently leave either %N or N at the end.
25   date -u +'time: %Y-%m-%d %H:%M:%S.%6NZ' | sed 's/\..*NZ$/.000000Z/'
26 }
27
28 subunit_start_test () {
29   # emit the current protocol start-marker for test $1
30   timestamp
31   echo "test: $1"
32 }
33
34
35 subunit_pass_test () {
36   # emit the current protocol test passed marker for test $1
37   timestamp
38   echo "success: $1"
39 }
40
41 # This is just a hack as we have some broken scripts
42 # which use "exit $failed", without initializing failed.
43 failed=0
44
45 subunit_fail_test () {
46   # emit the current protocol fail-marker for test $1, and emit stdin as
47   # the error text.
48   # we use stdin because the failure message can be arbitrarily long, and this
49   # makes it convenient to write in scripts (using <<END syntax.
50   timestamp
51   echo "failure: $1 ["
52   cat -
53   echo "]"
54 }
55
56
57 subunit_error_test () {
58   # emit the current protocol error-marker for test $1, and emit stdin as
59   # the error text.
60   # we use stdin because the failure message can be arbitrarily long, and this
61   # makes it convenient to write in scripts (using <<END syntax.
62   timestamp
63   echo "error: $1 ["
64   cat -
65   echo "]"
66 }
67
68 subunit_skip_test () {
69   # emit the current protocol skip-marker for test $1, and emit stdin as
70   # the error text.
71   # we use stdin because the failure message can be arbitrarily long, and this
72   # makes it convenient to write in scripts (using <<END syntax.
73   echo "skip: $1 ["
74   cat -
75   echo "]"
76 }
77
78 testit () {
79         name="$1"
80         shift
81         cmdline="$*"
82         subunit_start_test "$name"
83         output=`$cmdline 2>&1`
84         status=$?
85         if [ x$status = x0 ]; then
86                 subunit_pass_test "$name"
87         else
88                 echo "$output" | subunit_fail_test "$name"
89         fi
90         return $status
91 }
92
93 testit_expect_failure () {
94         name="$1"
95         shift
96         cmdline="$*"
97         subunit_start_test "$name"
98         output=`$cmdline 2>&1`
99         status=$?
100         if [ x$status = x0 ]; then
101                 echo "$output" | subunit_fail_test "$name"
102         else
103                 subunit_pass_test "$name"
104         fi
105         return $status
106 }
107
108 testok () {
109         name=`basename $1`
110         failed=$2
111
112         exit $failed
113 }
114
115 # work out the top level source directory
116 if [ -d source4 ]; then
117     SRCDIR="."
118 else
119     SRCDIR=".."
120 fi
121 export SRCDIR