Skip to content

Commit cf7e147

Browse files
wincentgitster
authored andcommitted
Style fixes for pre-commit hook tests
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>
1 parent 80f8660 commit cf7e147

File tree

1 file changed

+57
-33
lines changed

1 file changed

+57
-33
lines changed

t/t7503-pre-commit-hook.sh

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ test_description='pre-commit hook'
44

55
. ./test-lib.sh
66

7-
test_expect_success "with no hook" \
8-
"echo 'foo' > file &&
9-
git add file &&
10-
git commit -m 'first'"
7+
test_expect_success 'with no hook' '
118
12-
test_expect_success "--no-verify with no hook" \
13-
"echo 'bar' > file &&
14-
git add file &&
15-
git commit --no-verify -m 'bar'"
9+
echo "foo" > file &&
10+
git add file &&
11+
git commit -m "first"
12+
13+
'
14+
15+
test_expect_success '--no-verify with no hook' '
16+
17+
echo "bar" > file &&
18+
git add file &&
19+
git commit --no-verify -m "bar"
20+
21+
'
1622

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

27-
test_expect_success "with succeeding hook" \
28-
"echo 'more' >> file &&
29-
git add file &&
30-
git commit -m 'more'"
33+
test_expect_success 'with succeeding hook' '
34+
35+
echo "more" >> file &&
36+
git add file &&
37+
git commit -m "more"
3138
32-
test_expect_success "--no-verify with succeeding hook" \
33-
"echo 'even more' >> file &&
34-
git add file &&
35-
git commit --no-verify -m 'even more'"
39+
'
40+
41+
test_expect_success '--no-verify with succeeding hook' '
42+
43+
echo "even more" >> file &&
44+
git add file &&
45+
git commit --no-verify -m "even more"
46+
47+
'
3648

3749
# now a hook that fails
3850
cat > "$HOOK" <<EOF
3951
#!/bin/sh
4052
exit 1
4153
EOF
4254

43-
test_expect_failure "with failing hook" \
44-
"echo 'another' >> file &&
45-
git add file &&
46-
git commit -m 'another'"
55+
test_expect_failure 'with failing hook' '
56+
57+
echo "another" >> file &&
58+
git add file &&
59+
git commit -m "another"
4760
48-
test_expect_success "--no-verify with failing hook" \
49-
"echo 'stuff' >> file &&
50-
git add file &&
51-
git commit --no-verify -m 'stuff'"
61+
'
62+
63+
test_expect_success '--no-verify with failing hook' '
64+
65+
echo "stuff" >> file &&
66+
git add file &&
67+
git commit --no-verify -m "stuff"
68+
69+
'
5270

5371
chmod -x "$HOOK"
54-
test_expect_success "with non-executable hook" \
55-
"echo 'content' >> file &&
56-
git add file &&
57-
git commit -m 'content'"
58-
59-
test_expect_success "--no-verify with non-executable hook" \
60-
"echo 'more content' >> file &&
61-
git add file &&
62-
git commit --no-verify -m 'more content'"
72+
test_expect_success 'with non-executable hook' '
73+
74+
echo "content" >> file &&
75+
git add file &&
76+
git commit -m "content"
77+
78+
'
79+
80+
test_expect_success '--no-verify with non-executable hook' '
81+
82+
echo "more content" >> file &&
83+
git add file &&
84+
git commit --no-verify -m "more content"
85+
86+
'
6387

6488
test_done

0 commit comments

Comments
 (0)