In a file, say, test/my_test.t:
source test-simple.bash tests 5
ok 0 '0 is true (other numbers are false)'
answer=$(question "...?") ok [ $answer == yes ] 'The answer is yes!' ok [[ $answer =~ ^y ]] 'The answer begins with y'
ok true 'true is ok' ok '! false' '! false is true'
Run the tests:
prove -ebash -v test/
The test-simple
library is meant to work for Bash, just like the
Test::Simple
module does in Perl.
You can run the tests under any TAP harness tool. The prove
utility is the
most popular one.
The library provides one function called ok()
:
ok <testing> <arguments> [<label>]
The last argument is assumed to be the a label, unless there is only one
argument, or unless its value is ]
or ]]
.
The test arguments are evaled and if the result is true, the test passes, otherwise it fails.