This directory contains automated tests for all pre-commit hooks using the bats testing framework.
tests/
├── test_helper.bash # Common test utilities
├── run_tests.sh # Test runner script
├── commits/ # Tests for commit hooks
├── nix/ # Tests for Nix hooks
├── terraform/ # Tests for Terraform hooks
├── web/ # Tests for web-related hooks
└── configs/ # Tests for config hooks
Install bats:
# Ubuntu/Debian
sudo apt-get install bats
# macOS
brew install bats-core
# Via npm
npm install -g bats./tests/run_tests.shbats tests/commits/test_gitlint.bats# Install kcov first
./tests/run_tests.sh # Will automatically use kcov if availableEach hook should have a corresponding test file following the pattern:
tests/<category>/test_<hook-name>.bats
Example test structure:
#!/usr/bin/env bats
load ../test_helper
setup() {
setup_test_env
}
teardown() {
teardown_test_env
}
@test "hook exists and is executable" {
run test -x "$ORIGINAL_DIR/hooks/category/hook.sh"
[ "$status" -eq 0 ]
}
@test "hook validates input correctly" {
# Test implementation
}- Coverage: Every hook must have at least basic tests
- Edge Cases: Test error conditions and edge cases
- Mocking: Use
mock_commandfor external dependencies - Isolation: Each test should be independent
- Performance: Keep tests fast (<1s per test)
Tests run automatically on:
- Every push to main branch
- Every pull request
- Multiple OS environments (Ubuntu, macOS)
See .github/workflows/ci.yml for CI configuration.