Files
Coredesktop-Dev/tests/hooks.bats
T
2026-11-04 09:43:05 -07:00

67 lines
1.6 KiB
Bash

#!/usr/bin/env bats
load test_helper
setup() {
common_setup
make_working_copy
HOOK="$WC/.git/hooks/pre-push"
}
@test "hooks install installs the pre-push hook" {
run cdd hooks install
[ "$status" -eq 0 ]
[ -x "$HOOK" ]
cmp "$PROJECT/hooks/pre-push" "$HOOK"
run cdd hooks
[[ "$output" == *"The pre-push hook is installed"* ]]
}
@test "hooks install won't overwrite someone else's hook" {
printf '%s\n' '#!/bin/bash' 'mine' > "$HOOK"
run cdd hooks install
[ "$status" -eq 1 ]
[[ "$output" == *"didn't write it"* ]]
[ "$(tail -n 1 "$HOOK")" = mine ]
}
@test "hooks remove removes only our hook" {
cdd hooks install
run cdd hooks remove
[ "$status" -eq 0 ]
[ ! -e "$HOOK" ]
printf '%s\n' '#!/bin/bash' 'mine' > "$HOOK"
run cdd hooks remove
[ "$status" -eq 1 ]
[ -e "$HOOK" ]
}
@test "hooks follows core.hooksPath" {
git -C "$WC" config core.hooksPath .githooks
run cdd hooks install
[ "$status" -eq 0 ]
[ -x "$WC/.githooks/pre-push" ]
}
@test "the hook stops a push when check fails, and says how to skip it" {
mkdir -p "$HOME/.local/bin"
printf '%s\n' '#!/bin/bash' 'exit 1' > "$HOME/.local/bin/coredesktop-dev"
chmod +x "$HOME/.local/bin/coredesktop-dev"
run bash "$PROJECT/hooks/pre-push"
[ "$status" -eq 1 ]
[[ "$output" == *"git push --no-verify"* ]]
}
@test "the hook lets a push through when check passes" {
mkdir -p "$HOME/.local/bin"
printf '%s\n' '#!/bin/bash' 'exit 0' > "$HOME/.local/bin/coredesktop-dev"
chmod +x "$HOME/.local/bin/coredesktop-dev"
run bash "$PROJECT/hooks/pre-push"
[ "$status" -eq 0 ]
}