Skip to content

Commit 3c7406d

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 492b107 commit 3c7406d

File tree

1 file changed

+54
-18
lines changed

1 file changed

+54
-18
lines changed

t/t7006-pager.sh

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,58 +172,94 @@ then
172172
test_set_prereq SIMPLEPAGER
173173
fi
174174

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" "
176209
unset PAGER GIT_PAGER;
177210
test_might_fail git config --unset core.pager &&
178211
rm -f default_pager_used ||
179212
cleanup_fail &&
180213
181-
cat >$less <<-\EOF &&
214+
cat >\$less <<-\EOF &&
182215
#!/bin/sh
183216
wc >default_pager_used
184217
EOF
185-
chmod +x $less &&
218+
chmod +x \$less &&
186219
(
187-
PATH=.:$PATH &&
220+
PATH=.:\$PATH &&
188221
export PATH &&
189-
test_terminal git log
222+
$full_command
190223
) &&
191224
test -e default_pager_used
192-
'
225+
"
193226

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" "
195229
unset GIT_PAGER;
196230
test_might_fail git config --unset core.pager &&
197231
rm -f PAGER_used ||
198232
cleanup_fail &&
199233
200-
PAGER="wc >PAGER_used" &&
234+
PAGER='wc >PAGER_used' &&
201235
export PAGER &&
202-
test_terminal git log &&
236+
$full_command &&
203237
test -e PAGER_used
204-
'
238+
"
205239

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" "
207242
unset GIT_PAGER;
208243
rm -f core.pager_used ||
209244
cleanup_fail &&
210245
211246
PAGER=wc &&
212247
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 &&
215250
test -e core.pager_used
216-
'
251+
"
217252

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" "
219255
rm -f GIT_PAGER_used ||
220256
cleanup_fail &&
221257
222258
git config core.pager wc &&
223-
GIT_PAGER="wc >GIT_PAGER_used" &&
259+
GIT_PAGER='wc >GIT_PAGER_used' &&
224260
export GIT_PAGER &&
225-
test_terminal git log &&
261+
$full_command &&
226262
test -e GIT_PAGER_used
227-
'
263+
"
228264

229265
test_done

0 commit comments

Comments
 (0)