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

[PATCH 08/12] t0001: use test_path_is_*

From
Jeff King <peff@peff.net>
Date
Mar 20, 2014, 23:17 UTC
Message-ID
<20140320231735.GH8479@sigill.intra.peff.net>
In-Reply-To
<20140320231159.GA7774@sigill.intra.peff.net>

t0001 predates the test_path_is_* helpers, and uses "test -f" and "test -d" directly. Using the helpers provides better debugging output, and are a little more robust. As opposed to "! test -d", test_path_is_missing will actually makes sure the path does not exist at all.

Signed-off-by: Jeff King <peff@peff.net>
---
 t/t0001-init.sh | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 5245711..fdcf4b3 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -199,13 +199,13 @@ test_expect_success 'init with --template (blank)' '
 		cd template-plain &&
 		git init
 	) &&
-	test -f template-plain/.git/info/exclude &&
+	test_path_is_file template-plain/.git/info/exclude &&
 	(
 		mkdir template-blank &&
 		cd template-blank &&
 		git init --template=
 	) &&
-	! test -f template-blank/.git/info/exclude
+	test_path_is_missing template-blank/.git/info/exclude
 '
 
 test_expect_success 'init with init.templatedir set' '
@@ -263,7 +263,7 @@ test_expect_success 'init creates a new directory' '
 	rm -fr newdir &&
 	(
 		git init newdir &&
-		test -d newdir/.git/refs
+		test_path_is_dir newdir/.git/refs
 	)
 '
 
@@ -271,7 +271,7 @@ test_expect_success 'init creates a new bare directory' '
 	rm -fr newdir &&
 	(
 		git init --bare newdir &&
-		test -d newdir/refs
+		test_path_is_dir newdir/refs
 	)
 '
 
@@ -280,7 +280,7 @@ test_expect_success 'init recreates a directory' '
 	(
 		mkdir newdir &&
 		git init newdir &&
-		test -d newdir/.git/refs
+		test_path_is_dir newdir/.git/refs
 	)
 '
 
@@ -289,14 +289,14 @@ test_expect_success 'init recreates a new bare directory' '
 	(
 		mkdir newdir &&
 		git init --bare newdir &&
-		test -d newdir/refs
+		test_path_is_dir newdir/refs
 	)
 '
 
 test_expect_success 'init creates a new deep directory' '
 	rm -fr newdir &&
 	git init newdir/a/b/c &&
-	test -d newdir/a/b/c/.git/refs
+	test_path_is_dir newdir/a/b/c/.git/refs
 '
 
 test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' '
@@ -306,7 +306,7 @@ test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shar
 		# the repository itself should follow "shared"
 		umask 002 &&
 		git init --bare --shared=0660 newdir/a/b/c &&
-		test -d newdir/a/b/c/refs &&
+		test_path_is_dir newdir/a/b/c/refs &&
 		ls -ld newdir/a newdir/a/b > lsab.out &&
 		! grep -v "^drwxrw[sx]r-x" lsab.out &&
 		ls -ld newdir/a/b/c > lsc.out &&
@@ -319,7 +319,7 @@ test_expect_success 'init notices EEXIST (1)' '
 	(
 		>newdir &&
 		test_must_fail git init newdir &&
-		test -f newdir
+		test_path_is_file newdir
 	)
 '
 
@@ -329,7 +329,7 @@ test_expect_success 'init notices EEXIST (2)' '
 		mkdir newdir &&
 		>newdir/a
 		test_must_fail git init newdir/a/b &&
-		test -f newdir/a
+		test_path_is_file newdir/a
 	)
 '
 
@@ -345,15 +345,15 @@ test_expect_success POSIXPERM,SANITY 'init notices EPERM' '
 test_expect_success 'init creates a new bare directory with global --bare' '
 	rm -rf newdir &&
 	git --bare init newdir &&
-	test -d newdir/refs
+	test_path_is_dir newdir/refs
 '
 
 test_expect_success 'init prefers command line to GIT_DIR' '
 	rm -rf newdir &&
 	mkdir otherdir &&
 	GIT_DIR=otherdir git --bare init newdir &&
-	test -d newdir/refs &&
-	! test -d otherdir/refs
+	test_path_is_dir newdir/refs &&
+	test_path_is_missing otherdir/refs
 '
 
 test_expect_success 'init with separate gitdir' '
@@ -361,7 +361,7 @@ test_expect_success 'init with separate gitdir' '
 	git init --separate-git-dir realgitdir newdir &&
 	echo "gitdir: `pwd`/realgitdir" >expected &&
 	test_cmp expected newdir/.git &&
-	test -d realgitdir/refs
+	test_path_is_dir realgitdir/refs
 '
 
 test_expect_success 're-init on .git file' '
@@ -375,8 +375,8 @@ test_expect_success 're-init to update git link' '
 	) &&
 	echo "gitdir: `pwd`/surrealgitdir" >expected &&
 	test_cmp expected newdir/.git &&
-	test -d surrealgitdir/refs &&
-	! test -d realgitdir/refs
+	test_path_is_dir surrealgitdir/refs &&
+	test_path_is_missing realgitdir/refs
 '
 
 test_expect_success 're-init to move gitdir' '
@@ -388,7 +388,7 @@ test_expect_success 're-init to move gitdir' '
 	) &&
 	echo "gitdir: `pwd`/realgitdir" >expected &&
 	test_cmp expected newdir/.git &&
-	test -d realgitdir/refs
+	test_path_is_dir realgitdir/refs
 '
 
 test_expect_success SYMLINKS 're-init to move gitdir symlink' '
@@ -403,7 +403,7 @@ test_expect_success SYMLINKS 're-init to move gitdir symlink' '
 	echo "gitdir: `pwd`/realgitdir" >expected &&
 	test_cmp expected newdir/.git &&
 	test_cmp expected newdir/here &&
-	test -d realgitdir/refs
+	test_path_is_dir realgitdir/refs
 '
 
 test_done
-- 
1.9.0.560.g01ceb46
Previous: Jeff KingNext: Jeff King
Message 21 of 28 in “tests: set temp variables using 'env' in test function instead of subshell”
  1. tests: set temp variables using 'env' in test function instead of subshellDavid Tran, Mar 18, 2014
  2. Junio C HamanoMar 18, 2014
  3. Jeff KingMar 18, 2014
  4. Junio C HamanoMar 18, 2014
  5. Jeff KingMar 18, 2014
  6. Junio C HamanoMar 19, 2014
  7. 0/12 GIT_CONFIG in the test suiteJeff King, Mar 20, 2014
  8. 01/12 t/Makefile: stop setting GIT_CONFIGJeff King, Mar 20, 2014
  9. 02/12 t/test-lib: drop redundant unset of GIT_CONFIGJeff King, Mar 20, 2014
  10. 03/12 t: drop useless sane_unset GIT_* callsJeff King, Mar 20, 2014
  11. Junio C HamanoMar 21, 2014
  12. Jeff KingMar 24, 2014
  13. Junio C HamanoMar 24, 2014
  14. Junio C HamanoMar 25, 2014
  15. 04/12 t: stop using GIT_CONFIG to cross repo boundariesJeff King, Mar 20, 2014
  16. Junio C HamanoMar 21, 2014
  17. Jeff KingMar 24, 2014
  18. 05/12 t: prefer "git config --file" to GIT_CONFIG with test_must_failJeff King, Mar 20, 2014
  19. 06/12 t: prefer "git config --file" to GIT_CONFIGJeff King, Mar 20, 2014
  20. 07/12 t0001: make symlink reinit test more carefulJeff King, Mar 20, 2014
  21. 08/12 t0001: use test_path_is_*Jeff King, Mar 20, 2014
  22. 09/12 t0001: use test_config_globalJeff King, Mar 20, 2014
  23. 10/12 t0001: use test_must_failJeff King, Mar 20, 2014
  24. 11/12 t0001: drop useless subshellsJeff King, Mar 20, 2014
  25. Eric SunshineMar 21, 2014
  26. 12/12 t0001: drop subshells just for "cd"Jeff King, Mar 20, 2014
  27. Eric SunshineMar 18, 2014
  28. Eric SunshineMar 18, 2014

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.