test-lib: refactor $GIT_SKIP_TESTS matching

It's already used twice, and we will have more of the same kind of matching in a minute. Helped-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Thomas Rast <trast@inf.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Jun 18, 2013 at 14:25 UTC e6a6ddc93a89862319c7876536d79d6d3538de5a
1 file changed +24 -17
t/test-lib.sh
+24 -17
@@ -328,6 +328,20 @@ test_debug () {
328 test "$debug" = "" || eval "$1"
329 }
330
331 +match_pattern_list () {
332 + arg="$1"
333 + shift
334 + test -z "$*" && return 1
335 + for pattern_
336 + do
337 + case "$arg" in
338 + $pattern_)
339 + return 0
340 + esac
341 + done
342 + return 1
343 +}
344 +
345 test_eval_ () {
346 # This is a separate function because some tests use
347 # "return" to end a test_expect_success block early.
@@ -358,14 +372,10 @@ test_run_ () {
372 test_skip () {
373 test_count=$(($test_count+1))
374 to_skip=
361 - for skp in $GIT_SKIP_TESTS
362 - do
363 - case $this_test.$test_count in
364 - $skp)
365 - to_skip=t
366 - break
367 - esac
368 - done
375 + if match_pattern_list $this_test.$test_count $GIT_SKIP_TESTS
376 + then
377 + to_skip=t
378 + fi
379 if test -z "$to_skip" && test -n "$test_prereq" &&
380 ! test_have_prereq "$test_prereq"
381 then
@@ -630,15 +640,12 @@ cd -P "$TRASH_DIRECTORY" || exit 1
640
641 this_test=${0##*/}
642 this_test=${this_test%%-*}
633 -for skp in $GIT_SKIP_TESTS
634 -do
635 - case "$this_test" in
636 - $skp)
637 - say_color info >&3 "skipping test $this_test altogether"
638 - skip_all="skip all tests in $this_test"
639 - test_done
640 - esac
641 -done
643 +if match_pattern_list "$this_test" $GIT_SKIP_TESTS
644 +then
645 + say_color info >&3 "skipping test $this_test altogether"
646 + skip_all="skip all tests in $this_test"
647 + test_done
648 +fi
649
650 # Provide an implementation of the 'yes' utility
651 yes () {