Simple tests for bash scripts. Uses Test Anything Protocol(TAP
).
To use the script, download it to a folder and include it in your test script.
./test.sh
#!/usr/bin/env bash
PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${PWD}/bashtap.bash"
plan
# Begin test block
spec "echo outputs arguments"
expect << EOT
echo hello world
EOT
to_output << EOT
hello world
EOT
# End test block
finish
$ ./test.sh
1..1
ok 1 echo hello world
Include this library in your project, you can use git submodules for that.
$ cd my-project
$ mkdir deps
$ git submodule add https://github.com/san650/bashtap deps/bashtap
Then include the library in your test script ./test.sh
#!/usr/bin/env bash
PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${PWD}/deps/bashtap/bashtap.bash"
spec "echo outputs arguments"
expect <<< 'echo hello world'
to_output <<< 'hello world'
finish
Make your test file executable and run it
$ chmod +x test.sh
$ ./test.sh
1..1
ok 1 echo outputs arguments
Function | Arguments | Description |
---|---|---|
plan |
None | Prints TAP header |
spec |
$1:String | Defines a new test |
expect |
File Descriptor or a heredoc block | Script to test |
to_output |
File Descriptor or a heredoc block | Expected output from the script defined in expect |
finish |
None | Exit the program with an error code if a test failed |
bashtap
is licensed under the MIT license.
See LICENSE for the full license text.