improve for-each-ref test script
Previously, we did a sanity check by doing for-each-ref using each possible format atom. However, we never checked the actual output produced by that atom, which recently let an obvious bug go undetected for some time. While we're at it, also clean up a few '!' into test_must_fail. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jun 26, 2008 at 04:08 UTC
d2bf48d2ad653ee8a052aa460ca5c6ef29dce41d
1 file changed
+70
-17
t/t6300-for-each-ref.sh
+70
-17
@@ -26,25 +26,78 @@ test_expect_success 'Create sample commit with known timestamp' '
26
git tag -a -m "Tagging at $datestamp" testtag
27
'
28
29
-test_expect_success 'Check atom names are valid' '
30
- bad=
31
- for token in \
32
- refname objecttype objectsize objectname tree parent \
33
- numparent object type author authorname authoremail \
34
- authordate committer committername committeremail \
35
- committerdate tag tagger taggername taggeremail \
36
- taggerdate creator creatordate subject body contents
37
- do
38
- git for-each-ref --format="$token=%($token)" refs/heads || {
39
- bad=$token
40
- break
41
- }
42
- done
43
- test -z "$bad"
29
+test_atom() {
30
+ case "$1" in
31
+ head) ref=refs/heads/master ;;
32
+ tag) ref=refs/tags/testtag ;;
33
+ esac
34
+ printf '%s\n' "$3" >expected
35
+ test_expect_${4:-success} "basic atom: $1 $2" "
36
+ git for-each-ref --format='%($2)' $ref >actual &&
37
+ test_cmp expected actual
38
+ "
39
+}
40
+
41
+test_atom head refname refs/heads/master
42
+test_atom head objecttype commit
43
+test_atom head objectsize 171
44
+test_atom head objectname 67a36f10722846e891fbada1ba48ed035de75581
45
+test_atom head tree 0e51c00fcb93dffc755546f27593d511e1bdb46f
46
+test_atom head parent ''
47
+test_atom head numparent 0
48
+test_atom head object ''
49
+test_atom head type ''
50
+test_atom head author 'A U Thor <author@example.com> 1151939924 +0200'
51
+test_atom head authorname 'A U Thor'
52
+test_atom head authoremail '<author@example.com>'
53
+test_atom head authordate 'Mon Jul 3 17:18:44 2006 +0200'
54
+test_atom head committer 'C O Mitter <committer@example.com> 1151939923 +0200'
55
+test_atom head committername 'C O Mitter'
56
+test_atom head committeremail '<committer@example.com>'
57
+test_atom head committerdate 'Mon Jul 3 17:18:43 2006 +0200'
58
+test_atom head tag ''
59
+test_atom head tagger ''
60
+test_atom head taggername ''
61
+test_atom head taggeremail ''
62
+test_atom head taggerdate ''
63
+test_atom head creator 'C O Mitter <committer@example.com> 1151939923 +0200'
64
+test_atom head creatordate 'Mon Jul 3 17:18:43 2006 +0200'
65
+test_atom head subject 'Initial'
66
+test_atom head body ''
67
+test_atom head contents 'Initial
68
+'
69
+
70
+test_atom tag refname refs/tags/testtag
71
+test_atom tag objecttype tag
72
+test_atom tag objectsize 154
73
+test_atom tag objectname 98b46b1d36e5b07909de1b3886224e3e81e87322
74
+test_atom tag tree ''
75
+test_atom tag parent ''
76
+test_atom tag numparent ''
77
+test_atom tag object '67a36f10722846e891fbada1ba48ed035de75581'
78
+test_atom tag type 'commit'
79
+test_atom tag author ''
80
+test_atom tag authorname ''
81
+test_atom tag authoremail ''
82
+test_atom tag authordate ''
83
+test_atom tag committer ''
84
+test_atom tag committername ''
85
+test_atom tag committeremail ''
86
+test_atom tag committerdate ''
87
+test_atom tag tag 'testtag'
88
+test_atom tag tagger 'C O Mitter <committer@example.com> 1151939925 +0200'
89
+test_atom tag taggername 'C O Mitter'
90
+test_atom tag taggeremail '<committer@example.com>'
91
+test_atom tag taggerdate 'Mon Jul 3 17:18:45 2006 +0200'
92
+test_atom tag creator 'C O Mitter <committer@example.com> 1151939925 +0200'
93
+test_atom tag creatordate 'Mon Jul 3 17:18:45 2006 +0200'
94
+test_atom tag subject 'Tagging at 1151939927'
95
+test_atom tag body ''
96
+test_atom tag contents 'Tagging at 1151939927
97
'
98
99
test_expect_success 'Check invalid atoms names are errors' '
47
- ! git-for-each-ref --format="%(INVALID)" refs/heads
100
+ test_must_fail git-for-each-ref --format="%(INVALID)" refs/heads
101
'
102
103
test_expect_success 'Check format specifiers are ignored in naming date atoms' '
@@ -64,7 +117,7 @@ test_expect_success 'Check valid format specifiers for date fields' '
117
'
118
119
test_expect_success 'Check invalid format specifiers are errors' '
67
- ! git-for-each-ref --format="%(authordate:INVALID)" refs/heads
120
+ test_must_fail git-for-each-ref --format="%(authordate:INVALID)" refs/heads
121
'
122
123
cat >expected <<\EOF