1.2.1 • Published 2 years ago
bats-zsh v1.2.1
bats-zsh
Wrapper enabling Bats to source and test Zsh scripts.
Install
npm is the preferred installation method.
npm install bats-zshUsage
This project provides the following functions:
zsource
Used in place of source to source 1 or more Zsh files.
@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.
zrun
Used in place of run to run a function from the sourced Zsh script.
@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).
zset
Used to set or change global variables in the sourced files.
@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" ]
}Testing
- Clone this repository:
git clone https://github.com/targendaz2/bats-zsh.git - Install global dependencies: Node.js, ShellCheck, & Zsh
- Install project dependencies:
npm install - Run shellcheck:
npm run shellcheck - Run tests:
npm test test