Files
Amicitia-Tabellarius/scripts/test-hooks.sh
T

37 lines
1.3 KiB
Bash

#!/bin/sh
# Proves the pre-commit hook in a throwaway repository. Prints a count; exits 1 on any failure.
set -eu
root=$(cd "$(dirname "$0")/.." && pwd)
passed=0
failed=0
run_case() { # name path bytes expect(accept|reject)
repo=$(mktemp -d)
(
cd "$repo"
git init -q
git config core.autocrlf false
git config user.name hook-test
git config user.email hook-test@invalid
cp -r "$root/.githooks" .githooks
git config core.hooksPath .githooks
mkdir -p "$(dirname "$2")"
head -c "$3" /dev/zero > "$2"
git add -f "$2"
git commit -q -m case >/dev/null 2>&1
) && got=accept || got=reject
rm -rf "$repo"
if [ "$got" = "$4" ]; then passed=$((passed + 1)); else failed=$((failed + 1)); echo "FAIL $1: $got"; fi
}
run_case "6 MB file is rejected" big.bin 6291456 reject
run_case "file under target/ is rejected" target/debug/x 10 reject
run_case "nested target/ is rejected" crates/relay/target/x 10 reject
run_case "nix result link path is rejected" result 10 reject
run_case "5 MB file is accepted" ok.bin 5242880 accept
run_case "ordinary source file is accepted" crates/relay/src/main.rs 10 accept
run_case "'targets.rs' is not mistaken for target/" src/targets.rs 10 accept
echo "hook tests: $passed passed, $failed failed"
[ "$failed" -eq 0 ]