b78eee6946e87ffc5dc478c79af4ee7e88b232db
[nivanova/samba-autobuild/.git] / lib / subunit / shell / tests / test_function_output.sh
1 #!/bin/bash
2 #  subunit shell bindings.
3 #  Copyright (C) 2006  Robert Collins <robertc@robertcollins.net>
4 #
5 #  Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
6 #  license at the users choice. A copy of both licenses are available in the
7 #  project source as Apache-2.0 and BSD. You may not use this file except in
8 #  compliance with one of these two licences.
9 #  
10 #  Unless required by applicable law or agreed to in writing, software
11 #  distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
12 #  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
13 #  license you chose for the specific language governing permissions and
14 #  limitations under that license.
15 #
16
17
18 # this script tests the output of the methods. As each is tested we start using
19 # it.
20 # So the first test manually implements the entire protocol, the next uses the
21 # start method and so on.
22 # it is assumed that we are running from the 'shell' tree root in the source
23 # of subunit, and that the library sourcing tests have all passed - if they 
24 # have not, this test script may well fail strangely.
25
26 # import the library.
27 . ${SHELL_SHARE}subunit.sh
28
29 echo 'test: subunit_start_test output'
30 func_output=$(subunit_start_test "foo bar")
31 func_status=$?
32 if [ $func_status == 0 -a "x$func_output" = "xtest: foo bar" ]; then
33   echo 'success: subunit_start_test output'
34 else
35   echo 'failure: subunit_start_test output ['
36   echo 'got an error code or incorrect output:'
37   echo "exit: $func_status"
38   echo "output: '$func_output'"
39   echo ']' ;
40 fi
41
42 subunit_start_test "subunit_pass_test output"
43 func_output=$(subunit_pass_test "foo bar")
44 func_status=$?
45 if [ $func_status == 0 -a "x$func_output" = "xsuccess: foo bar" ]; then
46   subunit_pass_test "subunit_pass_test output"
47 else
48   echo 'failure: subunit_pass_test output ['
49   echo 'got an error code or incorrect output:'
50   echo "exit: $func_status"
51   echo "output: '$func_output'"
52   echo ']' ;
53 fi
54
55 subunit_start_test "subunit_fail_test output"
56 func_output=$(subunit_fail_test "foo bar" <<END
57 something
58   wrong
59 here
60 END
61 )
62 func_status=$?
63 if [ $func_status == 0 -a "x$func_output" = "xfailure: foo bar [
64 something
65   wrong
66 here
67 ]" ]; then
68   subunit_pass_test "subunit_fail_test output"
69 else
70   echo 'failure: subunit_fail_test output ['
71   echo 'got an error code or incorrect output:'
72   echo "exit: $func_status"
73   echo "output: '$func_output'"
74   echo ']' ;
75 fi
76
77 subunit_start_test "subunit_error_test output"
78 func_output=$(subunit_error_test "foo bar" <<END
79 something
80   died
81 here
82 END
83 )
84 func_status=$?
85 if [ $func_status == 0 -a "x$func_output" = "xerror: foo bar [
86 something
87   died
88 here
89 ]" ]; then
90   subunit_pass_test "subunit_error_test output"
91 else
92   subunit_fail_test "subunit_error_test output" <<END
93 got an error code or incorrect output:
94 exit: $func_status
95 output: '$func_output'
96 END
97 fi