Skip to content

Commit f95cecf

Browse files
johnkeepinggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 547ed71 commit f95cecf

File tree

1 file changed

+40
-52
lines changed

1 file changed

+40
-52
lines changed

t/t6300-for-each-ref.sh

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -146,85 +146,73 @@ test_expect_success 'Check invalid format specifiers are errors' '
146146
test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
147147
'
148148

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+
}
153168

154169
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"
158174
'
159175

160176
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"
165181
'
166182

167183
# Don't know how to do relative check because I can't know when this script
168184
# is going to be run and can't fake the current time to git, and hence can't
169185
# provide expected output. Instead, I'll just make sure that "relative"
170186
# doesn't exit in error
171-
#
172-
#cat >expected <<\EOF
173-
#
174-
#EOF
175-
#
176187
test_expect_success 'Check format "relative" date fields output' '
177188
f=relative &&
178189
(git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
179190
git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
180191
'
181192

182-
cat >expected <<\EOF
183-
'refs/heads/master' '2006-07-03' '2006-07-03'
184-
'refs/tags/testtag' '2006-07-03'
185-
EOF
186-
187193
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
192195
'
193196

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-
199197
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"
204202
'
205203

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-
211204
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"
216209
'
217210

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-
223211
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"
228216
'
229217

230218
test_expect_success 'Check format of strftime date fields' '

0 commit comments

Comments
 (0)