[PATCH-w 101/105] t6300 (for-each-ref): modernize style

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output

Signed-off-by: Tom Grennan <tmgrennan@xxxxxxxxx>
---
 t/t6300-for-each-ref.sh |  296 +++++++++++++++++++++++++----------------------
 1 files changed, 157 insertions(+), 139 deletions(-)

diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 1721784..12916b2 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -5,9 +5,17 @@
 
 test_description='for-each-ref test'
 
+if ! test -r test-lib.sh ; then
+	(cd ${0%/*} && ./${0##*/} $@)
+	exit $?
+fi
+
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-gpg.sh
 
+quiet () { "$@" >/dev/null; }
+silent () { "$@" >/dev/null 2>&1; }
+
 # Mon Jul 3 15:18:43 2006 +0000
 datestamp=1151939923
 setdate_and_increment () {
@@ -22,9 +30,9 @@ test_expect_success 'Create sample commit with known timestamp' '
 	setdate_and_increment &&
 	echo "Using $datestamp" > one &&
 	git add one &&
-	git commit -m "Initial" &&
+	git commit -q -m "Initial" &&
 	setdate_and_increment &&
-	git tag -a -m "Tagging at $datestamp" testtag
+	quiet git tag -a -m "Tagging at $datestamp" testtag
 '
 
 test_expect_success 'Create upstream config' '
@@ -115,261 +123,270 @@ test_atom tag contents 'Tagging at 1151939927
 '
 
 test_expect_success 'Check invalid atoms names are errors' '
-	test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
+	silent test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
 '
 
 test_expect_success 'Check format specifiers are ignored in naming date atoms' '
-	git for-each-ref --format="%(authordate)" refs/heads &&
-	git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
-	git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
-	git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
+	f1="%(authordate)" &&
+	f2="%(authordate:default) %(authordate)" &&
+	f3="%(authordate) %(authordate:default)" &&
+	f4="%(authordate:default) %(authordate:default)"
+	quiet git for-each-ref --format="$f1" refs/heads &&
+	quiet git for-each-ref --format="$f2" refs/heads &&
+	quiet git for-each-ref --format="$f3" refs/heads &&
+	quiet git for-each-ref --format="$f4" refs/heads
 '
 
 test_expect_success 'Check valid format specifiers for date fields' '
-	git for-each-ref --format="%(authordate:default)" refs/heads &&
-	git for-each-ref --format="%(authordate:relative)" refs/heads &&
-	git for-each-ref --format="%(authordate:short)" refs/heads &&
-	git for-each-ref --format="%(authordate:local)" refs/heads &&
-	git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
-	git for-each-ref --format="%(authordate:rfc2822)" refs/heads
+	quiet git for-each-ref --format="%(authordate:default)" refs/heads &&
+	quiet git for-each-ref --format="%(authordate:relative)" refs/heads &&
+	quiet git for-each-ref --format="%(authordate:short)" refs/heads &&
+	quiet git for-each-ref --format="%(authordate:local)" refs/heads &&
+	quiet git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
+	quiet git for-each-ref --format="%(authordate:rfc2822)" refs/heads
 '
 
 test_expect_success 'Check invalid format specifiers are errors' '
-	test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
+	h="%(authordate:INVALID)" &&
+	silent test_must_fail git for-each-ref --format="$h" refs/heads
 '
 
-cat >expected <<\EOF
+test_expect_success 'Check unformatted date fields output' '
+	'"
+	cat >expect <<-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_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
+	"'
+	h="%(refname) %(committerdate) %(authordate)" &&
+	t="%(refname) %(taggerdate)" &&
+	(git for-each-ref --shell --format="$h" refs/heads &&
+	 git for-each-ref --shell --format="$t" refs/tags) |
+		test_cmp expect -
 '
 
 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
+	h="%(refname) %(committerdate:default) %(authordate:default)" &&
+	t="%(refname) %(taggerdate:default)" &&
+	(git for-each-ref --shell --format="$h" refs/heads &&
+	 git for-each-ref --shell --format="$t" refs/tags) |
+		test_cmp expect -
 '
 
-# 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
+	'"
+	# 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
+	"'
+	h="%(refname) %(committerdate:relative) %(authordate:relative)" &&
+	t="%(refname) %(taggerdate:relative)" &&
+	quiet git for-each-ref --shell --format="$h" refs/heads &&
+	quiet git for-each-ref --shell --format="$t" refs/tags
 '
 
-cat >expected <<\EOF
+test_expect_success 'Check format "short" date fields output' '
+	'"
+	cat >expect <<-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
+	"'
+	h="%(refname) %(committerdate:short) %(authordate:short)" &&
+	t="%(refname) %(taggerdate:short)" &&
+	(git for-each-ref --shell --format="$h" refs/heads &&
+	 git for-each-ref --shell --format="$t" refs/tags) |
+		test_cmp expect -
 '
 
-cat >expected <<\EOF
+test_expect_success 'Check format "local" date fields output' '
+	'"
+	cat >expect <<-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
+	"'
+	h="%(refname) %(committerdate:local) %(authordate:local)" &&
+	t="%(refname) %(taggerdate:local)" &&
+	(git for-each-ref --shell --format="$h" refs/heads &&
+	 git for-each-ref --shell --format="$t" refs/tags) |
+		test_cmp expect -
 '
 
-cat >expected <<\EOF
+test_expect_success 'Check format "iso8601" date fields output' '
+	'"
+	cat >expect <<-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
+	"'
+	h="%(refname) %(committerdate:iso8601) %(authordate:iso8601)" &&
+	t="%(refname) %(taggerdate:iso8601)" &&
+	(git for-each-ref --shell --format="$h" refs/heads &&
+	 git for-each-ref --shell --format="$t" refs/tags) |
+		test_cmp expect -
 '
 
-cat >expected <<\EOF
+test_expect_success 'Check format "rfc2822" date fields output' '
+	'"
+	cat >expect <<-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
+	"'
+	h="%(refname) %(committerdate:rfc2822) %(authordate:rfc2822)" &&
+	t="%(refname) %(taggerdate:rfc2822)" &&
+	(git for-each-ref --shell --format="$h" refs/heads &&
+	 git for-each-ref --shell --format="$t" refs/tags) |
+		test_cmp expect -
 '
 
-cat >expected <<\EOF
+test_expect_success 'Verify ascending sort' '
+	cat >expect <<-EOF
 refs/heads/master
 refs/remotes/origin/master
 refs/tags/testtag
 EOF
-
-test_expect_success 'Verify ascending sort' '
-	git for-each-ref --format="%(refname)" --sort=refname >actual &&
-	test_cmp expected actual
+	git for-each-ref --format="%(refname)" --sort=refname |
+		test_cmp expect -
 '
 
-
-cat >expected <<\EOF
+test_expect_success 'Verify descending sort' '
+	cat >expect <<-EOF
 refs/tags/testtag
 refs/remotes/origin/master
 refs/heads/master
 EOF
-
-test_expect_success 'Verify descending sort' '
-	git for-each-ref --format="%(refname)" --sort=-refname >actual &&
-	test_cmp expected actual
+	git for-each-ref --format="%(refname)" --sort=-refname |
+		test_cmp expect -
 '
 
-cat >expected <<\EOF
+test_expect_success 'Quoting style: shell' '
+	'"
+	cat >expect <<-EOF
 'refs/heads/master'
 'refs/remotes/origin/master'
 'refs/tags/testtag'
 EOF
-
-test_expect_success 'Quoting style: shell' '
-	git for-each-ref --shell --format="%(refname)" >actual &&
-	test_cmp expected actual
+	"'
+	git for-each-ref --shell --format="%(refname)" |
+		test_cmp expect -
 '
 
 test_expect_success 'Quoting style: perl' '
-	git for-each-ref --perl --format="%(refname)" >actual &&
-	test_cmp expected actual
+	git for-each-ref --perl --format="%(refname)" |
+		test_cmp expect -
 '
 
 test_expect_success 'Quoting style: python' '
-	git for-each-ref --python --format="%(refname)" >actual &&
-	test_cmp expected actual
+	git for-each-ref --python --format="%(refname)" |
+		test_cmp expect -
 '
 
-cat >expected <<\EOF
+test_expect_success 'Quoting style: tcl' '
+	cat >expect <<-EOF
 "refs/heads/master"
 "refs/remotes/origin/master"
 "refs/tags/testtag"
 EOF
-
-test_expect_success 'Quoting style: tcl' '
-	git for-each-ref --tcl --format="%(refname)" >actual &&
-	test_cmp expected actual
+	git for-each-ref --tcl --format="%(refname)" |
+		test_cmp expect -
 '
 
-for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
-	test_expect_success "more than one quoting style: $i" "
-		git for-each-ref $i 2>&1 | (read line &&
-		case \$line in
-		\"error: more than one quoting style\"*) : happy;;
-		*) false
-		esac)
-	"
-done
-
-cat >expected <<\EOF
+test_expect_success 'more than one quoting styles' '
+	cat >expect <<-EOF
+		error: more than one quoting style?
+	EOF
+	git for-each-ref --perl --shell 2>&1 | head -n 1 |
+		test_cmp expect - &&
+	git for-each-ref -s --python 2>&1 | head -n 1 |
+		test_cmp expect - &&
+	git for-each-ref --python --tcl 2>&1 | head -n 1 |
+		test_cmp expect - &&
+	git for-each-ref --tcl --perl 2>&1 | head -n 1 |
+		test_cmp expect -
+'
+test_expect_success 'Check short refname format' '
+	cat >expect <<-EOF
 master
 testtag
 EOF
-
-test_expect_success 'Check short refname format' '
-	(git for-each-ref --format="%(refname:short)" refs/heads &&
-	git for-each-ref --format="%(refname:short)" refs/tags) >actual &&
-	test_cmp expected actual
+	git for-each-ref --format="%(refname:short)" refs/heads refs/tags |
+		test_cmp expect -
 '
 
-cat >expected <<EOF
+test_expect_success 'Check short upstream format' '
+	cat >expect <<-EOF
 origin/master
 EOF
-
-test_expect_success 'Check short upstream format' '
-	git for-each-ref --format="%(upstream:short)" refs/heads >actual &&
-	test_cmp expected actual
+	git for-each-ref --format="%(upstream:short)" refs/heads |
+		test_cmp expect -
 '
 
-cat >expected <<EOF
+test_expect_success 'Check short objectname format' '
+	cat >expect <<-EOF
 67a36f1
 EOF
-
-test_expect_success 'Check short objectname format' '
-	git for-each-ref --format="%(objectname:short)" refs/heads >actual &&
-	test_cmp expected actual
+	git for-each-ref --format="%(objectname:short)" refs/heads |
+		test_cmp expect -
 '
 
 test_expect_success 'Check for invalid refname format' '
-	test_must_fail git for-each-ref --format="%(refname:INVALID)"
+	silent test_must_fail git for-each-ref --format="%(refname:INVALID)"
 '
 
-cat >expected <<\EOF
+test_expect_success 'Check ambiguous head and tag refs (strict)' '
+	cat >expect <<-EOF
 heads/master
 tags/master
 EOF
-
-test_expect_success 'Check ambiguous head and tag refs (strict)' '
 	git config --bool core.warnambiguousrefs true &&
-	git checkout -b newtag &&
+	git checkout -q -b newtag &&
 	echo "Using $datestamp" > one &&
 	git add one &&
-	git commit -m "Branch" &&
+	git commit -q -m "Branch" &&
 	setdate_and_increment &&
-	git tag -m "Tagging at $datestamp" master &&
-	git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
-	test_cmp expected actual
+	quiet git tag -m "Tagging at $datestamp" master &&
+	f="%(refname:short)" &&
+	git for-each-ref --format "$f" refs/heads/master refs/tags/master |
+		test_cmp expect -
 '
 
-cat >expected <<\EOF
+test_expect_success 'Check ambiguous head and tag refs (loose)' '
+	cat >expect <<-EOF
 heads/master
 master
 EOF
-
-test_expect_success 'Check ambiguous head and tag refs (loose)' '
 	git config --bool core.warnambiguousrefs false &&
-	git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
-	test_cmp expected actual
+	f="%(refname:short)" &&
+	git for-each-ref --format "$f" refs/heads/master refs/tags/master |
+		test_cmp expect -
 '
 
-cat >expected <<\EOF
+test_expect_success 'Check ambiguous head and tag refs II (loose)' '
+	cat >expect <<-EOF
 heads/ambiguous
 ambiguous
 EOF
-
-test_expect_success 'Check ambiguous head and tag refs II (loose)' '
-	git checkout master &&
+	git checkout -q master &&
 	git tag ambiguous testtag^0 &&
 	git branch ambiguous testtag^0 &&
-	git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
-	test_cmp expected actual
+	f="%(refname:short)" &&
+	git for-each-ref --format "$f" refs/heads/ambiguous refs/tags/ambiguous |
+		test_cmp expect -
 '
 
 test_expect_success 'an unusual tag with an incomplete line' '
-
 	git tag -m "bogo" bogo &&
 	bogo=$(git cat-file tag bogo) &&
 	bogo=$(printf "%s" "$bogo" | git mktag) &&
 	git tag -f bogo "$bogo" &&
 	git for-each-ref --format "%(body)" refs/tags/bogo
-
 '
 
 test_expect_success 'create tag with subject and body content' '
-	cat >>msg <<-\EOF &&
+	cat >msg <<-\EOF &&
 		the subject line
 
 		first body line
@@ -395,8 +412,9 @@ test_expect_success 'create tag with multiline subject' '
 		first body line
 		second body line
 	EOF
-	git tag -F msg multiline
+	quiet git tag -F msg multiline
 '
+
 test_atom refs/tags/multiline subject 'first subject line second subject line'
 test_atom refs/tags/multiline contents:subject 'first subject line second subject line'
 test_atom refs/tags/multiline body 'first body line
-- 
1.7.8

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]