t7006 (pager): introduce helper for parameterized tests
The current tests test pager configuration for ‘git log’, but other commands use a different setup procedure and should therefore be tested separately. Add a helper to make this easier. This patch introduces the helper and changes some existing tests to use it. The only functional change should be the introduction of ‘git log - ’ to a few test descriptions. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Jun 26, 2010 at 14:23 UTC
3c7406d4b595c9e8c8dfcff2739bab9412add5a3
1 file changed
+54
-18
t/t7006-pager.sh
+54
-18
@@ -172,58 +172,94 @@ then
172
test_set_prereq SIMPLEPAGER
173
fi
174
175
-test_expect_success SIMPLEPAGER 'default pager is used by default' '
175
+# Use this helper to make it easy for the caller of your
176
+# terminal-using function to specify whether it should fail.
177
+# If you write
178
+#
179
+# your_test() {
180
+# parse_args "$@"
181
+#
182
+# $test_expectation "$cmd - behaves well" "
183
+# ...
184
+# $full_command &&
185
+# ...
186
+# "
187
+# }
188
+#
189
+# then your test can be used like this:
190
+#
191
+# your_test expect_(success|failure) [test_must_fail] 'git foo'
192
+#
193
+parse_args() {
194
+ test_expectation="test_$1"
195
+ shift
196
+ if test "$1" = test_must_fail
197
+ then
198
+ full_command="test_must_fail test_terminal "
199
+ shift
200
+ else
201
+ full_command="test_terminal "
202
+ fi
203
+ cmd=$1
204
+ full_command="$full_command $1"
205
+}
206
+
207
+parse_args expect_success 'git log'
208
+$test_expectation SIMPLEPAGER "$cmd - default pager is used by default" "
209
unset PAGER GIT_PAGER;
210
test_might_fail git config --unset core.pager &&
211
rm -f default_pager_used ||
212
cleanup_fail &&
213
181
- cat >$less <<-\EOF &&
214
+ cat >\$less <<-\EOF &&
215
#!/bin/sh
216
wc >default_pager_used
217
EOF
185
- chmod +x $less &&
218
+ chmod +x \$less &&
219
(
187
- PATH=.:$PATH &&
220
+ PATH=.:\$PATH &&
221
export PATH &&
189
- test_terminal git log
222
+ $full_command
223
) &&
224
test -e default_pager_used
192
-'
225
+"
226
194
-test_expect_success TTY 'PAGER overrides default pager' '
227
+parse_args expect_success 'git log'
228
+$test_expectation TTY "$cmd - PAGER overrides default pager" "
229
unset GIT_PAGER;
230
test_might_fail git config --unset core.pager &&
231
rm -f PAGER_used ||
232
cleanup_fail &&
233
200
- PAGER="wc >PAGER_used" &&
234
+ PAGER='wc >PAGER_used' &&
235
export PAGER &&
202
- test_terminal git log &&
236
+ $full_command &&
237
test -e PAGER_used
204
-'
238
+"
239
206
-test_expect_success TTY 'core.pager overrides PAGER' '
240
+parse_args expect_success 'git log'
241
+$test_expectation TTY "$cmd - core.pager overrides PAGER" "
242
unset GIT_PAGER;
243
rm -f core.pager_used ||
244
cleanup_fail &&
245
246
PAGER=wc &&
247
export PAGER &&
213
- git config core.pager "wc >core.pager_used" &&
214
- test_terminal git log &&
248
+ git config core.pager 'wc >core.pager_used' &&
249
+ $full_command &&
250
test -e core.pager_used
216
-'
251
+"
252
218
-test_expect_success TTY 'GIT_PAGER overrides core.pager' '
253
+parse_args expect_success 'git log'
254
+$test_expectation TTY "$cmd - GIT_PAGER overrides core.pager" "
255
rm -f GIT_PAGER_used ||
256
cleanup_fail &&
257
258
git config core.pager wc &&
223
- GIT_PAGER="wc >GIT_PAGER_used" &&
259
+ GIT_PAGER='wc >GIT_PAGER_used' &&
260
export GIT_PAGER &&
225
- test_terminal git log &&
261
+ $full_command &&
262
test -e GIT_PAGER_used
227
-'
263
+"
264
265
test_done