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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Oct 10, 2014 at 02:11 UTC
8ad16524183baf196d1db82b99ef52d05ca438e9
2 files changed
+17
-8
t/t5304-prune.sh
+8
-8
@@ -13,7 +13,7 @@ add_blob() {
13
before=$(git count-objects | sed "s/ .*//") &&
14
BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
15
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/ .*//") &&
17
test_path_is_file $BLOB_FILE &&
18
test-chmtime =+0 $BLOB_FILE
19
}
@@ -45,11 +45,11 @@ test_expect_success 'prune --expire' '
45
46
add_blob &&
47
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/ .*//") &&
49
test_path_is_file $BLOB_FILE &&
50
test-chmtime =-86500 $BLOB_FILE &&
51
git prune --expire 1.day &&
52
- test $before = $(git count-objects | sed "s/ .*//") &&
52
+ verbose test $before = $(git count-objects | sed "s/ .*//") &&
53
test_path_is_missing $BLOB_FILE
54
55
'
@@ -59,11 +59,11 @@ test_expect_success 'gc: implicit prune --expire' '
59
add_blob &&
60
test-chmtime =-$((2*$week-30)) $BLOB_FILE &&
61
git gc &&
62
- test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
62
+ verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
63
test_path_is_file $BLOB_FILE &&
64
test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
65
git gc &&
66
- test $before = $(git count-objects | sed "s/ .*//") &&
66
+ verbose test $before = $(git count-objects | sed "s/ .*//") &&
67
test_path_is_missing $BLOB_FILE
68
69
'
@@ -144,7 +144,7 @@ test_expect_success 'gc --no-prune' '
144
test-chmtime =-$((5001*$day)) $BLOB_FILE &&
145
git config gc.pruneExpire 2.days.ago &&
146
git gc --no-prune &&
147
- test 1 = $(git count-objects | sed "s/ .*//") &&
147
+ verbose test 1 = $(git count-objects | sed "s/ .*//") &&
148
test_path_is_file $BLOB_FILE
149
150
'
@@ -209,10 +209,10 @@ test_expect_success 'gc: prune old objects after local clone' '
209
git clone --no-hardlinks . aclone &&
210
(
211
cd aclone &&
212
- test 1 = $(git count-objects | sed "s/ .*//") &&
212
+ verbose test 1 = $(git count-objects | sed "s/ .*//") &&
213
test_path_is_file $BLOB_FILE &&
214
git gc --prune &&
215
- test 0 = $(git count-objects | sed "s/ .*//") &&
215
+ verbose test 0 = $(git count-objects | sed "s/ .*//") &&
216
test_path_is_missing $BLOB_FILE
217
)
218
'
t/test-lib-functions.sh
+9
@@ -634,6 +634,15 @@ test_cmp_bin() {
634
cmp "$@"
635
}
636
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
+
646
# Check if the file expected to be empty is indeed empty, and barfs
647
# otherwise.
648