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

Re: [PATCH] Several tests: cd inside subshell instead of around

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 6, 2010, 23:16 UTC
Message-ID
<7vhbi2tqd0.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4C85357A.8090000@web.de>
Jens Lehmann <Jens.Lehmann@web.de> writes:
Show 7 quoted lines
> Fixed all places where it was a straightforward change from cd'ing into a
> directory and back via "cd .." to a cd inside a subshell.
>
> Found these places with "git grep -w "cd \.\.".
>
> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
> ---
Thanks; that is a huge effort of cleaning things up.
Show 21 quoted lines
> diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh
> index 5687499..c36157a 100755
> --- a/t/t1020-subdirectory.sh
> +++ b/t/t1020-subdirectory.sh
> @@ -27,13 +27,13 @@ test_expect_success 'update-index and ls-files' '
>  	one) echo pass one ;;
>  	*) echo bad one; exit 1 ;;
>  	esac &&
> -	cd dir &&
> +	(cd dir &&
>  	git update-index --add two &&
>  	case "`git ls-files`" in
>  	two) echo pass two ;;
>  	*) echo bad two; exit 1 ;;
> -	esac &&
> -	cd .. &&
> +	esac
> +	) &&
>  	case "`git ls-files`" in
>  	dir/two"$LF"one) echo pass both ;;
>  	*) echo bad; exit 1 ;;

If we were to do this, shouldn't we be able to lose 'cd "$HERE"' at the beginning of each test? The test after this one does "cd dir" without even coming back up and relies on the next one to go back itself, suggesting that grepping for 'cd ..' may not be sufficient, depending on what we are trying to fix.

If we were to insist that no matter how an individual test fail, the test that follows it must start in a known location (namely, $TRASH), then we might want to use something like the attached patch. On the other hand, we might want to be lenient to a test suite whose one test moves around and the test that follows such a test knows that, and also anticipates that the previous one _can_ fail and tries recover from that failure (e.g. use of 'cd "$HERE"' in the test that follows the above one.

Thoughts?
 t/test-lib.sh |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 29fd720..f07f275 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -432,10 +432,14 @@ test_expect_success () {
 	error "bug in the test script: not 2 or 3 parameters to test-expect-success"
 	if ! test_skip "$@"
 	then
+		test ",$TRASH_DIRECTORY" = ",$(pwd)" ||
+		error "bug in the test script: starting from a different directory"
 		say >&3 "expecting success: $2"
 		test_run_ "$2"
 		if [ "$?" = 0 -a "$eval_ret" = 0 ]
 		then
+			test ",$TRASH_DIRECTORY" = ",$(pwd)" ||
+			error "bug in the test script: moved to a different directory"
 			test_ok_ "$1"
 		else
 			test_failure_ "$@"
Previous: Jonathan NiederNext: Jonathan Nieder
Message 23 of 27 in “Several tests: cd inside subshell instead of around”
  1. Several tests: cd inside subshell instead of aroundJens Lehmann, Sep 6, 2010
  2. Jonathan NiederSep 6, 2010
  3. Jens LehmannSep 6, 2010
  4. 0/7 Re: [PATCH] Several tests: cd inside subshell instead of aroundJonathan Nieder, Sep 7, 2010
  5. 1/7 tests: subshell indentation stylefixJonathan Nieder, Sep 7, 2010
  6. Jonathan NiederSep 7, 2010
  7. 2/7 t1450 (fsck): remove dangling objectsJonathan Nieder, Sep 7, 2010
  8. 3/7 t2105 (gitfile): add missing &&Jonathan Nieder, Sep 7, 2010
  9. Brad KingSep 7, 2010
  10. 4/7 t0004 (unwritable files): simplify error handlingJonathan Nieder, Sep 7, 2010
  11. 5/7 t1302 (core.repositoryversion): style tweaksJonathan Nieder, Sep 7, 2010
  12. Nguyen Thai Ngoc DuySep 7, 2010
  13. 6/7 t1303 (config): style tweaksJonathan Nieder, Sep 7, 2010
  14. Jeff KingSep 7, 2010
  15. Junio C HamanoSep 7, 2010
  16. Jonathan NiederSep 7, 2010
  17. guarding everything with test_expect_success (Re: [PATCH 6/7] t1303 (config): style tweaks)Jonathan Nieder, Sep 7, 2010
  18. Jeff KingSep 7, 2010
  19. Jonathan NiederSep 7, 2010
  20. 7/7 t2016 (checkout -p): use printf for multiline y/n inputJonathan Nieder, Sep 7, 2010
  21. Thomas RastSep 7, 2010
  22. Jonathan NiederSep 7, 2010
  23. Junio C HamanoSep 6, 2010
  24. Jonathan NiederSep 7, 2010
  25. Junio C HamanoSep 7, 2010
  26. Jonathan NiederSep 7, 2010
  27. t1020: Get rid of 'cd "$HERE"' at the start of each testJens Lehmann, Sep 7, 2010

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.