This is a prototype for doing shell tests. To run:
$ ./test/suite.sh
To add another test suite, make a script in the test directory that ends with
_test.sh
and ensure it is executable. Then follow the pattern in
example_test.sh
:
#!/bin/sh
. ${0%/$TEST_CASE}/helper.sh
test_echo_echos_a_string_to_stdout () {
# The assert_equal method will check that the echo command exits
# with status 0, and that the stdout is 'hello world'.
#
# There are similar assertions to just check the exit status
# or just check stdout.
assert_equal 0 "$(
echo 'hello world'
)" $LINENO <<stdout
hello world
stdout
# Write as many assertions as you please in a given method.
}
run_test_case
You can write as many test methods as you like... just follow the same conventions as in ruby's Test::Unit (ie start the method with test_
).
I think shell-based testing has a lot of potential. One nice feature is that there are no special requirements for the server -- you don't have to install ruby, or anything else. This prototype should only require POSIX compatibility. I've only tested it with bash, but I think it should work with zsh, tcsh, or whaterver-sh.
Another nice feature is that it allows you to use the same commands you use already. There is a great correspondence between the checks you'd manually run and what goes in here.
Obviously it's a bit confusing if you're unfamiliar with the shell, but there are ways around that... like learning the shell, or potentially something like linecook to which I intend to add support for this kind of thing.