Skip to content

Commit 007c6b2

Browse files
committed
t: convert grep assertions to test_grep
Replace bare grep with test_grep in test assertions across the suite. 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. Existing '! test_grep' calls are rewritten to 'test_grep !' so that the diagnostic output is preserved on failure. This patch was produced using check-grep.pl (added in the next commit) to identify bare grep assertions, and then applying substitutions to the flagged lines. A handful of greps with backslash-continuation line offsets were fixed manually. To verify, apply the next commit and run: make -C t test-lint-grep Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
1 parent 31a18ee commit 007c6b2

332 files changed

Lines changed: 2779 additions & 2779 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/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

t/t0012-help.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ test_expect_success 'git help succeeds without git.html' '
131131

132132
test_expect_success 'git help --user-interfaces' '
133133
git help --user-interfaces >help.output &&
134-
grep "^ attributes " help.output &&
135-
grep "^ mailmap " help.output
134+
test_grep "^ attributes " help.output &&
135+
test_grep "^ mailmap " help.output
136136
'
137137

138138
test_expect_success 'git help -c' '

t/t0013-sha1dc.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fi
1616
test_expect_success 'test-sha1 detects shattered pdf' '
1717
test_must_fail test-tool sha1 <"$TEST_DATA/shattered-1.pdf" 2>err &&
1818
test_grep collision err &&
19-
grep 38762cf7f55934b34d179ae6a4c80cadccbb7f0a err
19+
test_grep 38762cf7f55934b34d179ae6a4c80cadccbb7f0a err
2020
'
2121

2222
test_done

t/t0017-env-helper.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ test_expect_success 'test-tool env-helper reads config thanks to trace2' '
8888
test_must_fail \
8989
env HOME="$(pwd)/home" \
9090
git config -l 2>err &&
91-
grep "exceeded maximum include depth" err &&
91+
test_grep "exceeded maximum include depth" err &&
9292
9393
# This validates that the assumption that we attempt to
9494
# read the configuration and fail very early in the start-up
@@ -100,7 +100,7 @@ test_expect_success 'test-tool env-helper reads config thanks to trace2' '
100100
test-tool -C no-such-directory \
101101
env-helper --type=bool --default=0 \
102102
--exit-code GIT_TEST_ENV_HELPER 2>err &&
103-
grep "exceeded maximum include depth" err
103+
test_grep "exceeded maximum include depth" err
104104
'
105105

106106
test_done

t/t0021-conversion.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ test_expect_success 'process filter should restart after unexpected write failur
731731
rm -f debug.log &&
732732
git checkout --quiet --no-progress . 2>git-stderr.log &&
733733
734-
grep "smudge write error" git-stderr.log &&
734+
test_grep "smudge write error" git-stderr.log &&
735735
test_grep "error: external filter" git-stderr.log &&
736736
737737
cat >expected.log <<-EOF &&
@@ -853,7 +853,7 @@ test_expect_success 'invalid process filter must fail (and not hang!)' '
853853
854854
cp "$TEST_ROOT/test.o" test.r &&
855855
test_must_fail git add . 2>git-stderr.log &&
856-
grep "expected git-filter-server" git-stderr.log
856+
test_grep "expected git-filter-server" git-stderr.log
857857
)
858858
'
859859

@@ -953,7 +953,7 @@ test_expect_success 'missing file in delayed checkout' '
953953
954954
rm -rf repo-cloned &&
955955
test_must_fail git clone repo repo-cloned 2>git-stderr.log &&
956-
grep "error: .missing-delay\.a. was not filtered properly" git-stderr.log
956+
test_grep "error: .missing-delay\.a. was not filtered properly" git-stderr.log
957957
'
958958

959959
test_expect_success 'invalid file in delayed checkout' '
@@ -974,7 +974,7 @@ test_expect_success 'invalid file in delayed checkout' '
974974
975975
rm -rf repo-cloned &&
976976
test_must_fail git clone repo repo-cloned 2>git-stderr.log &&
977-
grep "error: external filter .* signaled that .unfiltered. is now available although it has not been delayed earlier" git-stderr.log
977+
test_grep "error: external filter .* signaled that .unfiltered. is now available although it has not been delayed earlier" git-stderr.log
978978
'
979979

980980
for mode in 'case' 'utf-8'
@@ -1015,7 +1015,7 @@ do
10151015
10161016
git clone $mode-collision $mode-collision-cloned &&
10171017
# Make sure z was really delayed
1018-
grep "IN: smudge $dir/z .* \\[DELAYED\\]" $mode-collision-cloned/delayed.log &&
1018+
test_grep "IN: smudge $dir/z .* \\[DELAYED\\]" $mode-collision-cloned/delayed.log &&
10191019
10201020
# Should not create $dir/z at $symlink/z
10211021
test_path_is_missing $mode-collision/target-dir/z
@@ -1053,7 +1053,7 @@ test_expect_success SYMLINKS,CASE_INSENSITIVE_FS \
10531053
git commit -m super &&
10541054
10551055
git checkout --recurse-submodules . &&
1056-
grep "IN: smudge A/B/y .* \\[DELAYED\\]" delayed.log &&
1056+
test_grep "IN: smudge A/B/y .* \\[DELAYED\\]" delayed.log &&
10571057
test_path_is_missing target-dir/y
10581058
)
10591059
'
@@ -1144,9 +1144,9 @@ test_expect_success 'delayed checkout correctly reports the number of updated en
11441144
11451145
rm *.a &&
11461146
git checkout . 2>err &&
1147-
grep "IN: smudge test-delay10.a .* \\[DELAYED\\]" delayed.log &&
1148-
grep "IN: smudge test-delay11.a .* \\[DELAYED\\]" delayed.log &&
1149-
grep "Updated 2 paths from the index" err
1147+
test_grep "IN: smudge test-delay10.a .* \\[DELAYED\\]" delayed.log &&
1148+
test_grep "IN: smudge test-delay11.a .* \\[DELAYED\\]" delayed.log &&
1149+
test_grep "Updated 2 paths from the index" err
11501150
)
11511151
'
11521152

t/t0029-core-unsetenvvars.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ test_expect_success 'core.unsetenvvars works' '
2020
HOBBES=Calvin &&
2121
export HOBBES &&
2222
git commit --allow-empty -m with 2>err &&
23-
grep Calvin err &&
23+
test_grep Calvin err &&
2424
git -c core.unsetenvvars=FINDUS,HOBBES,CALVIN \
2525
commit --allow-empty -m without 2>err &&
26-
! grep Calvin err
26+
test_grep ! Calvin err
2727
'
2828

2929
test_done

t/t0030-stripspace.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,12 @@ test_expect_success 'strip comments with changed comment string' '
407407

408408
test_expect_success 'newline as commentchar is forbidden' '
409409
test_must_fail git -c core.commentChar="$LF" stripspace -s 2>err &&
410-
grep "core.commentchar cannot contain newline" err
410+
test_grep "core.commentchar cannot contain newline" err
411411
'
412412

413413
test_expect_success 'empty commentchar is forbidden' '
414414
test_must_fail git -c core.commentchar= stripspace -s 2>err &&
415-
grep "core.commentchar must have at least one character" err
415+
test_grep "core.commentchar must have at least one character" err
416416
'
417417

418418
test_expect_success '-c with single line' '

0 commit comments

Comments
 (0)