t6300: introduce test_date() helper
This moves the setup of the "expected" file inside the test case. The helper function has the advantage that we can use SQ in the file content without needing to escape the quotes. Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
John Keeping committed
Sep 3, 2015 at 22:48 UTC
f95cecf43335dd8e80e954c2f998dc0e8b0dd070
1 file changed
+40
-52
t/t6300-for-each-ref.sh
+40
-52
@@ -146,85 +146,73 @@ test_expect_success 'Check invalid format specifiers are errors' '
146
test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
147
'
148
149
-cat >expected <<\EOF
150
-'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200'
151
-'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200'
152
-EOF
149
+test_date () {
150
+ f=$1 &&
151
+ committer_date=$2 &&
152
+ author_date=$3 &&
153
+ tagger_date=$4 &&
154
+ cat >expected <<-EOF &&
155
+ 'refs/heads/master' '$committer_date' '$author_date'
156
+ 'refs/tags/testtag' '$tagger_date'
157
+ EOF
158
+ (
159
+ git for-each-ref --shell \
160
+ --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
161
+ refs/heads &&
162
+ git for-each-ref --shell \
163
+ --format="%(refname) %(taggerdate${f:+:$f})" \
164
+ refs/tags
165
+ ) >actual &&
166
+ test_cmp expected actual
167
+}
168
169
test_expect_success 'Check unformatted date fields output' '
155
- (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads &&
156
- git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual &&
157
- test_cmp expected actual
170
+ test_date "" \
171
+ "Mon Jul 3 17:18:43 2006 +0200" \
172
+ "Mon Jul 3 17:18:44 2006 +0200" \
173
+ "Mon Jul 3 17:18:45 2006 +0200"
174
'
175
176
test_expect_success 'Check format "default" formatted date fields output' '
161
- f=default &&
162
- (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
163
- git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
164
- test_cmp expected actual
177
+ test_date default \
178
+ "Mon Jul 3 17:18:43 2006 +0200" \
179
+ "Mon Jul 3 17:18:44 2006 +0200" \
180
+ "Mon Jul 3 17:18:45 2006 +0200"
181
'
182
183
# Don't know how to do relative check because I can't know when this script
184
# is going to be run and can't fake the current time to git, and hence can't
185
# provide expected output. Instead, I'll just make sure that "relative"
186
# doesn't exit in error
171
-#
172
-#cat >expected <<\EOF
173
-#
174
-#EOF
175
-#
187
test_expect_success 'Check format "relative" date fields output' '
188
f=relative &&
189
(git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
190
git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
191
'
192
182
-cat >expected <<\EOF
183
-'refs/heads/master' '2006-07-03' '2006-07-03'
184
-'refs/tags/testtag' '2006-07-03'
185
-EOF
186
-
193
test_expect_success 'Check format "short" date fields output' '
188
- f=short &&
189
- (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
190
- git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
191
- test_cmp expected actual
194
+ test_date short 2006-07-03 2006-07-03 2006-07-03
195
'
196
194
-cat >expected <<\EOF
195
-'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006'
196
-'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006'
197
-EOF
198
-
197
test_expect_success 'Check format "local" date fields output' '
200
- f=local &&
201
- (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
202
- git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
203
- test_cmp expected actual
198
+ test_date local \
199
+ "Mon Jul 3 15:18:43 2006" \
200
+ "Mon Jul 3 15:18:44 2006" \
201
+ "Mon Jul 3 15:18:45 2006"
202
'
203
206
-cat >expected <<\EOF
207
-'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200'
208
-'refs/tags/testtag' '2006-07-03 17:18:45 +0200'
209
-EOF
210
-
204
test_expect_success 'Check format "iso8601" date fields output' '
212
- f=iso8601 &&
213
- (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
214
- git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
215
- test_cmp expected actual
205
+ test_date iso8601 \
206
+ "2006-07-03 17:18:43 +0200" \
207
+ "2006-07-03 17:18:44 +0200" \
208
+ "2006-07-03 17:18:45 +0200"
209
'
210
218
-cat >expected <<\EOF
219
-'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200'
220
-'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200'
221
-EOF
222
-
211
test_expect_success 'Check format "rfc2822" date fields output' '
224
- f=rfc2822 &&
225
- (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
226
- git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
227
- test_cmp expected actual
212
+ test_date rfc2822 \
213
+ "Mon, 3 Jul 2006 17:18:43 +0200" \
214
+ "Mon, 3 Jul 2006 17:18:44 +0200" \
215
+ "Mon, 3 Jul 2006 17:18:45 +0200"
216
'
217
218
test_expect_success 'Check format of strftime date fields' '