Skip to content
Open
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,7 +20,10 @@ 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
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

- 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
52 changes: 52 additions & 0 deletions test/commit_msg_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

set -euo pipefail

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

run_hook() {
local expected_status="$1"
local message="$2"
local msg_file="$tmpdir/message"

printf '%s\n' "$message" > "$msg_file"

set +e
output=$(bash "$commit_msg_hook" "$msg_file" 2>&1)
status=$?
set -e

if [ "$status" -ne "$expected_status" ]; then
echo "expected exit $expected_status for message: $message" >&2
echo "got exit $status" >&2
echo "$output" >&2
exit 1
fi
}

assert_rejected() {
local message="$1"

run_hook 1 "$message"
if ! printf '%s' "$output" | grep -Fq "ERROR: Commit message does not follow Conventional Commits format."; then
echo "expected rejection output for message: $message" >&2
echo "$output" >&2
exit 1
fi
}

run_hook 0 "feat: add checkout hook"
run_hook 0 "fix(shell/hooks): preserve lfs args"
run_hook 0 "feat(api)!: change hook contract"
run_hook 0 "Merge pull request #6 from taigrr/cd/clear-conflicting-hook-config"
run_hook 0 "fixup! fix(shell): preserve lfs args"
run_hook 0 "squash! test(shell): add regression coverage"

assert_rejected "update hook behavior"
assert_rejected "feature: add checkout hook"
assert_rejected "fix(shell):"

echo "commit-msg regression tests passed"
Loading