# [PATCH v2 1/3] Enhance test t3700-add.sh

2 messages from 2016-07-29 to 2016-07-29. Participants: Ingo Brückl, Junio C Hamano.
Thread: https://gitlist.dev/t/42964

## Ingo Brückl, 2016-07-29 21:09

Subject: [PATCH v2 1/3] Enhance test t3700-add.sh
Message-ID: <579bc6ca.10e2ad4d.bm000@wupperonline.de>
URL: https://gitlist.dev/e/579bc6ca.10e2ad4d.bm000%40wupperonline.de

```
The files to be tested may already exist and be links which will make
the test fail. So ensure that we are working in a clean environment.

Signed-off-by: Ingo Brückl <ib@wupperonline.de>
---
 t/t3700-add.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 4865304..494f5b8 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -333,6 +333,7 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file out
 '

 test_expect_success 'git add --chmod=+x stages a non-executable file with +x' '
+	rm -f foo1 &&
 	echo foo >foo1 &&
 	git add --chmod=+x foo1 &&
 	case "$(git ls-files --stage foo1)" in
@@ -342,6 +343,7 @@ test_expect_success 'git add --chmod=+x stages a non-executable file with +x' '
 '

 test_expect_success 'git add --chmod=-x stages an executable file with -x' '
+	rm -f xfoo1 &&
 	echo foo >xfoo1 &&
 	chmod 755 xfoo1 &&
 	git add --chmod=-x xfoo1 &&
@@ -354,6 +356,7 @@ test_expect_success 'git add --chmod=-x stages an executable file with -x' '
 test_expect_success POSIXPERM,SYMLINKS 'git add --chmod=+x with symlinks' '
 	git config core.filemode 1 &&
 	git config core.symlinks 1 &&
+	rm -f foo2 &&
 	echo foo >foo2 &&
 	git add --chmod=+x foo2 &&
 	case "$(git ls-files --stage foo2)" in
--
2.9.2


```

## Junio C Hamano, 2016-07-29 21:57

Subject: Re: [PATCH v2 1/3] Enhance test t3700-add.sh
Message-ID: <xmqq60rom7jv.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq60rom7jv.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <579bc6ca.10e2ad4d.bm000@wupperonline.de>

```
Ingo Brückl <ib@wupperonline.de> writes:

> Subject: Re: [PATCH v2 1/3] Enhance test t3700-add.sh
>
> The files to be tested may already exist and be links which will make
> the test fail. So ensure that we are working in a clean environment.

"Enhance", like "Update" or "Change", is a more-or-less useless
noiseword in a commit title; it does not say much about in what way
it was enhanced.

If we clarify the body of the explanation, a better word emerges, I
would think.  How about this instead?

	t3700: remove unwanted leftover files before running new tests

	When an earlier test that has prerequisite is skipped, files
	used by later tests may be left in the working tree in an
	unexpected state.  For example, a test runs this sequence:

		echo foo >xfoo1 && chmod 755 xfoo1

	to create an executable file xfoo1, expecting that xfoo1
	does not exist before it runs in the test sequence.
	However, the absense of this file depends on "git reset
	--hard" done in an earlier test, that is skipped when SANITY
	prerequisite is not met, and worse yet, xfoo1 originally is
	created as a symbolic link, which means the chmod does not
	affect the modes of xfoo1 as this test expects.

	Fix this by starting the test with "rm -f xfoo1" to make
	sure the file is created from scratch, and do the same to
	other similar tests.

>
> Signed-off-by: Ingo Brückl <ib@wupperonline.de>
> ---
>  t/t3700-add.sh | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/t/t3700-add.sh b/t/t3700-add.sh
> index 4865304..494f5b8 100755
> --- a/t/t3700-add.sh
> +++ b/t/t3700-add.sh
> @@ -333,6 +333,7 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file out
>  '
>
>  test_expect_success 'git add --chmod=+x stages a non-executable file with +x' '
> +	rm -f foo1 &&
>  	echo foo >foo1 &&
>  	git add --chmod=+x foo1 &&
>  	case "$(git ls-files --stage foo1)" in
> @@ -342,6 +343,7 @@ test_expect_success 'git add --chmod=+x stages a non-executable file with +x' '
>  '
>
>  test_expect_success 'git add --chmod=-x stages an executable file with -x' '
> +	rm -f xfoo1 &&
>  	echo foo >xfoo1 &&
>  	chmod 755 xfoo1 &&
>  	git add --chmod=-x xfoo1 &&
> @@ -354,6 +356,7 @@ test_expect_success 'git add --chmod=-x stages an executable file with -x' '
>  test_expect_success POSIXPERM,SYMLINKS 'git add --chmod=+x with symlinks' '
>  	git config core.filemode 1 &&
>  	git config core.symlinks 1 &&
> +	rm -f foo2 &&
>  	echo foo >foo2 &&
>  	git add --chmod=+x foo2 &&
>  	case "$(git ls-files --stage foo2)" in
> --
> 2.9.2

```
