Skip to content

Commit

Permalink
Style fixes for pre-commit hook tests
Browse files Browse the repository at this point in the history
As pointed out by Junio on the mailing list, surrounding tests in
double quotes can lead to bugs wherein variables get substituted away,
so this isn't just style churn but important to prevent others from
looking at these tests in the future and thinking that this is "the
way" that Git tests should be written.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Wincent Colaiuta authored and Junio C Hamano committed Dec 10, 2007
1 parent 80f8660 commit cf7e147
Showing 1 changed file with 57 additions and 33 deletions.
90 changes: 57 additions & 33 deletions t/t7503-pre-commit-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ test_description='pre-commit hook'

. ./test-lib.sh

test_expect_success "with no hook" \
"echo 'foo' > file &&
git add file &&
git commit -m 'first'"
test_expect_success 'with no hook' '
test_expect_success "--no-verify with no hook" \
"echo 'bar' > file &&
git add file &&
git commit --no-verify -m 'bar'"
echo "foo" > file &&
git add file &&
git commit -m "first"
'

test_expect_success '--no-verify with no hook' '
echo "bar" > file &&
git add file &&
git commit --no-verify -m "bar"
'

# now install hook that always succeeds
HOOKDIR="$(git rev-parse --git-dir)/hooks"
Expand All @@ -24,41 +30,59 @@ exit 0
EOF
chmod +x "$HOOK"

test_expect_success "with succeeding hook" \
"echo 'more' >> file &&
git add file &&
git commit -m 'more'"
test_expect_success 'with succeeding hook' '
echo "more" >> file &&
git add file &&
git commit -m "more"
test_expect_success "--no-verify with succeeding hook" \
"echo 'even more' >> file &&
git add file &&
git commit --no-verify -m 'even more'"
'

test_expect_success '--no-verify with succeeding hook' '
echo "even more" >> file &&
git add file &&
git commit --no-verify -m "even more"
'

# now a hook that fails
cat > "$HOOK" <<EOF
#!/bin/sh
exit 1
EOF

test_expect_failure "with failing hook" \
"echo 'another' >> file &&
git add file &&
git commit -m 'another'"
test_expect_failure 'with failing hook' '
echo "another" >> file &&
git add file &&
git commit -m "another"
test_expect_success "--no-verify with failing hook" \
"echo 'stuff' >> file &&
git add file &&
git commit --no-verify -m 'stuff'"
'

test_expect_success '--no-verify with failing hook' '
echo "stuff" >> file &&
git add file &&
git commit --no-verify -m "stuff"
'

chmod -x "$HOOK"
test_expect_success "with non-executable hook" \
"echo 'content' >> file &&
git add file &&
git commit -m 'content'"

test_expect_success "--no-verify with non-executable hook" \
"echo 'more content' >> file &&
git add file &&
git commit --no-verify -m 'more content'"
test_expect_success 'with non-executable hook' '
echo "content" >> file &&
git add file &&
git commit -m "content"
'

test_expect_success '--no-verify with non-executable hook' '
echo "more content" >> file &&
git add file &&
git commit --no-verify -m "more content"
'

test_done

0 comments on commit cf7e147

Please sign in to comment.