Merge branch 'jk/test-avoid-globmatch-with-skip-patterns'

We broke "GIT_SKIP_TESTS=t?000" to skip certain tests in recent
update, which got fixed.

* jk/test-avoid-globmatch-with-skip-patterns:
  test-lib: avoid accidental globbing in match_pattern_list()
This commit is contained in:
Junio C Hamano
2021-07-08 13:15:01 -07:00

View File

@ -732,14 +732,24 @@ match_pattern_list () {
arg="$1" arg="$1"
shift shift
test -z "$*" && return 1 test -z "$*" && return 1
for pattern_ # We need to use "$*" to get field-splitting, but we want to
do # disable globbing, since we are matching against an arbitrary
case "$arg" in # $arg, not what's in the filesystem. Using "set -f" accomplishes
$pattern_) # that, but we must do it in a subshell to avoid impacting the
return 0 # rest of the script. The exit value of the subshell becomes
esac # the function's return value.
done (
return 1 set -f
for pattern_ in $*
do
case "$arg" in
$pattern_)
exit 0
;;
esac
done
exit 1
)
} }
match_test_selector_list () { match_test_selector_list () {
@ -848,7 +858,7 @@ maybe_teardown_verbose () {
last_verbose=t last_verbose=t
maybe_setup_verbose () { maybe_setup_verbose () {
test -z "$verbose_only" && return test -z "$verbose_only" && return
if match_pattern_list $test_count $verbose_only if match_pattern_list $test_count "$verbose_only"
then then
exec 4>&2 3>&1 exec 4>&2 3>&1
# Emit a delimiting blank line when going from # Emit a delimiting blank line when going from
@ -878,7 +888,7 @@ maybe_setup_valgrind () {
return return
fi fi
GIT_VALGRIND_ENABLED= GIT_VALGRIND_ENABLED=
if match_pattern_list $test_count $valgrind_only if match_pattern_list $test_count "$valgrind_only"
then then
GIT_VALGRIND_ENABLED=t GIT_VALGRIND_ENABLED=t
fi fi
@ -1006,7 +1016,7 @@ test_finish_ () {
test_skip () { test_skip () {
to_skip= to_skip=
skipped_reason= skipped_reason=
if match_pattern_list $this_test.$test_count $GIT_SKIP_TESTS if match_pattern_list $this_test.$test_count "$GIT_SKIP_TESTS"
then then
to_skip=t to_skip=t
skipped_reason="GIT_SKIP_TESTS" skipped_reason="GIT_SKIP_TESTS"
@ -1346,7 +1356,7 @@ fi
remove_trash= remove_trash=
this_test=${0##*/} this_test=${0##*/}
this_test=${this_test%%-*} this_test=${this_test%%-*}
if match_pattern_list "$this_test" $GIT_SKIP_TESTS if match_pattern_list "$this_test" "$GIT_SKIP_TESTS"
then then
say_color info >&3 "skipping test $this_test altogether" say_color info >&3 "skipping test $this_test altogether"
skip_all="skip all tests in $this_test" skip_all="skip all tests in $this_test"