Skip to content

Plugin enabling Bats to test Zsh scripts

License

Notifications You must be signed in to change notification settings

targendaz2/bats-zsh

Repository files navigation

bats-zsh

GitHub License GitHub package.json version NPM Version GitHub Actions Workflow Status

Plugin enabling Bats to source and test Zsh scripts.

Installation

This package is available on the npm registry as bats-zsh.

npm install -D bats bats-support bats-zsh

Usage

This project provides the following functions:

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

  1. Clone this repository: git clone https://github.com/targendaz2/bats-zsh.git
  2. Install global dependencies: Node.js, ShellCheck, & Zsh
  3. Install project dependencies: yarn install
  4. Run shellcheck: yarn lint
  5. Run tests: yarn test

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

This package is licensed under the Creative Commons Zero v1.0 Universal License.