git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/2] t1500-rev-parse: rewrite each test to run in isolation

From
Michael Rappazzo <rappazzo@gmail.com>
Date
Apr 16, 2016, 16:13 UTC
Message-ID
<1460823230-45692-3-git-send-email-rappazzo@gmail.com>
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
Previous: Eric SunshineNext: Eric Sunshine
Message 9 of 13 in “t1500-rev-parse: re-write t1500”
  1. 0/2 t1500-rev-parse: re-write t1500Michael Rappazzo, Apr 16, 2016
  2. 1/2 test-lib: add a function to compare an expection with stdout from a commandMichael Rappazzo, Apr 16, 2016
  3. Eric SunshineApr 17, 2016
  4. Jeff KingApr 17, 2016
  5. Eric SunshineApr 17, 2016
  6. Jeff KingApr 17, 2016
  7. Johannes SixtApr 17, 2016
  8. Eric SunshineApr 17, 2016
  9. 2/2 t1500-rev-parse: rewrite each test to run in isolationMichael Rappazzo, Apr 16, 2016
  10. Eric SunshineApr 17, 2016
  11. Johannes SixtApr 17, 2016
  12. SZEDER GáborApr 17, 2016
  13. Eric SunshineApr 17, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.