1.2.1 • Published 11 months ago

bats-zsh v1.2.1

Weekly downloads
-
License
CC0-1.0
Repository
github
Last release
11 months ago

bats-zsh

license GitHub release npm tests

Wrapper enabling Bats to source and test Zsh scripts.

Install

npm is the preferred installation method.

npm install bats-zsh

Usage

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

  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: npm install
  4. Run shellcheck: npm run shellcheck
  5. Run tests: npm test test