Testing shell scripts with Testing Framework
TF – Testing Framework
For some time I have been testing shell scripts using my own creation TF – Testing Framework.
I’m proud to present release 0.4.0 of it today. It includes:
- 2-4x speed improvement depending on used Ruby interpreter,
- add support for different shells via shebang
- improved validation of environment variables, including array variables testing and testing environment variable type,
- extended output matching allowing to separately match
stdout
andstderr
,
Installation
Install using (ruby required):
gem install tf
Supported tests
The test can be negated by replacing =
with !=
:
#status=<number>
– check if command returned given status (0 is success)#match=/<regexp>/
– regexp match command output both stdout and stderr#match[stdout|stderr]=/<regexp>/
– regexp match command either stdout or stderr#env[<var_name>]=~/<regexp>/
– regexp match the given environment variable name#env[<var_name>]?=[array|string|nil]
– verify type of the given environment variable name#env[<var_name><var_name>][]=<size>
– verify size of the given environment variable name#env[<var_name>][]=/<regexp>/
– regexp match all of elements of the given environment variable name#env[<var_name>][<index>]=/<regexp>/
– regexp match given element of the given environment variable name
And here is very simple test:
true # status=0 false # status!=0 echo "Super" # match=~/^Super$/ rvm install 1.9.3 # match[stderr]!=/Error/; status=0 rvm alias create default 1.9.3 # status=0
TF is used for testing RVM, SM Framework and rubygems-bundler. Let me know if any other awesome projects use TF!
TF was earlier known as DTF – Deryl’s Testing Framework, but as original author Deryl wanted to go in a bit different direction (more validation related), I had to move code to this new repository and name.