t: drop "verbose" helper function

We have a small helper function called "verbose", with the idea that you can write: verbose foo to get a message to stderr when the "foo" command fails, even if it does not produce any output itself. This goes back to 8ad1652418 (t5304: use helper to report failure of "test foo = bar", 2014-10-10). It does work, but overall it has not been a big success for two reasons: 1. Test writers have to remember to put it there (and the resulting test code is longer as a result). 2. It doesn't handle the opposite case (we expect "foo" to fail, but it succeeds), leading to inconsistencies in tests (which you can see in many hunks of this patch, e.g. ones involving "has_cr"). Most importantly, we added a136f6d8ff (test-lib.sh: support -x option for shell-tracing, 2014-10-10) at the same time, and it does roughly the same thing. The output is not quite as succinct as "verbose", and you have to watch out for stray shell-traces ending up in stderr. But it solves both of the problems above, and has clearly become the preferred tool. Let's consider the "verbose" function a failed experiment and remove the last few callers (which are all many years old, and have been dwindling as we remove them from scripts we touch for other reasons). It will be one less thing for new test writers to see and wonder if they should be using themselves. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 8, 2023 at 15:04 UTC 8ddfce7144bc965b030e0359f11b7282990e72fb
12 files changed +57 -66
t/t0020-crlf.sh
+19 -19
@@ -125,7 +125,7 @@ test_expect_success 'update with autocrlf=input' '
125 munge_cr append dir/two &&
126 git update-index -- one dir/two &&
127 differs=$(git diff-index --cached HEAD) &&
128 - verbose test -z "$differs"
128 + test -z "$differs"
129
130 '
131
@@ -138,7 +138,7 @@ test_expect_success 'update with autocrlf=true' '
138 munge_cr append dir/two &&
139 git update-index -- one dir/two &&
140 differs=$(git diff-index --cached HEAD) &&
141 - verbose test -z "$differs"
141 + test -z "$differs"
142
143 '
144
@@ -153,7 +153,7 @@ test_expect_success 'checkout with autocrlf=true' '
153 test "$one" = $(git hash-object --stdin <one) &&
154 test "$two" = $(git hash-object --stdin <dir/two) &&
155 differs=$(git diff-index --cached HEAD) &&
156 - verbose test -z "$differs"
156 + test -z "$differs"
157 '
158
159 test_expect_success 'checkout with autocrlf=input' '
@@ -167,7 +167,7 @@ test_expect_success 'checkout with autocrlf=input' '
167 test "$one" = $(git hash-object --stdin <one) &&
168 test "$two" = $(git hash-object --stdin <dir/two) &&
169 differs=$(git diff-index --cached HEAD) &&
170 - verbose test -z "$differs"
170 + test -z "$differs"
171 '
172
173 test_expect_success 'apply patch (autocrlf=input)' '
@@ -177,7 +177,7 @@ test_expect_success 'apply patch (autocrlf=input)' '
177 git read-tree --reset -u HEAD &&
178
179 git apply patch.file &&
180 - verbose test "$patched" = "$(git hash-object --stdin <one)"
180 + test "$patched" = "$(git hash-object --stdin <one)"
181 '
182
183 test_expect_success 'apply patch --cached (autocrlf=input)' '
@@ -187,7 +187,7 @@ test_expect_success 'apply patch --cached (autocrlf=input)' '
187 git read-tree --reset -u HEAD &&
188
189 git apply --cached patch.file &&
190 - verbose test "$patched" = $(git rev-parse :one)
190 + test "$patched" = $(git rev-parse :one)
191 '
192
193 test_expect_success 'apply patch --index (autocrlf=input)' '
@@ -197,8 +197,8 @@ test_expect_success 'apply patch --index (autocrlf=input)' '
197 git read-tree --reset -u HEAD &&
198
199 git apply --index patch.file &&
200 - verbose test "$patched" = $(git rev-parse :one) &&
201 - verbose test "$patched" = $(git hash-object --stdin <one)
200 + test "$patched" = $(git rev-parse :one) &&
201 + test "$patched" = $(git hash-object --stdin <one)
202 '
203
204 test_expect_success 'apply patch (autocrlf=true)' '
@@ -208,7 +208,7 @@ test_expect_success 'apply patch (autocrlf=true)' '
208 git read-tree --reset -u HEAD &&
209
210 git apply patch.file &&
211 - verbose test "$patched" = "$(remove_cr <one | git hash-object --stdin)"
211 + test "$patched" = "$(remove_cr <one | git hash-object --stdin)"
212 '
213
214 test_expect_success 'apply patch --cached (autocrlf=true)' '
@@ -218,7 +218,7 @@ test_expect_success 'apply patch --cached (autocrlf=true)' '
218 git read-tree --reset -u HEAD &&
219
220 git apply --cached patch.file &&
221 - verbose test "$patched" = $(git rev-parse :one)
221 + test "$patched" = $(git rev-parse :one)
222 '
223
224 test_expect_success 'apply patch --index (autocrlf=true)' '
@@ -228,8 +228,8 @@ test_expect_success 'apply patch --index (autocrlf=true)' '
228 git read-tree --reset -u HEAD &&
229
230 git apply --index patch.file &&
231 - verbose test "$patched" = $(git rev-parse :one) &&
232 - verbose test "$patched" = "$(remove_cr <one | git hash-object --stdin)"
231 + test "$patched" = $(git rev-parse :one) &&
232 + test "$patched" = "$(remove_cr <one | git hash-object --stdin)"
233 '
234
235 test_expect_success '.gitattributes says two is binary' '
@@ -240,7 +240,7 @@ test_expect_success '.gitattributes says two is binary' '
240 git read-tree --reset -u HEAD &&
241
242 ! has_cr dir/two &&
243 - verbose has_cr one &&
243 + has_cr one &&
244 ! has_cr three
245 '
246
@@ -259,8 +259,8 @@ test_expect_success '.gitattributes says two and three are text' '
259 echo "t* crlf" >.gitattributes &&
260 git read-tree --reset -u HEAD &&
261
262 - verbose has_cr dir/two &&
263 - verbose has_cr three
262 + has_cr dir/two &&
263 + has_cr three
264 '
265
266 test_expect_success 'in-tree .gitattributes (1)' '
@@ -273,7 +273,7 @@ test_expect_success 'in-tree .gitattributes (1)' '
273 git read-tree --reset -u HEAD &&
274
275 ! has_cr one &&
276 - verbose has_cr three
276 + has_cr three
277 '
278
279 test_expect_success 'in-tree .gitattributes (2)' '
@@ -283,7 +283,7 @@ test_expect_success 'in-tree .gitattributes (2)' '
283 git checkout-index -f -q -u -a &&
284
285 ! has_cr one &&
286 - verbose has_cr three
286 + has_cr three
287 '
288
289 test_expect_success 'in-tree .gitattributes (3)' '
@@ -294,7 +294,7 @@ test_expect_success 'in-tree .gitattributes (3)' '
294 git checkout-index -u one dir/two three &&
295
296 ! has_cr one &&
297 - verbose has_cr three
297 + has_cr three
298 '
299
300 test_expect_success 'in-tree .gitattributes (4)' '
@@ -305,7 +305,7 @@ test_expect_success 'in-tree .gitattributes (4)' '
305 git checkout-index -u .gitattributes &&
306
307 ! has_cr one &&
308 - verbose has_cr three
308 + has_cr three
309 '
310
311 test_expect_success 'checkout with existing .gitattributes' '
t/t1301-shared-repo.sh
+2 -2
@@ -89,7 +89,7 @@ do
89 rm -f .git/info/refs &&
90 git update-server-info &&
91 actual="$(test_modebits .git/info/refs)" &&
92 - verbose test "x$actual" = "x-$y"
92 + test "x$actual" = "x-$y"
93
94 '
95
@@ -99,7 +99,7 @@ do
99 rm -f .git/info/refs &&
100 git update-server-info &&
101 actual="$(test_modebits .git/info/refs)" &&
102 - verbose test "x$actual" = "x-$x"
102 + test "x$actual" = "x-$x"
103
104 '
105
t/t3427-rebase-subtree.sh
+6 -6
@@ -74,9 +74,9 @@ test_expect_success 'Rebase -Xsubtree --empty=ask --onto commit' '
74 test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --onto files-main main &&
75 : first pick results in no changes &&
76 git rebase --skip &&
77 - verbose test "$(commit_message HEAD~2)" = "topic_4" &&
78 - verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
79 - verbose test "$(commit_message HEAD)" = "Empty commit"
77 + test "$(commit_message HEAD~2)" = "topic_4" &&
78 + test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
79 + test "$(commit_message HEAD)" = "Empty commit"
80 '
81
82 test_expect_success 'Rebase -Xsubtree --empty=ask --rebase-merges --onto commit' '
@@ -85,9 +85,9 @@ test_expect_success 'Rebase -Xsubtree --empty=ask --rebase-merges --onto commit'
85 test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --rebase-merges --onto files-main --root &&
86 : first pick results in no changes &&
87 git rebase --skip &&
88 - verbose test "$(commit_message HEAD~2)" = "topic_4" &&
89 - verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
90 - verbose test "$(commit_message HEAD)" = "Empty commit"
88 + test "$(commit_message HEAD~2)" = "topic_4" &&
89 + test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
90 + test "$(commit_message HEAD)" = "Empty commit"
91 '
92
93 test_done
t/t4022-diff-rewrite.sh
+1 -1
@@ -24,7 +24,7 @@ test_expect_success setup '
24 test_expect_success 'detect rewrite' '
25
26 actual=$(git diff-files -B --summary test) &&
27 - verbose expr "$actual" : " rewrite test ([0-9]*%)$"
27 + expr "$actual" : " rewrite test ([0-9]*%)$"
28
29 '
30
t/t4062-diff-pickaxe.sh
+1 -1
@@ -24,7 +24,7 @@ test_expect_success '-G matches' '
24
25 test_expect_success '-S --pickaxe-regex' '
26 git diff --name-only -S0 --pickaxe-regex HEAD^ >out &&
27 - verbose test 4096-zeroes.txt = "$(cat out)"
27 + test 4096-zeroes.txt = "$(cat out)"
28 '
29
30 test_done
t/t5304-prune.sh
+8 -8
@@ -16,7 +16,7 @@ add_blob() {
16 before=$(git count-objects | sed "s/ .*//") &&
17 BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
18 BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
19 - verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
19 + test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
20 test_path_is_file $BLOB_FILE &&
21 test-tool chmtime =+0 $BLOB_FILE
22 }
@@ -51,11 +51,11 @@ test_expect_success 'prune stale packs' '
51 test_expect_success 'prune --expire' '
52 add_blob &&
53 git prune --expire=1.hour.ago &&
54 - verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
54 + test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
55 test_path_is_file $BLOB_FILE &&
56 test-tool chmtime =-86500 $BLOB_FILE &&
57 git prune --expire 1.day &&
58 - verbose test $before = $(git count-objects | sed "s/ .*//") &&
58 + test $before = $(git count-objects | sed "s/ .*//") &&
59 test_path_is_missing $BLOB_FILE
60 '
61
@@ -63,11 +63,11 @@ test_expect_success 'gc: implicit prune --expire' '
63 add_blob &&
64 test-tool chmtime =-$((2*$week-30)) $BLOB_FILE &&
65 git gc --no-cruft &&
66 - verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
66 + test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
67 test_path_is_file $BLOB_FILE &&
68 test-tool chmtime =-$((2*$week+1)) $BLOB_FILE &&
69 git gc --no-cruft &&
70 - verbose test $before = $(git count-objects | sed "s/ .*//") &&
70 + test $before = $(git count-objects | sed "s/ .*//") &&
71 test_path_is_missing $BLOB_FILE
72 '
73
@@ -138,7 +138,7 @@ test_expect_success 'gc --no-prune' '
138 test-tool chmtime =-$((5001*$day)) $BLOB_FILE &&
139 git config gc.pruneExpire 2.days.ago &&
140 git gc --no-prune --no-cruft &&
141 - verbose test 1 = $(git count-objects | sed "s/ .*//") &&
141 + test 1 = $(git count-objects | sed "s/ .*//") &&
142 test_path_is_file $BLOB_FILE
143 '
144
@@ -192,10 +192,10 @@ test_expect_success 'gc: prune old objects after local clone' '
192 git clone --no-hardlinks . aclone &&
193 (
194 cd aclone &&
195 - verbose test 1 = $(git count-objects | sed "s/ .*//") &&
195 + test 1 = $(git count-objects | sed "s/ .*//") &&
196 test_path_is_file $BLOB_FILE &&
197 git gc --prune --no-cruft &&
198 - verbose test 0 = $(git count-objects | sed "s/ .*//") &&
198 + test 0 = $(git count-objects | sed "s/ .*//") &&
199 test_path_is_missing $BLOB_FILE
200 )
201 '
t/t6006-rev-list-format.sh
+1 -1
@@ -493,7 +493,7 @@ test_expect_success 'empty email' '
493 test_tick &&
494 C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&
495 A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) &&
496 - verbose test "$A" = "$GIT_AUTHOR_NAME,,Thu Apr 7 15:14:13 2005 -0700"
496 + test "$A" = "$GIT_AUTHOR_NAME,,Thu Apr 7 15:14:13 2005 -0700"
497 '
498
499 test_expect_success 'del LF before empty (1)' '
t/t6501-freshen-objects.sh
+1 -1
@@ -152,7 +152,7 @@ test_expect_success 'do not complain about existing broken links (commit)' '
152 EOF
153 commit=$(git hash-object -t commit -w broken-commit) &&
154 git gc --no-cruft -q 2>stderr &&
155 - verbose git cat-file -e $commit &&
155 + git cat-file -e $commit &&
156 test_must_be_empty stderr
157 '
158
t/t7001-mv.sh
+1 -1
@@ -192,7 +192,7 @@ test_expect_success "Michael Cassar's test case" '
192
193 T=$(git write-tree) &&
194 git ls-tree -r $T >out &&
195 - verbose grep partA/outline.txt out
195 + grep partA/outline.txt out
196 '
197
198 rm -fr papers partA path?
t/t7300-clean.sh
+2 -2
@@ -120,7 +120,7 @@ test_expect_success 'git clean with relative prefix' '
120 grep part3 |
121 sed -n -e "s|^Would remove ||p"
122 ) &&
123 - verbose test "$would_clean" = ../src/part3.c
123 + test "$would_clean" = ../src/part3.c
124 '
125
126 test_expect_success 'git clean with absolute path' '
@@ -133,7 +133,7 @@ test_expect_success 'git clean with absolute path' '
133 grep part3 |
134 sed -n -e "s|^Would remove ||p"
135 ) &&
136 - verbose test "$would_clean" = ../src/part3.c
136 + test "$would_clean" = ../src/part3.c
137 '
138
139 test_expect_success 'git clean with out of work tree relative path' '
t/t9902-completion.sh
+15 -15
@@ -405,40 +405,40 @@ test_expect_success '__gitdir - remote as argument' '
405
406 test_expect_success '__git_dequote - plain unquoted word' '
407 __git_dequote unquoted-word &&
408 - verbose test unquoted-word = "$dequoted_word"
408 + test unquoted-word = "$dequoted_word"
409 '
410
411 # input: b\a\c\k\'\\\"s\l\a\s\h\es
412 # expected: back'\"slashes
413 test_expect_success '__git_dequote - backslash escaped' '
414 __git_dequote "b\a\c\k\\'\''\\\\\\\"s\l\a\s\h\es" &&
415 - verbose test "back'\''\\\"slashes" = "$dequoted_word"
415 + test "back'\''\\\"slashes" = "$dequoted_word"
416 '
417
418 # input: sin'gle\' '"quo'ted
419 # expected: single\ "quoted
420 test_expect_success '__git_dequote - single quoted' '
421 __git_dequote "'"sin'gle\\\\' '\\\"quo'ted"'" &&
422 - verbose test '\''single\ "quoted'\'' = "$dequoted_word"
422 + test '\''single\ "quoted'\'' = "$dequoted_word"
423 '
424
425 # input: dou"ble\\" "\"\quot"ed
426 # expected: double\ "\quoted
427 test_expect_success '__git_dequote - double quoted' '
428 __git_dequote '\''dou"ble\\" "\"\quot"ed'\'' &&
429 - verbose test '\''double\ "\quoted'\'' = "$dequoted_word"
429 + test '\''double\ "\quoted'\'' = "$dequoted_word"
430 '
431
432 # input: 'open single quote
433 test_expect_success '__git_dequote - open single quote' '
434 __git_dequote "'\''open single quote" &&
435 - verbose test "open single quote" = "$dequoted_word"
435 + test "open single quote" = "$dequoted_word"
436 '
437
438 # input: "open double quote
439 test_expect_success '__git_dequote - open double quote' '
440 __git_dequote "\"open double quote" &&
441 - verbose test "open double quote" = "$dequoted_word"
441 + test "open double quote" = "$dequoted_word"
442 '
443
444
@@ -616,7 +616,7 @@ test_expect_success '__git_is_configured_remote' '
616 test_when_finished "git remote remove remote_2" &&
617 git remote add remote_2 git://remote_2 &&
618 (
619 - verbose __git_is_configured_remote remote_2 &&
619 + __git_is_configured_remote remote_2 &&
620 test_must_fail __git_is_configured_remote non-existent
621 )
622 '
@@ -2596,30 +2596,30 @@ test_expect_success 'options with value' '
2596 test_expect_success 'sourcing the completion script clears cached commands' '
2597 (
2598 __git_compute_all_commands &&
2599 - verbose test -n "$__git_all_commands" &&
2599 + test -n "$__git_all_commands" &&
2600 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2601 - verbose test -z "$__git_all_commands"
2601 + test -z "$__git_all_commands"
2602 )
2603 '
2604
2605 test_expect_success 'sourcing the completion script clears cached merge strategies' '
2606 (
2607 __git_compute_merge_strategies &&
2608 - verbose test -n "$__git_merge_strategies" &&
2608 + test -n "$__git_merge_strategies" &&
2609 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2610 - verbose test -z "$__git_merge_strategies"
2610 + test -z "$__git_merge_strategies"
2611 )
2612 '
2613
2614 test_expect_success 'sourcing the completion script clears cached --options' '
2615 (
2616 __gitcomp_builtin checkout &&
2617 - verbose test -n "$__gitcomp_builtin_checkout" &&
2617 + test -n "$__gitcomp_builtin_checkout" &&
2618 __gitcomp_builtin notes_edit &&
2619 - verbose test -n "$__gitcomp_builtin_notes_edit" &&
2619 + test -n "$__gitcomp_builtin_notes_edit" &&
2620 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2621 - verbose test -z "$__gitcomp_builtin_checkout" &&
2622 - verbose test -z "$__gitcomp_builtin_notes_edit"
2621 + test -z "$__gitcomp_builtin_checkout" &&
2622 + test -z "$__gitcomp_builtin_notes_edit"
2623 )
2624 '
2625
t/test-lib-functions.sh
-9
@@ -1227,15 +1227,6 @@ test_i18ngrep () {
1227 return 1
1228 }
1229
1230 -# Call any command "$@" but be more verbose about its
1231 -# failure. This is handy for commands like "test" which do
1232 -# not output anything when they fail.
1233 -verbose () {
1234 - "$@" && return 0
1235 - echo >&4 "command failed: $(git rev-parse --sq-quote "$@")"
1236 - return 1
1237 -}
1238 -
1230 # Check if the file expected to be empty is indeed empty, and barfs
1231 # otherwise.
1232