@matheusbsbs / matheus-bagliano / commits / 80f86605ba
Fork 0

Interactive editor tests for commit-msg hook

Supplement the existing tests for the commit-msg hook (which all use "git commit -m") with tests which use an interactive editor (no -m switch) to ensure that all code paths get tested. At the same time the quoting of some of the existing tests is changed to conform to Junio's recommendations for test style (single quotes used around the test unless there is a compelling reason not to, and the opening quote on the same line as the test_expect and the closing quote in column 1). Signed-off-by: Wincent Colaiuta <win@wincent.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Wincent Colaiuta committed Dec 10, 2007 at 08:33 UTC 80f86605baaa37f962755ccd771eb879a9c43865
1 file changed +175 -43
t/t7504-commit-msg-hook.sh
+175 -43
@@ -4,15 +4,49 @@ test_description='commit-msg hook'
4
5 . ./test-lib.sh
6
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' '
8
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 +# set up fake editor for interactive editing
16 +cat > fake-editor <<'EOF'
17 +#!/bin/sh
18 +cp FAKE_MSG "$1"
19 +exit 0
20 +EOF
21 +chmod +x fake-editor
22 +FAKE_EDITOR="$(pwd)/fake-editor"
23 +export FAKE_EDITOR
24 +
25 +test_expect_success 'with no hook (editor)' '
26 +
27 + echo "more foo" >> file &&
28 + git add file &&
29 + echo "more foo" > FAKE_MSG &&
30 + GIT_EDITOR="$FAKE_EDITOR" git commit
31 +
32 +'
33 +
34 +test_expect_success '--no-verify with no hook' '
35 +
36 + echo "bar" > file &&
37 + git add file &&
38 + git commit --no-verify -m "bar"
39 +
40 +'
41 +
42 +test_expect_success '--no-verify with no hook (editor)' '
43 +
44 + echo "more bar" > file &&
45 + git add file &&
46 + echo "more bar" > FAKE_MSG &&
47 + GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
48 +
49 +'
50
51 # now install hook that always succeeds
52 HOOKDIR="$(git rev-parse --git-dir)/hooks"
@@ -24,15 +58,39 @@ exit 0
58 EOF
59 chmod +x "$HOOK"
60
27 -test_expect_success "with succeeding hook" \
28 - "echo 'more' >> file &&
29 - git add file &&
30 - git commit -m 'more'"
61 +test_expect_success 'with succeeding hook' '
62
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'"
63 + echo "more" >> file &&
64 + git add file &&
65 + git commit -m "more"
66 +
67 +'
68 +
69 +test_expect_success 'with succeeding hook (editor)' '
70 +
71 + echo "more more" >> file &&
72 + git add file &&
73 + echo "more more" > FAKE_MSG &&
74 + GIT_EDITOR="$FAKE_EDITOR" git commit
75 +
76 +'
77 +
78 +test_expect_success '--no-verify with succeeding hook' '
79 +
80 + echo "even more" >> file &&
81 + git add file &&
82 + git commit --no-verify -m "even more"
83 +
84 +'
85 +
86 +test_expect_success '--no-verify with succeeding hook (editor)' '
87 +
88 + echo "even more more" >> file &&
89 + git add file &&
90 + echo "even more more" > FAKE_MSG &&
91 + GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
92 +
93 +'
94
95 # now a hook that fails
96 cat > "$HOOK" <<EOF
@@ -40,26 +98,74 @@ cat > "$HOOK" <<EOF
98 exit 1
99 EOF
100
43 -test_expect_failure "with failing hook" \
44 - "echo 'another' >> file &&
45 - git add file &&
46 - git commit -m 'another'"
101 +test_expect_failure 'with failing hook' '
102 +
103 + echo "another" >> file &&
104 + git add file &&
105 + git commit -m "another"
106 +
107 +'
108 +
109 +test_expect_failure 'with failing hook (editor)' '
110 +
111 + echo "more another" >> file &&
112 + git add file &&
113 + echo "more another" > FAKE_MSG &&
114 + GIT_EDITOR="$FAKE_EDITOR" git commit
115
48 -test_expect_success "--no-verify with failing hook" \
49 - "echo 'stuff' >> file &&
50 - git add file &&
51 - git commit --no-verify -m 'stuff'"
116 +'
117 +
118 +test_expect_success '--no-verify with failing hook' '
119 +
120 + echo "stuff" >> file &&
121 + git add file &&
122 + git commit --no-verify -m "stuff"
123 +
124 +'
125 +
126 +test_expect_success '--no-verify with failing hook (editor)' '
127 +
128 + echo "more stuff" >> file &&
129 + git add file &&
130 + echo "more stuff" > FAKE_MSG &&
131 + GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
132 +
133 +'
134
135 chmod -x "$HOOK"
54 -test_expect_success "with non-executable hook" \
55 - "echo 'content' >> file &&
56 - git add file &&
57 - git commit -m 'content'"
136 +test_expect_success 'with non-executable hook' '
137 +
138 + echo "content" >> file &&
139 + git add file &&
140 + git commit -m "content"
141 +
142 +'
143 +
144 +test_expect_success 'with non-executable hook (editor)' '
145 +
146 + echo "content again" >> file &&
147 + git add file &&
148 + echo "content again" > FAKE_MSG &&
149 + GIT_EDITOR="$FAKE_EDITOR" git commit -m "content again"
150 +
151 +'
152 +
153 +test_expect_success '--no-verify with non-executable hook' '
154 +
155 + echo "more content" >> file &&
156 + git add file &&
157 + git commit --no-verify -m "more content"
158 +
159 +'
160
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'"
161 +test_expect_success '--no-verify with non-executable hook (editor)' '
162 +
163 + echo "even more content" >> file &&
164 + git add file &&
165 + echo "even more content" > FAKE_MSG &&
166 + GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
167 +
168 +'
169
170 # now a hook that edits the commit message
171 cat > "$HOOK" <<'EOF'
@@ -73,16 +179,42 @@ commit_msg_is () {
179 test "`git log --pretty=format:%s%b -1`" = "$1"
180 }
181
76 -test_expect_success "hook edits commit message" \
77 - "echo 'additional' >> file &&
78 - git add file &&
79 - git commit -m 'additional' &&
80 - commit_msg_is 'new message'"
81 -
82 -test_expect_success "hook doesn't edit commit message" \
83 - "echo 'plus' >> file &&
84 - git add file &&
85 - git commit --no-verify -m 'plus' &&
86 - commit_msg_is 'plus'"
182 +test_expect_success 'hook edits commit message' '
183 +
184 + echo "additional" >> file &&
185 + git add file &&
186 + git commit -m "additional" &&
187 + commit_msg_is "new message"
188 +
189 +'
190 +
191 +test_expect_success 'hook edits commit message (editor)' '
192 +
193 + echo "additional content" >> file &&
194 + git add file &&
195 + echo "additional content" > FAKE_MSG &&
196 + GIT_EDITOR="$FAKE_EDITOR" git commit &&
197 + commit_msg_is "new message"
198 +
199 +'
200 +
201 +test_expect_success "hook doesn't edit commit message" '
202 +
203 + echo "plus" >> file &&
204 + git add file &&
205 + git commit --no-verify -m "plus" &&
206 + commit_msg_is "plus"
207 +
208 +'
209 +
210 +test_expect_success "hook doesn't edit commit message (editor)" '
211 +
212 + echo "more plus" >> file &&
213 + git add file &&
214 + echo "more plus" > FAKE_MSG &&
215 + GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify &&
216 + commit_msg_is "more plus"
217 +
218 +'
219
220 test_done