A collection of useful shell functions with unit tests.
Execute these:
BATS_INSTALL="${HOME}/.local/share/bats"
mkdir -p "${BATS_INSTALL}"
cd "${BATS_INSTALL}"
git clone --recurse-submodules https://github.com/sstephenson/bats core
git clone --recurse-submodules https://github.com/ztombol/bats-support support
git clone --recurse-submodules https://github.com/ztombol/bats-assert assert
git clone --recurse-submodules https://github.com/ztombol/bats-file file
cd core
./install.sh "${HOME}/.local"
Add to shell init scripts:
BATS_INSTALL="${HOME}/.local/share/bats"
PATH=$PATH:${HOME}/.local/bin:${HOME}/.local/libexec
export PATH BATS_INSTALL
Use in testname.bats files:
load "${BATS_INSTALL}/support/load.bash"
load "${BATS_INSTALL}/assert/load.bash"
load "${BATS_INSTALL}/file/load.bash"
Function naming scheme:
- _name - Support functions not likely used in body of script.
- get_name - Prints string suitable for assigning to variable.
- is_name - Typically a true/false test.
- mk_name - Creates something, typically a file or directory.
- set_name - Sets one or more variables, typically in script environment.
Files which are not (just) functions are in CamelCase. These set global variables and/or execute code which may or may not have side-effects.
Most functions are designed to be used as-is, however these are specifically designed to be over-ridden:
parse_options
PreambleFull
Main
- awmyhr awmyhr@gmail.com
PRs accepted.
Apache-2.0 (c) 2019 awmyhr