Skip to content

Commit 8753941

Browse files
peffspearce
authored andcommitted
tests: grep portability fixes
We try to avoid using the "-q" or "-e" options, as they are largely useless, as explained in aadbe44. There is one exception for "-e" here, which is in t7701 used to produce an "or" of patterns. This can be rewritten as an egrep pattern. This patch also removes use of "grep -F" in favor of the more widely available "fgrep". [sp: Tested on AIX 5.3 by Mike Ralphson, Tested on MinGW by Johannes Sixt] Signed-off-by: Jeff King <[email protected]> Tested-by: Mike Ralphson <[email protected]> Tested-by: Johannes Sixt <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent c33912a commit 8753941

8 files changed

+11
-11
lines changed

t/t0002-gitfile.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test_expect_success 'bad setup: invalid .git file format' '
3232
echo "git rev-parse accepted an invalid .git file"
3333
false
3434
fi &&
35-
if ! grep -qe "Invalid gitfile format" .err
35+
if ! grep "Invalid gitfile format" .err
3636
then
3737
echo "git rev-parse returned wrong error"
3838
false
@@ -46,7 +46,7 @@ test_expect_success 'bad setup: invalid .git file path' '
4646
echo "git rev-parse accepted an invalid .git file path"
4747
false
4848
fi &&
49-
if ! grep -qe "Not a git repository" .err
49+
if ! grep "Not a git repository" .err
5050
then
5151
echo "git rev-parse returned wrong error"
5252
false

t/t1501-worktree.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ test_expect_success 'git diff' '
171171

172172
test_expect_success 'git grep' '
173173
(cd repo.git/work/sub &&
174-
GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep -q dir/tracked)
174+
GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep dir/tracked)
175175
'
176176

177177
test_done

t/t3700-add.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ test_expect_success 'git add '\''fo\[ou\]bar'\'' ignores foobar' '
226226
git reset --hard &&
227227
touch fo\[ou\]bar foobar &&
228228
git add '\''fo\[ou\]bar'\'' &&
229-
git ls-files fo\[ou\]bar | grep -F fo\[ou\]bar &&
229+
git ls-files fo\[ou\]bar | fgrep fo\[ou\]bar &&
230230
! ( git ls-files foobar | grep foobar )
231231
'
232232

t/t4150-am.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ test_expect_success 'am --keep really keeps the subject' '
165165
git am --keep patch4 &&
166166
! test -d .git/rebase-apply &&
167167
git cat-file commit HEAD |
168-
grep -q -F "Re: Re: Re: [PATCH 1/5 v2] third"
168+
fgrep "Re: Re: Re: [PATCH 1/5 v2] third"
169169
'
170170

171171
test_expect_success 'am -3 falls back to 3-way merge' '

t/t6040-tracking-info.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ test_expect_success 'checkout' '
5353
(
5454
cd test && git checkout b1
5555
) >actual &&
56-
grep -e "have 1 and 1 different" actual
56+
grep "have 1 and 1 different" actual
5757
'
5858

5959
test_expect_success 'status' '
@@ -63,7 +63,7 @@ test_expect_success 'status' '
6363
# reports nothing to commit
6464
test_must_fail git status
6565
) >actual &&
66-
grep -e "have 1 and 1 different" actual
66+
grep "have 1 and 1 different" actual
6767
'
6868

6969

t/t7002-grep.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ do
109109
'
110110

111111
test_expect_success "grep -c $L (no /dev/null)" '
112-
! git grep -c test $H | grep -q /dev/null
112+
! git grep -c test $H | grep /dev/null
113113
'
114114

115115
done

t/t7701-repack-unpack-unreachable.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test_expect_success '-A option leaves unreachable objects unpacked' '
2929
git repack -A -d -l &&
3030
# verify objects are packed in repository
3131
test 3 = $(git verify-pack -v -- .git/objects/pack/*.idx |
32-
grep -e "^$fsha1 " -e "^$csha1 " -e "^$tsha1 " |
32+
egrep "^($fsha1|$csha1|$tsha1) " |
3333
sort | uniq | wc -l) &&
3434
git show $fsha1 &&
3535
git show $csha1 &&
@@ -41,7 +41,7 @@ test_expect_success '-A option leaves unreachable objects unpacked' '
4141
git repack -A -d -l &&
4242
# verify objects are retained unpacked
4343
test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
44-
grep -e "^$fsha1 " -e "^$csha1 " -e "^$tsha1 " |
44+
egrep "^($fsha1|$csha1|$tsha1) " |
4545
sort | uniq | wc -l) &&
4646
git show $fsha1 &&
4747
git show $csha1 &&

t/t9500-gitweb-standalone-no-errors.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ gitweb_run () {
5656
rm -f gitweb.log &&
5757
perl -- "$TEST_DIRECTORY/../gitweb/gitweb.perl" \
5858
>/dev/null 2>gitweb.log &&
59-
if grep -q -s "^[[]" gitweb.log >/dev/null; then false; else true; fi
59+
if grep "^[[]" gitweb.log >/dev/null 2>&1; then false; else true; fi
6060

6161
# gitweb.log is left for debugging
6262
}

0 commit comments

Comments
 (0)