git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Rappazzo <rappazzo@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, sunshine@sunshineco.com, pclouds@gmail.com,
	szeder@ira.uka.de, peff@peff.net,
	Michael Rappazzo <rappazzo@gmail.com>
Subject: [PATCH v2 2/2] t1500-rev-parse: rewrite each test to run in isolation
Date: Sat, 16 Apr 2016 12:13:50 -0400	[thread overview]
Message-ID: <1460823230-45692-3-git-send-email-rappazzo@gmail.com> (raw)
In-Reply-To: <1460823230-45692-1-git-send-email-rappazzo@gmail.com>

t1500-rev-parse has many tests which change directories and leak
environment variables.  This makes it difficult to add new tests without
minding the environment variables and current directory.

Each test is now setup, executed, and cleaned up without leaving anything
behind.  Test comparisons been converted to use test_cmp or test_stdout.

Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>
---
 t/t1500-rev-parse.sh | 355 ++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 295 insertions(+), 60 deletions(-)

diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index 48ee077..e2c2a06 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -3,85 +3,320 @@
 test_description='test git rev-parse'
 . ./test-lib.sh
 
-test_rev_parse() {
-	name=$1
-	shift
+test_expect_success 'toplevel: is-bare-repository' '
+	test_stdout false git rev-parse --is-bare-repository
+'
 
-	test_expect_success "$name: is-bare-repository" \
-	"test '$1' = \"\$(git rev-parse --is-bare-repository)\""
-	shift
-	[ $# -eq 0 ] && return
+test_expect_success 'toplevel: is-inside-git-dir' '
+	test_stdout false git rev-parse --is-inside-git-dir
+'
 
-	test_expect_success "$name: is-inside-git-dir" \
-	"test '$1' = \"\$(git rev-parse --is-inside-git-dir)\""
-	shift
-	[ $# -eq 0 ] && return
+test_expect_success 'toplevel: is-inside-work-tree' '
+	test_stdout true git rev-parse --is-inside-work-tree
+'
 
-	test_expect_success "$name: is-inside-work-tree" \
-	"test '$1' = \"\$(git rev-parse --is-inside-work-tree)\""
-	shift
-	[ $# -eq 0 ] && return
+test_expect_success 'toplevel: prefix' '
+	test_stdout "" git rev-parse --show-prefix
+'
 
-	test_expect_success "$name: prefix" \
-	"test '$1' = \"\$(git rev-parse --show-prefix)\""
-	shift
-	[ $# -eq 0 ] && return
+test_expect_success 'toplevel: git-dir' '
+	test_stdout .git git rev-parse --git-dir
+'
 
-	test_expect_success "$name: git-dir" \
-	"test '$1' = \"\$(git rev-parse --git-dir)\""
-	shift
-	[ $# -eq 0 ] && return
-}
+test_expect_success '.git/: is-bare-repository' '
+	test_stdout false git -C .git rev-parse --is-bare-repository
+'
 
-# label is-bare is-inside-git is-inside-work prefix git-dir
+test_expect_success '.git/: is-inside-git-dir' '
+	test_stdout true git -C .git rev-parse --is-inside-git-dir
+'
 
-ROOT=$(pwd)
+test_expect_success '.git/: is-inside-work-tree' '
+	test_stdout false git -C .git rev-parse --is-inside-work-tree
+'
 
-test_rev_parse toplevel false false true '' .git
+test_expect_success '.git/: prefix' '
+	test_stdout "" git -C .git rev-parse --show-prefix
+'
 
-cd .git || exit 1
-test_rev_parse .git/ false true false '' .
-cd objects || exit 1
-test_rev_parse .git/objects/ false true false '' "$ROOT/.git"
-cd ../.. || exit 1
+test_expect_success '.git/: git-dir' '
+	test_stdout . git -C .git rev-parse --git-dir
+'
 
-mkdir -p sub/dir || exit 1
-cd sub/dir || exit 1
-test_rev_parse subdirectory false false true sub/dir/ "$ROOT/.git"
-cd ../.. || exit 1
+test_expect_success '.git/objects/: is-bare-repository' '
+	test_stdout false git -C .git/objects rev-parse --is-bare-repository
+'
 
-git config core.bare true
-test_rev_parse 'core.bare = true' true false false
+test_expect_success '.git/objects/: is-inside-git-dir' '
+	test_stdout true git -C .git/objects rev-parse --is-inside-git-dir
+'
 
-git config --unset core.bare
-test_rev_parse 'core.bare undefined' false false true
+test_expect_success '.git/objects/: is-inside-work-tree' '
+	test_stdout false git -C .git/objects rev-parse --is-inside-work-tree
+'
 
-mkdir work || exit 1
-cd work || exit 1
-GIT_DIR=../.git
-GIT_CONFIG="$(pwd)"/../.git/config
-export GIT_DIR GIT_CONFIG
+test_expect_success '.git/objects/: prefix' '
+	test_stdout "" git -C .git/objects rev-parse --show-prefix
+'
 
-git config core.bare false
-test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true ''
+test_expect_success '.git/objects/: git-dir' '
+	echo $(pwd)/.git >expect &&
+	git -C .git/objects rev-parse --git-dir >actual &&
+	test_cmp expect actual
+'
 
-git config core.bare true
-test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false false ''
+test_expect_success 'subdirectory: is-bare-repository' '
+	mkdir -p sub/dir &&
+	test_when_finished "rm -rf sub" &&
+	test_stdout false git -C sub/dir rev-parse --is-bare-repository
+'
 
-git config --unset core.bare
-test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true ''
+test_expect_success 'subdirectory: is-inside-git-dir' '
+	mkdir -p sub/dir &&
+	test_when_finished "rm -rf sub" &&
+	test_stdout false git -C sub/dir rev-parse --is-inside-git-dir
+'
 
-mv ../.git ../repo.git || exit 1
-GIT_DIR=../repo.git
-GIT_CONFIG="$(pwd)"/../repo.git/config
+test_expect_success 'subdirectory: is-inside-work-tree' '
+	mkdir -p sub/dir &&
+	test_when_finished "rm -rf sub" &&
+	test_stdout true git -C sub/dir rev-parse --is-inside-work-tree
+'
 
-git config core.bare false
-test_rev_parse 'GIT_DIR=../repo.git, core.bare = false' false false true ''
+test_expect_success 'subdirectory: prefix' '
+	mkdir -p sub/dir &&
+	test_when_finished "rm -rf sub" &&
+	test sub/dir/ = "$(git -C sub/dir rev-parse --show-prefix)"
+'
 
-git config core.bare true
-test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true false false ''
+test_expect_success 'subdirectory: git-dir' '
+	mkdir -p sub/dir &&
+	test_when_finished "rm -rf sub" &&
+	echo $(pwd)/.git >expect &&
+	git -C sub/dir rev-parse --git-dir >actual &&
+	test_cmp expect actual
+'
 
-git config --unset core.bare
-test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
+test_expect_success 'core.bare = true: is-bare-repository' '
+	test_config core.bare true &&
+	test_stdout true git rev-parse --is-bare-repository
+'
+
+test_expect_success 'core.bare = true: is-inside-git-dir' '
+	test_config core.bare true &&
+	test_stdout false git rev-parse --is-inside-git-dir
+'
+
+test_expect_success 'core.bare = true: is-inside-work-tree' '
+	test_config core.bare true &&
+	test_stdout false git rev-parse --is-inside-work-tree
+'
+
+test_expect_success 'core.bare undefined: is-bare-repository' '
+	test_config core.bare "" &&
+	test_stdout false git rev-parse --is-bare-repository
+'
+
+test_expect_success 'core.bare undefined: is-inside-git-dir' '
+	test_config core.bare "" &&
+	test_stdout false git rev-parse --is-inside-git-dir
+'
+
+test_expect_success 'core.bare undefined: is-inside-work-tree' '
+	test_config core.bare "" &&
+	test_stdout true git rev-parse --is-inside-work-tree
+'
+
+test_expect_success 'GIT_DIR=../.git, core.bare = false: is-bare-repository' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	test_config -C "$(pwd)"/.git core.bare false &&
+	GIT_DIR=../.git test_stdout false git -C work rev-parse --is-bare-repository
+'
+
+test_expect_success 'GIT_DIR=../.git, core.bare = false: is-inside-git-dir' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	test_config -C "$(pwd)"/.git core.bare false &&
+	GIT_DIR=../.git test_stdout false git -C work rev-parse --is-inside-git-dir
+'
+
+test_expect_success 'GIT_DIR=../.git, core.bare = false: is-inside-work-tree' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	test_config -C "$(pwd)"/.git core.bare false &&
+	GIT_DIR=../.git test_stdout true git -C work rev-parse --is-inside-work-tree
+'
+
+test_expect_success 'GIT_DIR=../.git, core.bare = false: prefix' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	test_config -C "$(pwd)"/.git core.bare false &&
+	GIT_DIR=../.git test_stdout "" git -C work rev-parse --show-prefix >actual
+'
+
+test_expect_success 'GIT_DIR=../.git, core.bare = true: is-bare-repository' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	test_config -C "$(pwd)"/.git core.bare true &&
+	GIT_DIR=../.git test_stdout true git -C work rev-parse --is-bare-repository
+'
+
+test_expect_success 'GIT_DIR=../.git, core.bare = true: is-inside-git-dir' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	test_config -C "$(pwd)"/.git core.bare true &&
+	GIT_DIR=../.git test_stdout false git -C work rev-parse --is-inside-git-dir
+'
+
+test_expect_success 'GIT_DIR=../.git, core.bare = true: is-inside-work-tree' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	test_config -C "$(pwd)"/.git core.bare true &&
+	GIT_DIR=../.git test_stdout false git -C work rev-parse --is-inside-work-tree
+'
+
+test_expect_success 'GIT_DIR=../.git, core.bare = true: prefix' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	test_config -C "$(pwd)"/.git core.bare true &&
+	GIT_DIR=../.git test_stdout "" git -C work rev-parse --show-prefix
+'
+
+test_expect_success 'GIT_DIR=../.git, core.bare undefined: is-bare-repository' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	test_config -C "$(pwd)"/.git core.bar = &&
+	GIT_DIR=../.git test_stdout false git -C work rev-parse --is-bare-repository
+'
+
+test_expect_success 'GIT_DIR=../.git, core.bare undefined: is-inside-git-dir' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	test_config -C "$(pwd)"/.git core.bar = &&
+	GIT_DIR=../.git test_stdout false git -C work rev-parse --is-inside-git-dir
+'
+
+test_expect_success 'GIT_DIR=../.git, core.bare undefined: is-inside-work-tree' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	test_config -C "$(pwd)"/.git core.bar = &&
+	GIT_DIR=../.git test_stdout true git -C work rev-parse --is-inside-work-tree
+'
+
+test_expect_success 'GIT_DIR=../.git, core.bare undefined: prefix' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	test_config -C "$(pwd)"/.git core.bar = &&
+	GIT_DIR=../.git test_stdout "" git -C work rev-parse --show-prefix
+'
+
+test_expect_success 'GIT_DIR=../repo.git, core.bare = false: is-bare-repository' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	cp -r .git repo.git &&
+	test_when_finished "rm -r repo.git" &&
+	test_config -C "$(pwd)"/repo.git core.bare false &&
+	GIT_DIR=../repo.git test_stdout false git -C work rev-parse --is-bare-repository
+'
+
+test_expect_success 'GIT_DIR=../repo.git, core.bare = false: is-inside-git-dir' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	cp -r .git repo.git &&
+	test_when_finished "rm -r repo.git" &&
+	test_config -C "$(pwd)"/repo.git core.bare false &&
+	GIT_DIR=../repo.git test_stdout false git -C work rev-parse --is-inside-git-dir
+'
+
+test_expect_success 'GIT_DIR=../repo.git, core.bare = false: is-inside-work-tree' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	cp -r .git repo.git &&
+	test_when_finished "rm -r repo.git" &&
+	test_config -C "$(pwd)"/repo.git core.bare false &&
+	GIT_DIR=../repo.git test_stdout true git -C work rev-parse --is-inside-work-tree
+'
+
+test_expect_success 'GIT_DIR=../repo.git, core.bare = false: prefix' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	cp -r .git repo.git &&
+	test_when_finished "rm -r repo.git" &&
+	test_config -C "$(pwd)"/repo.git core.bare false &&
+	GIT_DIR=../repo.git test_stdout "" git -C work rev-parse --show-prefix
+'
+
+test_expect_success 'GIT_DIR=../repo.git, core.bare = true: is-bare-repository' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	cp -r .git repo.git &&
+	test_when_finished "rm -r repo.git" &&
+	test_config -C "$(pwd)"/repo.git core.bare true &&
+	GIT_DIR=../repo.git test_stdout true git -C work rev-parse --is-bare-repository
+'
+
+test_expect_success 'GIT_DIR=../repo.git, core.bare = true: is-inside-git-dir' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	cp -r .git repo.git &&
+	test_when_finished "rm -r repo.git" &&
+	test_config -C "$(pwd)"/repo.git core.bare true &&
+	GIT_DIR=../repo.git test_stdout false git -C work rev-parse --is-inside-git-dir
+'
+
+test_expect_success 'GIT_DIR=../repo.git, core.bare = true: is-inside-work-tree' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	cp -r .git repo.git &&
+	test_when_finished "rm -r repo.git" &&
+	test_config -C "$(pwd)"/repo.git core.bare true &&
+	GIT_DIR=../repo.git test_stdout false git -C work rev-parse --is-inside-work-tree
+'
+
+test_expect_success 'GIT_DIR=../repo.git, core.bare = true: prefix' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	cp -r .git repo.git &&
+	test_when_finished "rm -r repo.git" &&
+	test_config -C "$(pwd)"/repo.git core.bare true &&
+	GIT_DIR=../repo.git test_stdout "" git -C work rev-parse --show-prefix
+'
+
+test_expect_success 'GIT_DIR=../repo.git, core.bare undefined: is-bare-repository' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	cp -r .git repo.git &&
+	test_when_finished "rm -r repo.git" &&
+	test_config -C "$(pwd)"/repo.git core.bare "" &&
+	GIT_DIR=../repo.git test_stdout false git -C work rev-parse --is-bare-repository
+'
+
+test_expect_success 'GIT_DIR=../repo.git, core.bare undefined: is-inside-git-dir' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	cp -r .git repo.git &&
+	test_when_finished "rm -r repo.git" &&
+	test_config -C "$(pwd)"/repo.git core.bare "" &&
+	GIT_DIR=../repo.git test_stdout false git -C work rev-parse --is-inside-git-dir
+'
+
+test_expect_success 'GIT_DIR=../repo.git, core.bare undefined: is-inside-work-tree' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	cp -r .git repo.git &&
+	test_when_finished "rm -r repo.git" &&
+	test_config -C "$(pwd)"/repo.git core.bare "" &&
+	GIT_DIR=../repo.git test_stdout true git -C work rev-parse --is-inside-work-tree
+'
+
+test_expect_success 'GIT_DIR=../repo.git, core.bare undefined: prefix' '
+	mkdir work &&
+	test_when_finished "rm -rf work" &&
+	cp -r .git repo.git &&
+	test_when_finished "rm -r repo.git" &&
+	test_config -C "$(pwd)"/repo.git core.bare "" &&
+	GIT_DIR=../repo.git test_stdout "" git -C work rev-parse --show-prefix
+'
 
 test_done
-- 
2.8.0

  parent reply	other threads:[~2016-04-16 16:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-16 16:13 [PATCH v2 0/2] t1500-rev-parse: re-write t1500 Michael Rappazzo
2016-04-16 16:13 ` [PATCH v2 1/2] test-lib: add a function to compare an expection with stdout from a command Michael Rappazzo
2016-04-17  3:07   ` Eric Sunshine
2016-04-17  3:54     ` Jeff King
2016-04-17  6:36       ` Eric Sunshine
2016-04-17  6:41         ` Jeff King
2016-04-17 15:19     ` Johannes Sixt
2016-04-17 16:22       ` Eric Sunshine
2016-04-16 16:13 ` Michael Rappazzo [this message]
2016-04-17  5:59   ` [PATCH v2 2/2] t1500-rev-parse: rewrite each test to run in isolation Eric Sunshine
2016-04-17 15:05     ` Johannes Sixt
2016-04-17  9:42   ` SZEDER Gábor
2016-04-17 16:15     ` Eric Sunshine

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=1460823230-45692-3-git-send-email-rappazzo@gmail.com \
    --to=rappazzo@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).