Subject: Re: [PATCH 1/2] git submodule: Add test cases for git submodule add

From: Junio C Hamano <[email-masked]>
Date: Wed, 25 Feb 2009 13:24:57 -0800

Michael J Gruber <[email-masked]> writes:

> diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
> index b8cb2df..b154050 100755
> --- a/t/t7400-submodule-basic.sh
> +++ b/t/t7400-submodule-basic.sh
> @@ -47,6 +47,25 @@ test_expect_success 'Prepare submodule testing' '
>  	GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/init.git
>  '

Please don't chdir around in individual tests.  Instead have each test
begin and end in the original directory given.  Like:

> +test_expect_success 'Prepare submodule add testing' '
> +	submodurl=$(pwd)
> +	mkdir addtest &&
> +	pushd addtest &&
> +	git init
> +'

	(
        	mkdir addtest &&
                cd addtest &&
                git init
	)

> +test_expect_success 'submodule add' '
> +	git submodule add "$submodurl" submod &&
> +	git submodule init
> +'

	(
        	cd addtest &&
                git submodule add ...
	)                

> +test_expect_failure 'submodule add with ./ in path' '
> +	git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
> +	git submodule init
> +'
> +# end of submodule add testing
> +popd >/dev/null

The rule of thumb is minimize things done outside of tests, like this
popd.

This is to prevent mistaken test sequence to go up too many levels.  E.g.
an earlier test that is supposed to chdir down and make the subsequent
tests begin at one level deeper than the original could fail, but when
tests are run without the "-i" option, the failed test would not abort the
whole sequence.  The subsequent tests run in a wrong place, and one of
them would try to chdir up to come back to the original directory, but
their "cd .." will go up too high, because the first chdir that tried to
go down failed.