Skip to content

Commit 34ceda3

Browse files
committed
t: convert grep assertions to test_grep
Replace bare grep with test_grep in test assertions across the suite, including sourced test helpers (lib-*.sh, *-tests.sh). test_grep prints the contents of the file being searched on failure, making debugging easier than a bare grep which fails silently. Only assertion-style greps are converted: grep used as a filter in pipelines, command substitutions, conditionals, or with redirected I/O is left as-is with a "# lint-ok" annotation. Existing '! test_grep' calls are rewritten to 'test_grep !' so that the diagnostic output is preserved on failure. To reproduce, apply greplint.pl from the next commit and run: # Step 1: mark bare greps that should not be converted sed -i '/! grep "\$m" \.git\/packed-refs/s/$/ # lint-ok: file may not exist (reftable)/' \ t/t1400-update-ref.sh sed -i '/! grep dirty file3 &&/{/lint-ok/!s/$/ # lint-ok: file may not exist after --quit/}' \ t/t3420-rebase-autostash.sh sed -i '/grep -vf before commits\.raw/s/$/ # lint-ok: data filter/' \ t/t5326-multi-pack-bitmaps.sh sed -i '/! grep \$d shallow-client\/\.git\/shallow/s/$/ # lint-ok: file may not exist after repack/' \ t/t5537-fetch-shallow.sh sed -i '/grep -E "^\[0-9a-f\].*|| :/s/$/ # lint-ok: data filter/' \ t/t5702-protocol-v2.sh sed -i '/! grep gitdir squatting-clone/s/$/ # lint-ok: file may not exist after failed clone/' \ t/t7450-bad-git-dotfiles.sh # Step 2: reorder pre-existing '! test_grep' to 'test_grep !' # (must come before steps 3-4 so greplint does not see them) sed -i 's/! test_grep/test_grep !/' t/t0031-lockfile-pid.sh sed -i 's/! test_grep/test_grep !/' t/t5300-pack-object.sh sed -i 's/! test_grep/test_grep !/' t/t5319-multi-pack-index.sh # Step 3: convert '! grep' -> 'test_grep !' perl t/greplint.pl t/*.sh 2>&1 | cut -d: -f1,2 | while IFS=: read f l; do sed -i "${l}s/! *grep/test_grep !/" "$f" done # Step 4: convert remaining 'grep' -> 'test_grep' perl t/greplint.pl t/*.sh 2>&1 | cut -d: -f1,2 | while IFS=: read f l; do sed -i "${l}s/grep/test_grep/" "$f" done To verify, run: make -C t test-greplint Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
1 parent fe33901 commit 34ceda3

338 files changed

Lines changed: 2807 additions & 2807 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

t/for-each-ref-tests.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ test_expect_success 'Verify descending sort' '
523523

524524
test_expect_success 'Give help even with invalid sort atoms' '
525525
test_expect_code 129 ${git_for_each_ref} --sort=bogus -h >actual 2>&1 &&
526-
grep "^usage: ${git_for_each_ref}" actual
526+
test_grep "^usage: ${git_for_each_ref}" actual
527527
'
528528

529529
cat >expected <<\EOF
@@ -622,7 +622,7 @@ test_expect_success 'Quoting style: tcl' '
622622
for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
623623
test_expect_success "more than one quoting style: $i" "
624624
test_must_fail ${git_for_each_ref} $i 2>err &&
625-
grep '^error: more than one quoting style' err
625+
test_grep '^error: more than one quoting style' err
626626
"
627627
done
628628

@@ -1892,7 +1892,7 @@ test_expect_success "${git_for_each_ref} --stdin: fails if extra args" '
18921892
>in &&
18931893
test_must_fail ${git_for_each_ref} --format="%(refname)" \
18941894
--stdin refs/heads/extra <in 2>err &&
1895-
grep "unknown arguments supplied with --stdin" err
1895+
test_grep "unknown arguments supplied with --stdin" err
18961896
'
18971897

18981898
test_expect_success "${git_for_each_ref} --stdin: matches" '
@@ -1955,11 +1955,11 @@ test_expect_success "${git_for_each_ref} with nested tags" '
19551955

19561956
test_expect_success 'is-base atom with non-commits' '
19571957
${git_for_each_ref} --format="%(is-base:HEAD) %(refname)" >out 2>err &&
1958-
grep "(HEAD) refs/heads/main" out &&
1958+
test_grep "(HEAD) refs/heads/main" out &&
19591959
19601960
test_line_count = 2 err &&
1961-
grep "error: object .* is a commit, not a blob" err &&
1962-
grep "error: bad tag pointer to" err
1961+
test_grep "error: object .* is a commit, not a blob" err &&
1962+
test_grep "error: bad tag pointer to" err
19631963
'
19641964

19651965
GRADE_FORMAT="%(signature:grade)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)"

t/lib-bitmap.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ rev_list_tests_head () {
173173

174174
test_expect_success "bitmap --objects handles non-commit objects ($state, $branch)" '
175175
git rev-list --objects --use-bitmap-index $branch tagged-blob >actual &&
176-
grep $blob actual
176+
test_grep $blob actual
177177
'
178178
}
179179

@@ -242,16 +242,16 @@ basic_bitmap_tests () {
242242
GIT_PROGRESS_DELAY=0 \
243243
git pack-objects --all --stdout --progress \
244244
</dev/null >/dev/null 2>stderr &&
245-
grep "Enumerating objects: $count, done" stderr &&
246-
grep "pack-reused $count" stderr &&
245+
test_grep "Enumerating objects: $count, done" stderr &&
246+
test_grep "pack-reused $count" stderr &&
247247
248248
# now the same but with one non-reused object
249249
git commit --allow-empty -m "an extra commit object" &&
250250
GIT_PROGRESS_DELAY=0 \
251251
git pack-objects --all --stdout --progress \
252252
</dev/null >/dev/null 2>stderr &&
253-
grep "Enumerating objects: $((count+1)), done" stderr &&
254-
grep "pack-reused $count" stderr
253+
test_grep "Enumerating objects: $((count+1)), done" stderr &&
254+
test_grep "pack-reused $count" stderr
255255
'
256256
}
257257

@@ -283,7 +283,7 @@ test_rev_exists () {
283283
then
284284
test_path_is_file $midx-$(midx_checksum $objdir).rev
285285
fi &&
286-
grep "\"category\":\"load_midx_revindex\",\"key\":\"source\",\"value\":\"$kind\"" event.trace
286+
test_grep "\"category\":\"load_midx_revindex\",\"key\":\"source\",\"value\":\"$kind\"" event.trace
287287
'
288288
}
289289

t/lib-bundle-uri-protocol.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ test_expect_success "connect with $BUNDLE_URI_PROTOCOL:// using protocol v2: no
6363
>actual 2>err &&
6464
6565
# Server responded using protocol v2
66-
grep "< version 2" log &&
66+
test_grep "< version 2" log &&
6767
68-
! grep bundle-uri log
68+
test_grep ! bundle-uri log
6969
'
7070

7171
test_expect_success "connect with $BUNDLE_URI_PROTOCOL:// using protocol v2: have bundle-uri" '
@@ -78,10 +78,10 @@ test_expect_success "connect with $BUNDLE_URI_PROTOCOL:// using protocol v2: hav
7878
>actual 2>err &&
7979
8080
# Server responded using protocol v2
81-
grep "< version 2" log &&
81+
test_grep "< version 2" log &&
8282
8383
# Server advertised bundle-uri capability
84-
grep "< bundle-uri" log
84+
test_grep "< bundle-uri" log
8585
'
8686

8787
test_expect_success "clone with $BUNDLE_URI_PROTOCOL:// using protocol v2: request bundle-uris" '
@@ -95,13 +95,13 @@ test_expect_success "clone with $BUNDLE_URI_PROTOCOL:// using protocol v2: reque
9595
>actual 2>err &&
9696
9797
# Server responded using protocol v2
98-
grep "< version 2" log &&
98+
test_grep "< version 2" log &&
9999
100100
# Server advertised bundle-uri capability
101-
grep "< bundle-uri" log &&
101+
test_grep "< bundle-uri" log &&
102102
103103
# Client did not issue bundle-uri command
104-
! grep "> command=bundle-uri" log &&
104+
test_grep ! "> command=bundle-uri" log &&
105105
106106
GIT_TRACE_PACKET="$PWD/log" \
107107
git \
@@ -111,13 +111,13 @@ test_expect_success "clone with $BUNDLE_URI_PROTOCOL:// using protocol v2: reque
111111
>actual 2>err &&
112112
113113
# Server responded using protocol v2
114-
grep "< version 2" log &&
114+
test_grep "< version 2" log &&
115115
116116
# Server advertised bundle-uri capability
117-
grep "< bundle-uri" log &&
117+
test_grep "< bundle-uri" log &&
118118
119119
# Client issued bundle-uri command
120-
grep "> command=bundle-uri" log &&
120+
test_grep "> command=bundle-uri" log &&
121121
122122
GIT_TRACE_PACKET="$PWD/log3" \
123123
git \
@@ -128,13 +128,13 @@ test_expect_success "clone with $BUNDLE_URI_PROTOCOL:// using protocol v2: reque
128128
>actual 2>err &&
129129
130130
# Server responded using protocol v2
131-
grep "< version 2" log3 &&
131+
test_grep "< version 2" log3 &&
132132
133133
# Server advertised bundle-uri capability
134-
grep "< bundle-uri" log3 &&
134+
test_grep "< bundle-uri" log3 &&
135135
136136
# Client did not issue bundle-uri command (--bundle-uri override)
137-
! grep "> command=bundle-uri" log3
137+
test_grep ! "> command=bundle-uri" log3
138138
'
139139

140140
# The remaining tests will all assume transfer.bundleURI=true

t/lib-httpd.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ test_http_push_nonff () {
275275
'
276276

277277
test_expect_success 'non-fast-forward push show ref status' '
278-
grep "^ ! \[rejected\][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" output
278+
test_grep "^ ! \[rejected\][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" output
279279
'
280280

281281
test_expect_success 'non-fast-forward push shows help message' '

t/pack-refs-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ test_expect_success 'delete ref while another dangling packed ref' '
195195
test_expect_success 'pack ref directly below refs/' '
196196
git update-ref refs/top HEAD &&
197197
git ${pack_refs} --all --prune &&
198-
grep refs/top .git/packed-refs &&
198+
test_grep refs/top .git/packed-refs &&
199199
test_path_is_missing .git/refs/top
200200
'
201201

t/show-ref-exists-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test_expect_success '--exists with missing reference' '
1919

2020
test_expect_success '--exists does not use DWIM' '
2121
test_expect_code 2 ${git_show_ref_exists} $GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 2>err &&
22-
grep "reference does not exist" err
22+
test_grep "reference does not exist" err
2323
'
2424

2525
test_expect_success '--exists with HEAD' '

t/t0000-basic.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ test_expect_success 'subtest: lazy prereqs do not turn off tracing' '
743743
test_done
744744
EOF
745745
746-
grep "echo trace" lazy-prereq-and-tracing/err
746+
test_grep "echo trace" lazy-prereq-and-tracing/err
747747
'
748748

749749
test_expect_success 'subtest: tests clean up after themselves' '
@@ -815,7 +815,7 @@ test_expect_success 'subtest: test_atexit is run' '
815815

816816
test_expect_success 'test_oid provides sane info by default' '
817817
test_oid zero >actual &&
818-
grep "^00*\$" actual &&
818+
test_grep "^00*\$" actual &&
819819
rawsz="$(test_oid rawsz)" &&
820820
hexsz="$(test_oid hexsz)" &&
821821
# +1 accounts for the trailing newline
@@ -827,7 +827,7 @@ test_expect_success 'test_oid can look up data for SHA-1' '
827827
test_when_finished "test_detect_hash" &&
828828
test_set_hash sha1 &&
829829
test_oid zero >actual &&
830-
grep "^00*\$" actual &&
830+
test_grep "^00*\$" actual &&
831831
rawsz="$(test_oid rawsz)" &&
832832
hexsz="$(test_oid hexsz)" &&
833833
test $(wc -c <actual) -eq 41 &&
@@ -839,7 +839,7 @@ test_expect_success 'test_oid can look up data for SHA-256' '
839839
test_when_finished "test_detect_hash" &&
840840
test_set_hash sha256 &&
841841
test_oid zero >actual &&
842-
grep "^00*\$" actual &&
842+
test_grep "^00*\$" actual &&
843843
rawsz="$(test_oid rawsz)" &&
844844
hexsz="$(test_oid hexsz)" &&
845845
test $(wc -c <actual) -eq 65 &&
@@ -884,11 +884,11 @@ test_expect_success 'test_bool_env' '
884884
# test script, hence the redirection of fd 7, and aborts
885885
# with "exit 1", hence the subshell.
886886
! ( test_bool_env envvar true ) 7>err &&
887-
grep "error: test_bool_env requires bool values" err &&
887+
test_grep "error: test_bool_env requires bool values" err &&
888888
889889
envvar=true &&
890890
! ( test_bool_env envvar invalid ) 7>err &&
891-
grep "error: test_bool_env requires bool values" err
891+
test_grep "error: test_bool_env requires bool values" err
892892
)
893893
'
894894

@@ -1242,12 +1242,12 @@ test_expect_success 'test_must_fail on a failing git command with env' '
12421242

12431243
test_expect_success 'test_must_fail rejects a non-git command' '
12441244
! test_must_fail grep ^$ notafile 2>err &&
1245-
grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err
1245+
test_grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err
12461246
'
12471247

12481248
test_expect_success 'test_must_fail rejects a non-git command with env' '
12491249
! test_must_fail env var1=a var2=b grep ^$ notafile 2>err &&
1250-
grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err
1250+
test_grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err
12511251
'
12521252

12531253
test_done

t/t0001-init.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shar
278278
git init --bare --shared=0660 newdir/a/b/c &&
279279
test_path_is_dir newdir/a/b/c/refs &&
280280
ls -ld newdir/a newdir/a/b > lsab.out &&
281-
! grep -v "^drwxrw[sx]r-x" lsab.out &&
281+
test_grep ! -v "^drwxrw[sx]r-x" lsab.out &&
282282
ls -ld newdir/a/b/c > lsc.out &&
283-
! grep -v "^drwxrw[sx]---" lsc.out
283+
test_grep ! -v "^drwxrw[sx]---" lsc.out
284284
)
285285
'
286286

@@ -619,7 +619,7 @@ test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage is not allowed wi
619619
git init refstorage &&
620620
git -C refstorage config extensions.refStorage files &&
621621
test_must_fail git -C refstorage rev-parse 2>err &&
622-
grep "repo version is 0, but v1-only extension found" err
622+
test_grep "repo version is 0, but v1-only extension found" err
623623
'
624624

625625
test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage with files backend' '
@@ -637,7 +637,7 @@ test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage with unknown back
637637
git -C refstorage config core.repositoryformatversion 1 &&
638638
git -C refstorage config extensions.refStorage garbage &&
639639
test_must_fail git -C refstorage rev-parse 2>err &&
640-
grep "invalid value for ${SQ}extensions.refstorage${SQ}: ${SQ}garbage${SQ}" err
640+
test_grep "invalid value for ${SQ}extensions.refstorage${SQ}: ${SQ}garbage${SQ}" err
641641
'
642642

643643
test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' '
@@ -848,8 +848,8 @@ test_expect_success MINGW 'redirect std handles' '
848848
GIT_REDIRECT_STDOUT=output.txt \
849849
GIT_REDIRECT_STDERR="2>&1" \
850850
git rev-parse --git-dir --verify refs/invalid &&
851-
grep "^\\.git\$" output.txt &&
852-
grep "Needed a single revision" output.txt
851+
test_grep "^\\.git\$" output.txt &&
852+
test_grep "Needed a single revision" output.txt
853853
'
854854

855855
test_expect_success '--initial-branch' '
@@ -862,14 +862,14 @@ test_expect_success '--initial-branch' '
862862
git init --initial-branch=ignore initial-branch-option 2>err &&
863863
test_grep "ignored --initial-branch" err &&
864864
git -C initial-branch-option symbolic-ref HEAD >actual &&
865-
grep hello actual
865+
test_grep hello actual
866866
'
867867

868868
test_expect_success 'overridden default initial branch name (config)' '
869869
test_config_global init.defaultBranch nmb &&
870870
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git init initial-branch-config &&
871871
git -C initial-branch-config symbolic-ref HEAD >actual &&
872-
grep nmb actual
872+
test_grep nmb actual
873873
'
874874

875875
test_expect_success 'advice on unconfigured init.defaultBranch' '
@@ -907,7 +907,7 @@ test_expect_success 'overridden default main branch name (env)' '
907907
test_config_global init.defaultBranch nmb &&
908908
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&
909909
git -C main-branch-env symbolic-ref HEAD >actual &&
910-
grep env actual
910+
test_grep env actual
911911
'
912912

913913
test_expect_success 'invalid default branch name' '

t/t0008-ignores.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,8 @@ test_expect_success 'existing file and directory' '
790790
>one &&
791791
mkdir top-level-dir &&
792792
git check-ignore one top-level-dir >actual &&
793-
grep one actual &&
794-
grep top-level-dir actual
793+
test_grep one actual &&
794+
test_grep top-level-dir actual
795795
'
796796

797797
test_expect_success 'existing directory and file' '
@@ -800,8 +800,8 @@ test_expect_success 'existing directory and file' '
800800
>one &&
801801
mkdir top-level-dir &&
802802
git check-ignore top-level-dir one >actual &&
803-
grep one actual &&
804-
grep top-level-dir actual
803+
test_grep one actual &&
804+
test_grep top-level-dir actual
805805
'
806806

807807
test_expect_success 'exact prefix matching (with root)' '

t/t0009-git-dir-validation.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test_expect_success PIPE 'setup: .git as a FIFO (named pipe) is rejected' '
3535
cd parent/fifo-trap &&
3636
mkfifo .git &&
3737
test_must_fail git rev-parse --git-dir 2>stderr &&
38-
grep "not a regular file" stderr
38+
test_grep "not a regular file" stderr
3939
)
4040
'
4141

@@ -47,7 +47,7 @@ test_expect_success SYMLINKS,PIPE 'setup: .git as a symlink to a FIFO is rejecte
4747
mkfifo target-fifo &&
4848
ln -s target-fifo .git &&
4949
test_must_fail git rev-parse --git-dir 2>stderr &&
50-
grep "not a regular file" stderr
50+
test_grep "not a regular file" stderr
5151
)
5252
'
5353

@@ -58,7 +58,7 @@ test_expect_success 'setup: .git with garbage content is rejected' '
5858
cd parent/garbage-trap &&
5959
echo "garbage" >.git &&
6060
test_must_fail git rev-parse --git-dir 2>stderr &&
61-
grep "invalid gitfile format" stderr
61+
test_grep "invalid gitfile format" stderr
6262
)
6363
'
6464

0 commit comments

Comments
 (0)