#!/usr/bin/env bats load test_helper HOOK_MARKER="# Installed by coredesktop-dev; remove with: coredesktop-dev hooks remove" @test "update installs the packages and links the command, without asking anything" { run bash "$PROJECT/update.sh" < /dev/null [ "$status" -eq 0 ] called install_packages shellcheck bats tea qemu-base libisoburn [ "$(readlink "$HOME/.local/bin/coredesktop-dev")" = "$PROJECT/bin/coredesktop-dev" ] } @test "update fixes a link that points somewhere else" { mkdir -p "$HOME/.local/bin" ln -s /nowhere "$HOME/.local/bin/coredesktop-dev" run bash "$PROJECT/update.sh" < /dev/null [ "$status" -eq 0 ] [ "$(readlink "$HOME/.local/bin/coredesktop-dev")" = "$PROJECT/bin/coredesktop-dev" ] } @test "update leaves an unchanged pre-push hook alone" { make_working_copy cp "$PROJECT/hooks/pre-push" "$WC/.git/hooks/pre-push" touch -d '2020-01-01' "$WC/.git/hooks/pre-push" run bash "$PROJECT/update.sh" < /dev/null [ "$status" -eq 0 ] [ "$(date -r "$WC/.git/hooks/pre-push" +%Y)" = 2020 ] [[ "$output" != *"Updated the pre-push hook"* ]] } @test "update refreshes our pre-push hook when it has changed" { make_working_copy printf '%s\n' '#!/bin/bash' "$HOOK_MARKER" 'old version' > "$WC/.git/hooks/pre-push" run bash "$PROJECT/update.sh" < /dev/null [ "$status" -eq 0 ] cmp "$PROJECT/hooks/pre-push" "$WC/.git/hooks/pre-push" [[ "$output" == *"Updated the pre-push hook"* ]] } @test "update doesn't touch someone else's pre-push hook" { make_working_copy printf '%s\n' '#!/bin/bash' 'mine' > "$WC/.git/hooks/pre-push" run bash "$PROJECT/update.sh" < /dev/null [ "$status" -eq 0 ] [ "$(tail -n 1 "$WC/.git/hooks/pre-push")" = mine ] }