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 committedMay 8, 2023 at 15:04 UTC8ddfce7144bc965b030e0359f11b7282990e72fb
12 files changed+57-66
t/t0020-crlf.sh
+19-19
index 35cc8c3b39..81946e87cc 100755--- a/t/t0020-crlf.sh+++ b/t/t0020-crlf.sh@@ -125,7 +125,7 @@ test_expect_success 'update with autocrlf=input' ' munge_cr append dir/two && git update-index -- one dir/two && differs=$(git diff-index --cached HEAD) &&- verbose test -z "$differs"+ test -z "$differs" '@@ -138,7 +138,7 @@ test_expect_success 'update with autocrlf=true' ' munge_cr append dir/two && git update-index -- one dir/two && differs=$(git diff-index --cached HEAD) &&- verbose test -z "$differs"+ test -z "$differs" '@@ -153,7 +153,7 @@ test_expect_success 'checkout with autocrlf=true' ' test "$one" = $(git hash-object --stdin <one) && test "$two" = $(git hash-object --stdin <dir/two) && differs=$(git diff-index --cached HEAD) &&- verbose test -z "$differs"+ test -z "$differs" ' test_expect_success 'checkout with autocrlf=input' '@@ -167,7 +167,7 @@ test_expect_success 'checkout with autocrlf=input' ' test "$one" = $(git hash-object --stdin <one) && test "$two" = $(git hash-object --stdin <dir/two) && differs=$(git diff-index --cached HEAD) &&- verbose test -z "$differs"+ test -z "$differs" ' test_expect_success 'apply patch (autocrlf=input)' '@@ -177,7 +177,7 @@ test_expect_success 'apply patch (autocrlf=input)' ' git read-tree --reset -u HEAD && git apply patch.file &&- verbose test "$patched" = "$(git hash-object --stdin <one)"+ test "$patched" = "$(git hash-object --stdin <one)" ' test_expect_success 'apply patch --cached (autocrlf=input)' '@@ -187,7 +187,7 @@ test_expect_success 'apply patch --cached (autocrlf=input)' ' git read-tree --reset -u HEAD && git apply --cached patch.file &&- verbose test "$patched" = $(git rev-parse :one)+ test "$patched" = $(git rev-parse :one) ' test_expect_success 'apply patch --index (autocrlf=input)' '@@ -197,8 +197,8 @@ test_expect_success 'apply patch --index (autocrlf=input)' ' git read-tree --reset -u HEAD && git apply --index patch.file &&- verbose test "$patched" = $(git rev-parse :one) &&- verbose test "$patched" = $(git hash-object --stdin <one)+ test "$patched" = $(git rev-parse :one) &&+ test "$patched" = $(git hash-object --stdin <one) ' test_expect_success 'apply patch (autocrlf=true)' '@@ -208,7 +208,7 @@ test_expect_success 'apply patch (autocrlf=true)' ' git read-tree --reset -u HEAD && git apply patch.file &&- verbose test "$patched" = "$(remove_cr <one | git hash-object --stdin)"+ test "$patched" = "$(remove_cr <one | git hash-object --stdin)" ' test_expect_success 'apply patch --cached (autocrlf=true)' '@@ -218,7 +218,7 @@ test_expect_success 'apply patch --cached (autocrlf=true)' ' git read-tree --reset -u HEAD && git apply --cached patch.file &&- verbose test "$patched" = $(git rev-parse :one)+ test "$patched" = $(git rev-parse :one) ' test_expect_success 'apply patch --index (autocrlf=true)' '@@ -228,8 +228,8 @@ test_expect_success 'apply patch --index (autocrlf=true)' ' git read-tree --reset -u HEAD && git apply --index patch.file &&- verbose test "$patched" = $(git rev-parse :one) &&- verbose test "$patched" = "$(remove_cr <one | git hash-object --stdin)"+ test "$patched" = $(git rev-parse :one) &&+ test "$patched" = "$(remove_cr <one | git hash-object --stdin)" ' test_expect_success '.gitattributes says two is binary' '@@ -240,7 +240,7 @@ test_expect_success '.gitattributes says two is binary' ' git read-tree --reset -u HEAD && ! has_cr dir/two &&- verbose has_cr one &&+ has_cr one && ! has_cr three '@@ -259,8 +259,8 @@ test_expect_success '.gitattributes says two and three are text' ' echo "t* crlf" >.gitattributes && git read-tree --reset -u HEAD &&- verbose has_cr dir/two &&- verbose has_cr three+ has_cr dir/two &&+ has_cr three ' test_expect_success 'in-tree .gitattributes (1)' '@@ -273,7 +273,7 @@ test_expect_success 'in-tree .gitattributes (1)' ' git read-tree --reset -u HEAD && ! has_cr one &&- verbose has_cr three+ has_cr three ' test_expect_success 'in-tree .gitattributes (2)' '@@ -283,7 +283,7 @@ test_expect_success 'in-tree .gitattributes (2)' ' git checkout-index -f -q -u -a && ! has_cr one &&- verbose has_cr three+ has_cr three ' test_expect_success 'in-tree .gitattributes (3)' '@@ -294,7 +294,7 @@ test_expect_success 'in-tree .gitattributes (3)' ' git checkout-index -u one dir/two three && ! has_cr one &&- verbose has_cr three+ has_cr three ' test_expect_success 'in-tree .gitattributes (4)' '@@ -305,7 +305,7 @@ test_expect_success 'in-tree .gitattributes (4)' ' git checkout-index -u .gitattributes && ! has_cr one &&- verbose has_cr three+ has_cr three ' test_expect_success 'checkout with existing .gitattributes' '
t/t1301-shared-repo.sh
+2-2
index 1b6437ec07..ae5cd3f5a0 100755--- a/t/t1301-shared-repo.sh+++ b/t/t1301-shared-repo.sh@@ -89,7 +89,7 @@ do rm -f .git/info/refs && git update-server-info && actual="$(test_modebits .git/info/refs)" &&- verbose test "x$actual" = "x-$y"+ test "x$actual" = "x-$y" '@@ -99,7 +99,7 @@ do rm -f .git/info/refs && git update-server-info && actual="$(test_modebits .git/info/refs)" &&- verbose test "x$actual" = "x-$x"+ test "x$actual" = "x-$x" '
t/t3427-rebase-subtree.sh
+6-6
index 48b76f8232..1b3e97c875 100755--- a/t/t3427-rebase-subtree.sh+++ b/t/t3427-rebase-subtree.sh@@ -74,9 +74,9 @@ test_expect_success 'Rebase -Xsubtree --empty=ask --onto commit' ' test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --onto files-main main && : first pick results in no changes && git rebase --skip &&- verbose test "$(commit_message HEAD~2)" = "topic_4" &&- verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&- verbose test "$(commit_message HEAD)" = "Empty commit"+ test "$(commit_message HEAD~2)" = "topic_4" &&+ test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&+ test "$(commit_message HEAD)" = "Empty commit" ' 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' test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --rebase-merges --onto files-main --root && : first pick results in no changes && git rebase --skip &&- verbose test "$(commit_message HEAD~2)" = "topic_4" &&- verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&- verbose test "$(commit_message HEAD)" = "Empty commit"+ test "$(commit_message HEAD~2)" = "topic_4" &&+ test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&+ test "$(commit_message HEAD)" = "Empty commit" ' test_done
index c975eb54d2..0ef7b78457 100755--- a/t/t7300-clean.sh+++ b/t/t7300-clean.sh@@ -120,7 +120,7 @@ test_expect_success 'git clean with relative prefix' ' grep part3 | sed -n -e "s|^Would remove ||p" ) &&- verbose test "$would_clean" = ../src/part3.c+ test "$would_clean" = ../src/part3.c ' test_expect_success 'git clean with absolute path' '@@ -133,7 +133,7 @@ test_expect_success 'git clean with absolute path' ' grep part3 | sed -n -e "s|^Would remove ||p" ) &&- verbose test "$would_clean" = ../src/part3.c+ test "$would_clean" = ../src/part3.c ' test_expect_success 'git clean with out of work tree relative path' '
t/t9902-completion.sh
+15-15
index d6c0478d98..8835e16e81 100755--- a/t/t9902-completion.sh+++ b/t/t9902-completion.sh@@ -405,40 +405,40 @@ test_expect_success '__gitdir - remote as argument' ' test_expect_success '__git_dequote - plain unquoted word' ' __git_dequote unquoted-word &&- verbose test unquoted-word = "$dequoted_word"+ test unquoted-word = "$dequoted_word" ' # input: b\a\c\k\'\\\"s\l\a\s\h\es # expected: back'\"slashes test_expect_success '__git_dequote - backslash escaped' ' __git_dequote "b\a\c\k\\'\''\\\\\\\"s\l\a\s\h\es" &&- verbose test "back'\''\\\"slashes" = "$dequoted_word"+ test "back'\''\\\"slashes" = "$dequoted_word" ' # input: sin'gle\' '"quo'ted # expected: single\ "quoted test_expect_success '__git_dequote - single quoted' ' __git_dequote "'"sin'gle\\\\' '\\\"quo'ted"'" &&- verbose test '\''single\ "quoted'\'' = "$dequoted_word"+ test '\''single\ "quoted'\'' = "$dequoted_word" ' # input: dou"ble\\" "\"\quot"ed # expected: double\ "\quoted test_expect_success '__git_dequote - double quoted' ' __git_dequote '\''dou"ble\\" "\"\quot"ed'\'' &&- verbose test '\''double\ "\quoted'\'' = "$dequoted_word"+ test '\''double\ "\quoted'\'' = "$dequoted_word" ' # input: 'open single quote test_expect_success '__git_dequote - open single quote' ' __git_dequote "'\''open single quote" &&- verbose test "open single quote" = "$dequoted_word"+ test "open single quote" = "$dequoted_word" ' # input: "open double quote test_expect_success '__git_dequote - open double quote' ' __git_dequote "\"open double quote" &&- verbose test "open double quote" = "$dequoted_word"+ test "open double quote" = "$dequoted_word" '@@ -616,7 +616,7 @@ test_expect_success '__git_is_configured_remote' ' test_when_finished "git remote remove remote_2" && git remote add remote_2 git://remote_2 && (- verbose __git_is_configured_remote remote_2 &&+ __git_is_configured_remote remote_2 && test_must_fail __git_is_configured_remote non-existent ) '@@ -2596,30 +2596,30 @@ test_expect_success 'options with value' ' test_expect_success 'sourcing the completion script clears cached commands' ' ( __git_compute_all_commands &&- verbose test -n "$__git_all_commands" &&+ test -n "$__git_all_commands" && . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&- verbose test -z "$__git_all_commands"+ test -z "$__git_all_commands" ) ' test_expect_success 'sourcing the completion script clears cached merge strategies' ' ( __git_compute_merge_strategies &&- verbose test -n "$__git_merge_strategies" &&+ test -n "$__git_merge_strategies" && . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&- verbose test -z "$__git_merge_strategies"+ test -z "$__git_merge_strategies" ) ' test_expect_success 'sourcing the completion script clears cached --options' ' ( __gitcomp_builtin checkout &&- verbose test -n "$__gitcomp_builtin_checkout" &&+ test -n "$__gitcomp_builtin_checkout" && __gitcomp_builtin notes_edit &&- verbose test -n "$__gitcomp_builtin_notes_edit" &&+ test -n "$__gitcomp_builtin_notes_edit" && . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&- verbose test -z "$__gitcomp_builtin_checkout" &&- verbose test -z "$__gitcomp_builtin_notes_edit"+ test -z "$__gitcomp_builtin_checkout" &&+ test -z "$__gitcomp_builtin_notes_edit" ) '
t/test-lib-functions.sh
-9
index 999d46fafe..6e19ebc922 100644--- a/t/test-lib-functions.sh+++ b/t/test-lib-functions.sh@@ -1227,15 +1227,6 @@ test_i18ngrep () { return 1 }-# Call any command "$@" but be more verbose about its-# failure. This is handy for commands like "test" which do-# not output anything when they fail.-verbose () {- "$@" && return 0- echo >&4 "command failed: $(git rev-parse --sq-quote "$@")"- return 1-}- # Check if the file expected to be empty is indeed empty, and barfs # otherwise.