Testing Your Scripts
Static Code Analysis
This means that you can use these tools to ensure that any custom code you use in your script, is also valid.
Note that when testing with
shfmt, you should specify an indentation of 2
spaces, and case indentation rules:
$ shfmt --diff --case-indent --indent 2 yourscript
bashly add test to add a
test folder to your project, with the
In cases where your scripts are more elaborate, or when you wish to ensure your scripts behave as expected, you can use any bash testing framework to test your scripts.
One such lightweight framework, is Approvals.bash, which lets you test any command in your script, and prompting you for interactive approval of its output. Whenever the output changes, you will be prompted again to approve it.
A sample test script looks like this:
#!/usr/bin/env bash source approvals.bash approve "your-cli --help" approve "your-cli command --arg" # ... more tests