mirror of
https://github.com/git/git
synced 2024-08-24 18:26:02 +00:00
grep tests: create a helper function for "BRE" or "ERE"
Refactor the repeated test code for finding out whether a given set of configuration will pick basic, extended or fixed into a new "test_pattern_type" helper function. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
ff37a60c36
commit
ccb1fccc21
134
t/t7810-grep.sh
134
t/t7810-grep.sh
|
@ -98,6 +98,37 @@ test_expect_success 'grep should not segfault with a bad input' '
|
||||||
|
|
||||||
test_invalid_grep_expression --and -e A
|
test_invalid_grep_expression --and -e A
|
||||||
|
|
||||||
|
test_pattern_type () {
|
||||||
|
H=$1 &&
|
||||||
|
HC=$2 &&
|
||||||
|
L=$3 &&
|
||||||
|
type=$4 &&
|
||||||
|
shift 4 &&
|
||||||
|
|
||||||
|
expected_str= &&
|
||||||
|
case "$type" in
|
||||||
|
BRE)
|
||||||
|
expected_str="${HC}ab:a+bc"
|
||||||
|
;;
|
||||||
|
ERE)
|
||||||
|
expected_str="${HC}ab:abc"
|
||||||
|
;;
|
||||||
|
FIX)
|
||||||
|
expected_str="${HC}ab:a+b*c"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
BUG "unknown pattern type '$type'"
|
||||||
|
;;
|
||||||
|
esac &&
|
||||||
|
config_str="$@" &&
|
||||||
|
|
||||||
|
test_expect_success "grep $L with '$config_str' interpreted as $type" '
|
||||||
|
echo $expected_str >expected &&
|
||||||
|
git $config_str grep "a+b*c" $H ab >actual &&
|
||||||
|
test_cmp expected actual
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
for H in HEAD ''
|
for H in HEAD ''
|
||||||
do
|
do
|
||||||
case "$H" in
|
case "$H" in
|
||||||
|
@ -393,35 +424,13 @@ do
|
||||||
git grep --no-recursive -n -e vvv $H -- t . >actual &&
|
git grep --no-recursive -n -e vvv $H -- t . >actual &&
|
||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
test_expect_success "grep $L with grep.extendedRegexp=false" '
|
|
||||||
echo "${HC}ab:a+bc" >expected &&
|
|
||||||
git -c grep.extendedRegexp=false grep "a+b*c" $H ab >actual &&
|
|
||||||
test_cmp expected actual
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success "grep $L with grep.extendedRegexp=true" '
|
|
||||||
echo "${HC}ab:abc" >expected &&
|
|
||||||
git -c grep.extendedRegexp=true grep "a+b*c" $H ab >actual &&
|
|
||||||
test_cmp expected actual
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success "grep $L with grep.patterntype=basic" '
|
test_pattern_type "$H" "$HC" "$L" BRE -c grep.extendedRegexp=false
|
||||||
echo "${HC}ab:a+bc" >expected &&
|
test_pattern_type "$H" "$HC" "$L" ERE -c grep.extendedRegexp=true
|
||||||
git -c grep.patterntype=basic grep "a+b*c" $H ab >actual &&
|
test_pattern_type "$H" "$HC" "$L" BRE -c grep.patternType=basic
|
||||||
test_cmp expected actual
|
test_pattern_type "$H" "$HC" "$L" ERE -c grep.patternType=extended
|
||||||
'
|
test_pattern_type "$H" "$HC" "$L" FIX -c grep.patternType=fixed
|
||||||
|
|
||||||
test_expect_success "grep $L with grep.patterntype=extended" '
|
|
||||||
echo "${HC}ab:abc" >expected &&
|
|
||||||
git -c grep.patterntype=extended grep "a+b*c" $H ab >actual &&
|
|
||||||
test_cmp expected actual
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success "grep $L with grep.patterntype=fixed" '
|
|
||||||
echo "${HC}ab:a+b*c" >expected &&
|
|
||||||
git -c grep.patterntype=fixed grep "a+b*c" $H ab >actual &&
|
|
||||||
test_cmp expected actual
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success PCRE "grep $L with grep.patterntype=perl" '
|
test_expect_success PCRE "grep $L with grep.patterntype=perl" '
|
||||||
echo "${HC}ab:a+b*c" >expected &&
|
echo "${HC}ab:a+b*c" >expected &&
|
||||||
|
@ -433,59 +442,24 @@ do
|
||||||
test_must_fail git -c grep.patterntype=perl grep "foo.*bar"
|
test_must_fail git -c grep.patterntype=perl grep "foo.*bar"
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success "grep $L with grep.patternType=default and grep.extendedRegexp=true" '
|
test_pattern_type "$H" "$HC" "$L" ERE \
|
||||||
echo "${HC}ab:abc" >expected &&
|
-c grep.patternType=default \
|
||||||
git \
|
-c grep.extendedRegexp=true
|
||||||
-c grep.patternType=default \
|
test_pattern_type "$H" "$HC" "$L" ERE \
|
||||||
-c grep.extendedRegexp=true \
|
-c grep.extendedRegexp=true \
|
||||||
grep "a+b*c" $H ab >actual &&
|
-c grep.patternType=default
|
||||||
test_cmp expected actual
|
test_pattern_type "$H" "$HC" "$L" ERE \
|
||||||
'
|
-c grep.patternType=extended \
|
||||||
|
-c grep.extendedRegexp=false
|
||||||
test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=default" '
|
test_pattern_type "$H" "$HC" "$L" BRE \
|
||||||
echo "${HC}ab:abc" >expected &&
|
-c grep.patternType=basic \
|
||||||
git \
|
-c grep.extendedRegexp=true
|
||||||
-c grep.extendedRegexp=true \
|
test_pattern_type "$H" "$HC" "$L" ERE \
|
||||||
-c grep.patternType=default \
|
-c grep.extendedRegexp=false \
|
||||||
grep "a+b*c" $H ab >actual &&
|
-c grep.patternType=extended
|
||||||
test_cmp expected actual
|
test_pattern_type "$H" "$HC" "$L" BRE \
|
||||||
'
|
-c grep.extendedRegexp=true \
|
||||||
|
-c grep.patternType=basic
|
||||||
test_expect_success "grep $L with grep.patternType=extended and grep.extendedRegexp=false" '
|
|
||||||
echo "${HC}ab:abc" >expected &&
|
|
||||||
git \
|
|
||||||
-c grep.patternType=extended \
|
|
||||||
-c grep.extendedRegexp=false \
|
|
||||||
grep "a+b*c" $H ab >actual &&
|
|
||||||
test_cmp expected actual
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success "grep $L with grep.patternType=basic and grep.extendedRegexp=true" '
|
|
||||||
echo "${HC}ab:a+bc" >expected &&
|
|
||||||
git \
|
|
||||||
-c grep.patternType=basic \
|
|
||||||
-c grep.extendedRegexp=true \
|
|
||||||
grep "a+b*c" $H ab >actual &&
|
|
||||||
test_cmp expected actual
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success "grep $L with grep.extendedRegexp=false and grep.patternType=extended" '
|
|
||||||
echo "${HC}ab:abc" >expected &&
|
|
||||||
git \
|
|
||||||
-c grep.extendedRegexp=false \
|
|
||||||
-c grep.patternType=extended \
|
|
||||||
grep "a+b*c" $H ab >actual &&
|
|
||||||
test_cmp expected actual
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=basic" '
|
|
||||||
echo "${HC}ab:a+bc" >expected &&
|
|
||||||
git \
|
|
||||||
-c grep.extendedRegexp=true \
|
|
||||||
-c grep.patternType=basic \
|
|
||||||
grep "a+b*c" $H ab >actual &&
|
|
||||||
test_cmp expected actual
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success "grep --count $L" '
|
test_expect_success "grep --count $L" '
|
||||||
echo ${HC}ab:3 >expected &&
|
echo ${HC}ab:3 >expected &&
|
||||||
|
|
Loading…
Reference in a new issue