Enable focused tests as repository pre-commit hook
This commit is contained in:
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Repository pre-commit hook: run only tests selected by staged paths.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
||||||
|
exec "$REPO_ROOT/scripts/test-changed.sh"
|
||||||
@@ -22,11 +22,18 @@ For normal commits, use the focused wrapper:
|
|||||||
```
|
```
|
||||||
|
|
||||||
It reads staged paths with `git diff --cached` and runs only the mapped Bats
|
It reads staged paths with `git diff --cached` and runs only the mapped Bats
|
||||||
files. Use `--list` to inspect the selection without running tests, or
|
files. The tracked `.githooks/pre-commit` hook invokes this wrapper. Enable the
|
||||||
`--paths FILE ...` to preview a mapping. Shared test infrastructure and
|
repository hook path once per checkout:
|
||||||
unmapped paths fail closed rather than silently skipping coverage. Run the
|
|
||||||
full suite with `./tests/run.sh` when changing shared test helpers, the test
|
```bash
|
||||||
runner, or when focused coverage is not sufficient.
|
git config core.hooksPath .githooks
|
||||||
|
```
|
||||||
|
|
||||||
|
Use `--list` to inspect the selection without running tests, or `--paths FILE
|
||||||
|
...` to preview a mapping. Shared test infrastructure and unmapped paths fail
|
||||||
|
closed rather than silently skipping coverage. Run the full suite with
|
||||||
|
`./tests/run.sh` when changing shared test helpers, the test runner, or when
|
||||||
|
focused coverage is not sufficient.
|
||||||
|
|
||||||
## Red-Green
|
## Red-Green
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ for path in "${CHANGED[@]}"; do
|
|||||||
tests/helpers.bash|tests/run.sh)
|
tests/helpers.bash|tests/run.sh)
|
||||||
die "$path is shared test infrastructure; run ./tests/run.sh explicitly"
|
die "$path is shared test infrastructure; run ./tests/run.sh explicitly"
|
||||||
;;
|
;;
|
||||||
|
.githooks/*)
|
||||||
|
add_test tests/changed_tests.bats
|
||||||
|
;;
|
||||||
dankserver/compose.yaml|dankclaw/compose.yaml)
|
dankserver/compose.yaml|dankclaw/compose.yaml)
|
||||||
add_test tests/compose_validity.bats
|
add_test tests/compose_validity.bats
|
||||||
add_test tests/env_consistency.bats
|
add_test tests/env_consistency.bats
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ load helpers
|
|||||||
|
|
||||||
@test "changed-test wrapper is executable and uses staged diff by default" {
|
@test "changed-test wrapper is executable and uses staged diff by default" {
|
||||||
[ -x "$REPO_ROOT/scripts/test-changed.sh" ]
|
[ -x "$REPO_ROOT/scripts/test-changed.sh" ]
|
||||||
|
[ -x "$REPO_ROOT/.githooks/pre-commit" ]
|
||||||
|
run grep -F 'scripts/test-changed.sh' "$REPO_ROOT/.githooks/pre-commit"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
run grep -F 'git diff --cached' "$REPO_ROOT/scripts/test-changed.sh"
|
run grep -F 'git diff --cached' "$REPO_ROOT/scripts/test-changed.sh"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user