Skip to content

Latest commit

 

History

History
83 lines (57 loc) · 1.51 KB

Readme.md

File metadata and controls

83 lines (57 loc) · 1.51 KB

Unit tested Bash project template with Pre-commit

Travis Build Status License: AGPL v3

You can use this as a starting point for your Bash/shell project with:

  • Unit testing
  • Code Coverage (100 %)
  • Pre-commit:
    • shfmt (Auto-formatter)
    • Shellcheck
  • Continuous Integration (GitLab CI)

That way, you start your project in a clean, tested environment.

Usage

The main code can be ran with:

src/main.sh

Testing

Put your unit test files (with extension .bats) in folder: /test/

Prerequisites

(Re)-install the required submodules with:

chmod +x install-bats-libs.sh
./install-bats-libs.sh

Install:

sudo gem install bats
sudo gem install bashcov
sudo apt install shfmt -y
pre-commit install
pre-commit autoupdate

Pre-commit

Run pre-commit with:

pre-commit run --all

Tests

Run the tests with:

bats test

If you want to run particular tests, you could use the test.sh file:

chmod +x test.sh
./test.sh

Code coverage

bashcov bats test

How to help

  • Include bash code coverage in GitLab CI.
  • Add additional (relevant) pre-commit hooks.
  • Develop Bash documentation checks here, and add them to this pre-commit.