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>
This commit is contained in:
John Keeping 2015-09-03 22:48:56 +01:00 committed by Junio C Hamano
parent 547ed71636
commit f95cecf433

View File

@ -146,85 +146,73 @@ test_expect_success 'Check invalid format specifiers are errors' '
test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
' '
cat >expected <<\EOF test_date () {
'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200' f=$1 &&
'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200' committer_date=$2 &&
EOF author_date=$3 &&
tagger_date=$4 &&
cat >expected <<-EOF &&
'refs/heads/master' '$committer_date' '$author_date'
'refs/tags/testtag' '$tagger_date'
EOF
(
git for-each-ref --shell \
--format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
refs/heads &&
git for-each-ref --shell \
--format="%(refname) %(taggerdate${f:+:$f})" \
refs/tags
) >actual &&
test_cmp expected actual
}
test_expect_success 'Check unformatted date fields output' ' test_expect_success 'Check unformatted date fields output' '
(git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads && test_date "" \
git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual && "Mon Jul 3 17:18:43 2006 +0200" \
test_cmp expected actual "Mon Jul 3 17:18:44 2006 +0200" \
"Mon Jul 3 17:18:45 2006 +0200"
' '
test_expect_success 'Check format "default" formatted date fields output' ' test_expect_success 'Check format "default" formatted date fields output' '
f=default && test_date default \
(git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && "Mon Jul 3 17:18:43 2006 +0200" \
git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && "Mon Jul 3 17:18:44 2006 +0200" \
test_cmp expected actual "Mon Jul 3 17:18:45 2006 +0200"
' '
# Don't know how to do relative check because I can't know when this script # Don't know how to do relative check because I can't know when this script
# is going to be run and can't fake the current time to git, and hence can't # is going to be run and can't fake the current time to git, and hence can't
# provide expected output. Instead, I'll just make sure that "relative" # provide expected output. Instead, I'll just make sure that "relative"
# doesn't exit in error # doesn't exit in error
#
#cat >expected <<\EOF
#
#EOF
#
test_expect_success 'Check format "relative" date fields output' ' test_expect_success 'Check format "relative" date fields output' '
f=relative && f=relative &&
(git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
' '
cat >expected <<\EOF
'refs/heads/master' '2006-07-03' '2006-07-03'
'refs/tags/testtag' '2006-07-03'
EOF
test_expect_success 'Check format "short" date fields output' ' test_expect_success 'Check format "short" date fields output' '
f=short && test_date short 2006-07-03 2006-07-03 2006-07-03
(git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
test_cmp expected actual
' '
cat >expected <<\EOF
'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006'
'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006'
EOF
test_expect_success 'Check format "local" date fields output' ' test_expect_success 'Check format "local" date fields output' '
f=local && test_date local \
(git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && "Mon Jul 3 15:18:43 2006" \
git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && "Mon Jul 3 15:18:44 2006" \
test_cmp expected actual "Mon Jul 3 15:18:45 2006"
' '
cat >expected <<\EOF
'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200'
'refs/tags/testtag' '2006-07-03 17:18:45 +0200'
EOF
test_expect_success 'Check format "iso8601" date fields output' ' test_expect_success 'Check format "iso8601" date fields output' '
f=iso8601 && test_date iso8601 \
(git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && "2006-07-03 17:18:43 +0200" \
git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && "2006-07-03 17:18:44 +0200" \
test_cmp expected actual "2006-07-03 17:18:45 +0200"
' '
cat >expected <<\EOF
'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200'
'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200'
EOF
test_expect_success 'Check format "rfc2822" date fields output' ' test_expect_success 'Check format "rfc2822" date fields output' '
f=rfc2822 && test_date rfc2822 \
(git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && "Mon, 3 Jul 2006 17:18:43 +0200" \
git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && "Mon, 3 Jul 2006 17:18:44 +0200" \
test_cmp expected actual "Mon, 3 Jul 2006 17:18:45 +0200"
' '
test_expect_success 'Check format of strftime date fields' ' test_expect_success 'Check format of strftime date fields' '