All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
	"Michael Rappazzo" <rappazzo@gmail.com>,
	"Duy Nguyen" <pclouds@gmail.com>,
	"SZEDER Gábor" <szeder@ira.uka.de>,
	"Johannes Sixt" <j.sixt@viscovery.net>,
	"Eric Sunshine" <sunshine@sunshineco.com>
Subject: [PATCH 1/6] t1500: test_rev_parse: facilitate future test enhancements
Date: Tue, 10 May 2016 01:20:50 -0400	[thread overview]
Message-ID: <20160510052055.32924-2-sunshine@sunshineco.com> (raw)
In-Reply-To: <20160510052055.32924-1-sunshine@sunshineco.com>

Tests run by test_rev_parse() are nearly identical; each invokes
git-rev-parse with a single option and compares the result against an
expected value. Such duplication makes it onerous to extend the tests
since any change needs to be repeated in each test. Reduce the
duplication by parameterizing the test and driving it via a for-loop.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 t/t1500-rev-parse.sh | 44 +++++++++++++++++---------------------------
 1 file changed, 17 insertions(+), 27 deletions(-)

diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index 48ee077..03f22fe 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -3,38 +3,28 @@
 test_description='test git rev-parse'
 . ./test-lib.sh
 
-test_rev_parse() {
+# usage: label is-bare is-inside-git is-inside-work prefix git-dir
+test_rev_parse () {
 	name=$1
 	shift
 
-	test_expect_success "$name: is-bare-repository" \
-	"test '$1' = \"\$(git rev-parse --is-bare-repository)\""
-	shift
-	[ $# -eq 0 ] && return
-
-	test_expect_success "$name: is-inside-git-dir" \
-	"test '$1' = \"\$(git rev-parse --is-inside-git-dir)\""
-	shift
-	[ $# -eq 0 ] && return
-
-	test_expect_success "$name: is-inside-work-tree" \
-	"test '$1' = \"\$(git rev-parse --is-inside-work-tree)\""
-	shift
-	[ $# -eq 0 ] && return
-
-	test_expect_success "$name: prefix" \
-	"test '$1' = \"\$(git rev-parse --show-prefix)\""
-	shift
-	[ $# -eq 0 ] && return
-
-	test_expect_success "$name: git-dir" \
-	"test '$1' = \"\$(git rev-parse --git-dir)\""
-	shift
-	[ $# -eq 0 ] && return
+	for o in is-bare-repository \
+		 is-inside-git-dir \
+		 is-inside-work-tree \
+		 show-prefix \
+		 git-dir
+	do
+		expect="$1"
+		test_expect_success "$name: $o" '
+			echo "$expect" >expect &&
+			git rev-parse --$o >actual &&
+			test_cmp expect actual
+		'
+		shift
+		test $# -eq 0 && break
+	done
 }
 
-# label is-bare is-inside-git is-inside-work prefix git-dir
-
 ROOT=$(pwd)
 
 test_rev_parse toplevel false false true '' .git
-- 
2.8.2.530.g51d527d

  reply	other threads:[~2016-05-10  5:21 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-10  5:20 [PATCH 0/6] modernize t1500 Eric Sunshine
2016-05-10  5:20 ` Eric Sunshine [this message]
2016-05-10  5:20 ` [PATCH 2/6] t1500: reduce dependence upon global state Eric Sunshine
2016-05-10  5:20 ` [PATCH 3/6] t1500: avoid changing working directory outside of tests Eric Sunshine
2016-05-10  5:20 ` [PATCH 4/6] t1500: avoid setting configuration options " Eric Sunshine
2016-05-10  6:34   ` Eric Sunshine
2016-05-10 18:02     ` Junio C Hamano
2016-05-10  5:20 ` [PATCH 5/6] t1500: avoid setting environment variables " Eric Sunshine
2016-05-10 18:39   ` Jeff King
2016-05-10 19:12     ` Eric Sunshine
2016-05-10 19:19       ` Junio C Hamano
2016-05-10 19:48       ` Eric Sunshine
2016-05-10 19:59         ` Eric Sunshine
2016-05-10 20:41           ` Jeff King
2016-05-10 20:07         ` Junio C Hamano
2016-05-10 21:01         ` SZEDER Gábor
2016-05-10 21:11           ` Junio C Hamano
2016-05-10 21:19             ` Eric Sunshine
2016-05-10  5:20 ` [PATCH 6/6] t1500: be considerate to future potential tests Eric Sunshine
2016-05-10  6:07 ` [PATCH 0/6] modernize t1500 Junio C Hamano
2016-05-10 18:10   ` Junio C Hamano
2016-05-10 18:26     ` Junio C Hamano
2016-05-16 17:39       ` Eric Sunshine
2016-05-16 18:52         ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2016-02-29  6:30 50a6c8ef - xmalloc_array Torsten Bögershausen
2016-02-29  9:28 ` [PATCH] compat/mingw: brown paper bag fix for 50a6c8e Jeff King
2016-02-29  9:56   ` Torsten Bögershausen
2016-02-29 10:02     ` Jeff King
2016-02-29 10:40       ` Compiler warning under cygwin/mingw (was: fix for 50a6c8e) Torsten Bögershausen
2016-02-29 10:47         ` Jeff King
2016-02-29 14:05           ` SZEDER Gábor
2016-04-12 23:20             ` Compiler warning under cygwin/mingw Junio C Hamano
2016-05-10 18:29             ` [PATCH 0/6] modernize t1500 Junio C Hamano
2016-02-29 12:32         ` Compiler warning under cygwin/mingw Ramsay Jones
2016-03-03  3:33           ` Ramsay Jones
2016-03-03  5:25             ` Ramsay Jones
2016-02-29 19:10       ` [PATCH] compat/mingw: brown paper bag fix for 50a6c8e Junio C Hamano
2016-02-29 21:36         ` Jeff King
2016-03-01  5:49           ` Torsten Bögershausen
2016-03-01  5:54             ` Jeff King
2016-03-01 13:52               ` Johannes Schindelin
2016-02-29 13:01   ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160510052055.32924-2-sunshine@sunshineco.com \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=rappazzo@gmail.com \
    --cc=szeder@ira.uka.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.