Thanks for your interest in bash-lib!
For general contribution and community guidelines, please see the community repo. In particular, before contributing please review our contributor licensing guide to ensure your contribution is compliant with our contributor license agreements.
Contributed bash functions are most welcome! The more we share the less we duplicate each other. In order to keep this repo tidy, every function must be documented in the readme and tested, the lint scripts enforce these rules.
- Add the libraries or functions that you need
- Add BATS tests for all new top level functions
- Add descriptions for each function to the contents table in this readme
- Run ./run-tests to ensure all tests pass before submitting
- Create a PR
- Wait for review
Follow the google shell style guide. TL;DR:
- Use snake_case function and variable names
- Use
function
when declaring functions. - Don't use .sh extensions
Tests are written using BATS. Each lib has a lib-name.bats
file in tests-for-this-repo.
Asserts are provided by bats-assert-1. Asserts provide useful debugging output when the assertion fails, eg expected x got y.
Example:
# source support and assert libraries
. "${BASH_LIB_DIR}/test-utils/bats-support/load.bash"
. "${BASH_LIB_DIR}/test-utils/bats-assert-1/load.bash"
# source the library under test
. "${BASH_LIB_DIR}/git/lib"
# define a test that calls a library function
@test "it does the thing" {
some_prep_work
# run is a wrapper that catches failures so that assertsions can be run,
# otherwise the test would immediately fail.
run does_the_thing
assert_success
assert_output "thing done"
}
Test fixtures should go in /tests-for-this-repo/fixtures/lib-name.