Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ jobs:

- name: Run ShellCheck on all shell scripts
run: |
shellcheck pre-commit commit-msg pre-push post-checkout post-commit post-merge install.sh uninstall.sh test/install_test.sh test/commit_msg_test.sh
shellcheck pre-commit commit-msg pre-push post-checkout post-commit post-merge install.sh uninstall.sh test/install_test.sh test/commit_msg_test.sh test/pre_commit_test.sh

- name: Run install script regression tests
run: bash test/install_test.sh

- name: Run commit message regression tests
run: bash test/commit_msg_test.sh

- name: Run pre-commit regression tests
run: bash test/pre_commit_test.sh
56 changes: 56 additions & 0 deletions test/pre_commit_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

set -euo pipefail

repo_root="$(cd "$(dirname "$0")/.." && pwd)"
pre_commit="$repo_root/pre-commit"
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT

run() {
local expected_status="$1"
shift
set +e
output=$("$@" 2>&1)
status=$?
set -e
if [ "$status" -ne "$expected_status" ]; then
echo "expected exit $expected_status, got $status" >&2
echo "$output" >&2
exit 1
fi
printf '%s' "$output"
}

assert_contains() {
local haystack="$1"
local needle="$2"
if ! printf '%s' "$haystack" | grep -Fq "$needle"; then
echo "expected output to contain: $needle" >&2
echo "$haystack" >&2
exit 1
fi
}

cd "$tmpdir"
git init --quiet
git config user.email test@example.com
git config user.name "Test User"

printf 'small\n' > small.txt
git add small.txt
run 0 bash "$pre_commit"
git commit --quiet -m "test: add small file"

rm small.txt
git add small.txt
run 0 bash "$pre_commit"
git commit --quiet -m "test: remove small file"

dd if=/dev/zero of=large.bin bs=1M count=6 status=none
git add large.bin
output=$(run 1 bash "$pre_commit")
assert_contains "$output" "File large.bin is 6MiB"
assert_contains "$output" "Commit too large"

echo "pre-commit regression tests passed"
Loading