Fix unexpected EOF error in shell function tests.
[third_party/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 #  This program is free software; you can redistribute it and/or modify
6 #  it under the terms of the GNU General Public License as published by
7 #  the Free Software Foundation; either version 2 of the License, or
8 #  (at your option) any later version.
9 #
10 #  This program is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #  GNU General Public License for more details.
14 #
15 #  You should have received a copy of the GNU General Public License
16 #  along with this program; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 #
19
20
21 # this script tests the output of the methods. As each is tested we start using
22 # it.
23 # So the first test manually implements the entire protocol, the next uses the
24 # start method and so on.
25 # it is assumed that we are running from the 'shell' tree root in the source
26 # of subunit, and that the library sourcing tests have all passed - if they 
27 # have not, this test script may well fail strangely.
28
29 # import the library.
30 . ${SHELL_SHARE}subunit.sh
31
32 echo 'test: subunit_start_test output'
33 func_output=$(subunit_start_test "foo bar")
34 func_status=$?
35 if [ $func_status == 0 -a "x$func_output" = "xtest: foo bar" ]; then
36   echo 'success: subunit_start_test output'
37 else
38   echo 'failure: subunit_start_test output ['
39   echo 'got an error code or incorrect output:'
40   echo "exit: $func_status"
41   echo "output: '$func_output'"
42   echo ']' ;
43 fi
44
45 subunit_start_test "subunit_pass_test output"
46 func_output=$(subunit_pass_test "foo bar")
47 func_status=$?
48 if [ $func_status == 0 -a "x$func_output" = "xsuccess: foo bar" ]; then
49   subunit_pass_test "subunit_pass_test output"
50 else
51   echo 'failure: subunit_pass_test output ['
52   echo 'got an error code or incorrect output:'
53   echo "exit: $func_status"
54   echo "output: '$func_output'"
55   echo ']' ;
56 fi
57
58 subunit_start_test "subunit_fail_test output"
59 func_output=$(subunit_fail_test "foo bar" <<END
60 something
61   wrong
62 here
63 END
64 )
65 func_status=$?
66 if [ $func_status == 0 -a "x$func_output" = "xfailure: foo bar [
67 something
68   wrong
69 here
70 ]" ]; then
71   subunit_pass_test "subunit_fail_test output"
72 else
73   echo 'failure: subunit_fail_test output ['
74   echo 'got an error code or incorrect output:'
75   echo "exit: $func_status"
76   echo "output: '$func_output'"
77   echo ']' ;
78 fi
79
80 subunit_start_test "subunit_error_test output"
81 func_output=$(subunit_error_test "foo bar" <<END
82 something
83   died
84 here
85 END
86 )
87 func_status=$?
88 if [ $func_status == 0 -a "x$func_output" = "xerror: foo bar [
89 something
90   died
91 here
92 ]" ]; then
93   subunit_pass_test "subunit_error_test output"
94 else
95   subunit_fail_test "subunit_error_test output" <<END
96 got an error code or incorrect output:
97 exit: $func_status
98 output: '$func_output'
99 END
100 fi