Skip to content

Commit 8ad1652

Browse files
peffgitster
authored andcommitted
t5304: use helper to report failure of "test foo = bar"
For small outputs, we sometimes use: test "$(some_cmd)" = "something we expect" instead of a full test_cmp. The downside of this is that when it fails, there is no output at all from the script. Let's introduce a small helper to make tests easier to debug. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1dd90b commit 8ad1652

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

t/t5304-prune.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ add_blob() {
1313
before=$(git count-objects | sed "s/ .*//") &&
1414
BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
1515
BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
16-
test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
16+
verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
1717
test_path_is_file $BLOB_FILE &&
1818
test-chmtime =+0 $BLOB_FILE
1919
}
@@ -45,11 +45,11 @@ test_expect_success 'prune --expire' '
4545
4646
add_blob &&
4747
git prune --expire=1.hour.ago &&
48-
test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
48+
verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
4949
test_path_is_file $BLOB_FILE &&
5050
test-chmtime =-86500 $BLOB_FILE &&
5151
git prune --expire 1.day &&
52-
test $before = $(git count-objects | sed "s/ .*//") &&
52+
verbose test $before = $(git count-objects | sed "s/ .*//") &&
5353
test_path_is_missing $BLOB_FILE
5454
5555
'
@@ -59,11 +59,11 @@ test_expect_success 'gc: implicit prune --expire' '
5959
add_blob &&
6060
test-chmtime =-$((2*$week-30)) $BLOB_FILE &&
6161
git gc &&
62-
test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
62+
verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
6363
test_path_is_file $BLOB_FILE &&
6464
test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
6565
git gc &&
66-
test $before = $(git count-objects | sed "s/ .*//") &&
66+
verbose test $before = $(git count-objects | sed "s/ .*//") &&
6767
test_path_is_missing $BLOB_FILE
6868
6969
'
@@ -144,7 +144,7 @@ test_expect_success 'gc --no-prune' '
144144
test-chmtime =-$((5001*$day)) $BLOB_FILE &&
145145
git config gc.pruneExpire 2.days.ago &&
146146
git gc --no-prune &&
147-
test 1 = $(git count-objects | sed "s/ .*//") &&
147+
verbose test 1 = $(git count-objects | sed "s/ .*//") &&
148148
test_path_is_file $BLOB_FILE
149149
150150
'
@@ -209,10 +209,10 @@ test_expect_success 'gc: prune old objects after local clone' '
209209
git clone --no-hardlinks . aclone &&
210210
(
211211
cd aclone &&
212-
test 1 = $(git count-objects | sed "s/ .*//") &&
212+
verbose test 1 = $(git count-objects | sed "s/ .*//") &&
213213
test_path_is_file $BLOB_FILE &&
214214
git gc --prune &&
215-
test 0 = $(git count-objects | sed "s/ .*//") &&
215+
verbose test 0 = $(git count-objects | sed "s/ .*//") &&
216216
test_path_is_missing $BLOB_FILE
217217
)
218218
'

t/test-lib-functions.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,15 @@ test_cmp_bin() {
634634
cmp "$@"
635635
}
636636

637+
# Call any command "$@" but be more verbose about its
638+
# failure. This is handy for commands like "test" which do
639+
# not output anything when they fail.
640+
verbose () {
641+
"$@" && return 0
642+
echo >&2 "command failed: $(git rev-parse --sq-quote "$@")"
643+
return 1
644+
}
645+
637646
# Check if the file expected to be empty is indeed empty, and barfs
638647
# otherwise.
639648

0 commit comments

Comments
 (0)