Wrapper enabling Bats to test functions in Zsh scripts
npm install bats-zsh!license !GitHub release !npm !tests
Wrapper enabling Bats to source and test Zsh scripts.
npm is the preferred installation method.
``bash`
npm install bats-zsh
This project provides the following functions:
Used in place of source to source 1 or more Zsh files.
`bash`
@test 'zsource sample test'{
zsource path/to/zsh-file1.sh
zsource path/to/zsh-file2.sh
}
When multiple files are sourced using zsource, conflicts will be handled the same as source would. In effect, when there is a conflict, the newer version will overwrite the older one.
Used in place of run to run a function from the sourced Zsh script.
`bash
@test 'output_number_of_args() outputs the number of args' {
zsource path/to/zsh-file.sh
zrun output_number_of_args arg1 arg2 arg3
[ "$status" -eq 0 ]
[ "$output" = "there were 3 args" ]
[ "$BATS_RUN_COMMAND" = "zrun output_number_of_args arg1 arg2 arg3" ]
}
`
All variables expected from run will be set (i.e. status, output, and BATS_RUN_COMMAND).
Used to set or change global variables in the sourced files.
`bash
@test 'say_my_name() outputs \$MY_NAME'{
zsource path/to/zsh-file.sh
zrun say_my_name
[ "$output" = "You don't have a name" ]
zset MY_NAME="David"
zrun say_my_name
[ "$output" = "Your name is David" ]
}
`
1. Clone this repository:
git clone https://github.com/targendaz2/bats-zsh.gitnpm install
2. Install global dependencies:
Node.js, ShellCheck, & Zsh
3. Install project dependencies:npm run shellcheck
4. Run shellcheck:npm test test`
5. Run tests: