summaryrefslogtreecommitdiff
path: root/t/t6300-for-each-ref.sh
diff options
context:
space:
mode:
authorJohn Keeping <john@keeping.me.uk>2015-09-03 21:48:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-09-03 22:36:38 (GMT)
commitf95cecf43335dd8e80e954c2f998dc0e8b0dd070 (patch)
tree4450e3dba40a58f8cd4cf3b14d38539ba73b4d89 /t/t6300-for-each-ref.sh
parent547ed71636dbfab2dc303ba8cabb29c2cab22f1e (diff)
downloadgit-f95cecf43335dd8e80e954c2f998dc0e8b0dd070.zip
git-f95cecf43335dd8e80e954c2f998dc0e8b0dd070.tar.gz
git-f95cecf43335dd8e80e954c2f998dc0e8b0dd070.tar.bz2
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>
Diffstat (limited to 't/t6300-for-each-ref.sh')
-rwxr-xr-xt/t6300-for-each-ref.sh92
1 files changed, 40 insertions, 52 deletions
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index c7f368c..c14c457 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -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
'
-cat >expected <<\EOF
-'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200'
-'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200'
-EOF
+test_date () {
+ f=$1 &&
+ committer_date=$2 &&
+ 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' '
- (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads &&
- git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual &&
- test_cmp expected actual
+ test_date "" \
+ "Mon Jul 3 17:18:43 2006 +0200" \
+ "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' '
- f=default &&
- (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
+ test_date default \
+ "Mon Jul 3 17:18:43 2006 +0200" \
+ "Mon Jul 3 17:18:44 2006 +0200" \
+ "Mon Jul 3 17:18:45 2006 +0200"
'
# 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
# provide expected output. Instead, I'll just make sure that "relative"
# doesn't exit in error
-#
-#cat >expected <<\EOF
-#
-#EOF
-#
test_expect_success 'Check format "relative" date fields output' '
f=relative &&
(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
'
-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' '
- f=short &&
- (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
+ test_date short 2006-07-03 2006-07-03 2006-07-03
'
-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' '
- f=local &&
- (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
+ test_date local \
+ "Mon Jul 3 15:18:43 2006" \
+ "Mon Jul 3 15:18:44 2006" \
+ "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' '
- f=iso8601 &&
- (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
+ test_date iso8601 \
+ "2006-07-03 17:18:43 +0200" \
+ "2006-07-03 17:18:44 +0200" \
+ "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' '
- f=rfc2822 &&
- (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
+ test_date rfc2822 \
+ "Mon, 3 Jul 2006 17:18:43 +0200" \
+ "Mon, 3 Jul 2006 17:18:44 +0200" \
+ "Mon, 3 Jul 2006 17:18:45 +0200"
'
test_expect_success 'Check format of strftime date fields' '