diff options
author | Robert Collins <robertc@robertcollins.net> | 2006-04-15 00:53:37 +1000 |
---|---|---|
committer | Robert Collins <robertc@robertcollins.net> | 2006-04-15 00:53:37 +1000 |
commit | 06cee63c1b85757faae6a3676e66edbac0624aed (patch) | |
tree | 37e241cf5ab588aa27b91e800b2fe00e8b5d88a8 /shell | |
parent | 3bebe681fc9c80ced4cfdda1b8624dd64074e83a (diff) | |
download | subunit-06cee63c1b85757faae6a3676e66edbac0624aed.tar.gz |
Basic shell subunit bindings working.
Diffstat (limited to 'shell')
-rw-r--r-- | shell/Makefile | 2 | ||||
-rw-r--r-- | shell/README | 36 | ||||
-rw-r--r-- | shell/share/subunit.sh | 30 | ||||
-rwxr-xr-x | shell/tests/test_function_output.sh | 55 | ||||
-rwxr-xr-x | shell/tests/test_source_library.sh | 44 |
5 files changed, 164 insertions, 3 deletions
diff --git a/shell/Makefile b/shell/Makefile index 92b2a01..8a84b7a 100644 --- a/shell/Makefile +++ b/shell/Makefile @@ -1,7 +1,7 @@ all: check: - # check the core python bindings. + # check the shell bindings. python ./test_shell.py $(TESTRULE) .PHONY: all check diff --git a/shell/README b/shell/README index 38ffb4e..4132658 100644 --- a/shell/README +++ b/shell/README @@ -23,5 +23,41 @@ test scripts. You can use `make check` to run the tests. There is a trivial python test_shell.py which uses the pyunit gui to expose the test results in a compact form. +The shell bindings consist of four functions which you can use to output test +metadata trivially. See share/subunit.sh for the functions and comments. +However, this is not a full test environment, its support code for reporting to +subunit. You can look at ShUnit (http://shunit.sourceforge.net) for 'proper' +shell based xUnit functionality. I am currently integrating subunit into ShUnit +so you should be able to get both subunit an ShUnit easily. +If you are a test environment maintainer - either homegrown, or ShUnit or some +such, you will need to see how the subunit calls should be used. Here is what +a manually written test using the bindings might look like: + + +subunit_start_test "test name" +# determine if test passes or fails +result=$(something) +if [ $result == 0 ]; then + subunit_pass_test "test name" +else + subunit_fail_test "test name" <<END +Something went wrong running something: +exited with result: '$func_status' +END +fi + +Which when run with a subunit test runner will generate something like: +test name ... ok + +on success, and: + +test name ... FAIL + +====================================================================== +FAIL: test name +---------------------------------------------------------------------- +RemoteError: +Something went wrong running something: +exited with result: '1' diff --git a/shell/share/subunit.sh b/shell/share/subunit.sh index 0234737..89747c8 100644 --- a/shell/share/subunit.sh +++ b/shell/share/subunit.sh @@ -18,6 +18,34 @@ # function subunit_start_test () { - # emit the current protocol start-marker for test test_name + # emit the current protocol start-marker for test $1 echo "test: $1" } + + +function subunit_pass_test () { + # emit the current protocol test passed marker for test $1 + echo "success: $1" +} + + +function subunit_fail_test () { + # emit the current protocol fail-marker for test $1, and emit stdin as + # the error text. + # we use stdin because the failure message can be arbitrarily long, and this + # makes it convenient to write in scripts (using <<END syntax. + echo "failure: $1 [" + cat - + echo "]" +} + + +function subunit_error_test () { + # emit the current protocol error-marker for test $1, and emit stdin as + # the error text. + # we use stdin because the failure message can be arbitrarily long, and this + # makes it convenient to write in scripts (using <<END syntax. + echo "error: $1 [" + cat - + echo "]" +} diff --git a/shell/tests/test_function_output.sh b/shell/tests/test_function_output.sh index a57e6b9..35831f4 100755 --- a/shell/tests/test_function_output.sh +++ b/shell/tests/test_function_output.sh @@ -41,3 +41,58 @@ else echo "output: '$func_output'" echo ']' ; fi + +subunit_start_test "subunit_pass_test output" +func_output=$(subunit_pass_test "foo bar") +func_status=$? +if [ $func_status == 0 -a "x$func_output" = "xsuccess: foo bar" ]; then + subunit_pass_test "subunit_pass_test output" +else + echo 'failure: subunit_pass_test output [' + echo 'got an error code or incorrect output:' + echo "exit: $func_status" + echo "output: '$func_output'" + echo ']' ; +fi + +subunit_start_test "subunit_fail_test output" +func_output=$(subunit_fail_test "foo bar" <<END +something + wrong +here +END) +func_status=$? +if [ $func_status == 0 -a "x$func_output" = "xfailure: foo bar [ +something + wrong +here +]" ]; then + subunit_pass_test "subunit_fail_test output" +else + echo 'failure: subunit_fail_test output [' + echo 'got an error code or incorrect output:' + echo "exit: $func_status" + echo "output: '$func_output'" + echo ']' ; +fi + +subunit_start_test "subunit_error_test output" +func_output=$(subunit_error_test "foo bar" <<END +something + died +here +END) +func_status=$? +if [ $func_status == 0 -a "x$func_output" = "xerror: foo bar [ +something + died +here +]" ]; then + subunit_pass_test "subunit_error_test output" +else + subunit_fail_test "subunit_error_test output" <<END +got an error code or incorrect output: +exit: $func_status +output: '$func_output' +END +fi diff --git a/shell/tests/test_source_library.sh b/shell/tests/test_source_library.sh index 8fd10e6..765e42d 100755 --- a/shell/tests/test_source_library.sh +++ b/shell/tests/test_source_library.sh @@ -39,7 +39,7 @@ fi # now source it for real . share/subunit.sh -# we should have a test-start function +# we should have a start_test function echo 'test: subunit_start_test exists' found_type=$(type -t subunit_start_test) status=$? @@ -52,3 +52,45 @@ else echo "output: $found_type" echo ']' ; fi + +# we should have a pass_test function +echo 'test: subunit_pass_test exists' +found_type=$(type -t subunit_pass_test) +status=$? +if [ $status == 0 -a "x$found_type" = "xfunction" ]; then + echo 'success: subunit_pass_test exists' +else + echo 'failure: subunit_pass_test exists [' + echo 'subunit_pass_test is not a function:' + echo "type -t status: $status" + echo "output: $found_type" + echo ']' ; +fi + +# we should have a fail_test function +echo 'test: subunit_fail_test exists' +found_type=$(type -t subunit_fail_test) +status=$? +if [ $status == 0 -a "x$found_type" = "xfunction" ]; then + echo 'success: subunit_fail_test exists' +else + echo 'failure: subunit_fail_test exists [' + echo 'subunit_fail_test is not a function:' + echo "type -t status: $status" + echo "output: $found_type" + echo ']' ; +fi + +# we should have a error_test function +echo 'test: subunit_error_test exists' +found_type=$(type -t subunit_error_test) +status=$? +if [ $status == 0 -a "x$found_type" = "xfunction" ]; then + echo 'success: subunit_error_test exists' +else + echo 'failure: subunit_error_test exists [' + echo 'subunit_error_test is not a function:' + echo "type -t status: $status" + echo "output: $found_type" + echo ']' ; +fi |