threads / patch / 42766

patcht7610 test for mktemp existence

Subject: [PATCH] t7610 test for mktemp existence

## tl;dr

4 messages between Jul 2, 2016 and Jul 6, 2016. Diffs are folded; open one to read it.

replies: 3people: 3as markdown or json

Armin Kunaschik· Jul 2, 2016, 19:01 UTC · lore
Subject: t7610: test for mktemp before test execution

mktemp is not available on all platforms, so the test 'temporary filenames are used with mergetool.writeToTemp' fails there. This patch does not replace mktemp but just disables the test that otherwise would fail. mergetool checks itself before executing mktemp and reports an error.

Signed-off-by: Armin Kunaschik <megabreit@googlemail.com>
---
Show changes to t/t7610-mergetool.sh +6 −1
diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index 76306cf..9279bf5 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -589,7 +589,12 @@ test_expect_success 'filenames seen by tools start with ./' '
 	git reset --hard master >/dev/null 2>&1
 '

-test_expect_success 'temporary filenames are used with mergetool.writeToTemp' '
+test_lazy_prereq MKTEMP '
+	tempdir=$(mktemp -d -t foo.XXX) &&
+	test -d "$tempdir"
+'
+
+test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' '
 	git checkout -b test16 branch1 &&
 	test_config mergetool.writeToTemp true &&
 	test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
Junio C Hamano· Jul 6, 2016, 18:23 UTC · re: Armin Kunaschik · lore

Re: [PATCH] t7610 test for mktemp existence

Armin Kunaschik <megabreit@googlemail.com> writes:
Show 9 quoted lines
> Subject: t7610: test for mktemp before test execution
>
> mktemp is not available on all platforms, so the test
> 'temporary filenames are used with mergetool.writeToTemp'
> fails there.
> This patch does not replace mktemp but just disables
> the test that otherwise would fail.
> mergetool checks itself before executing mktemp and
> reports an error.
Thanks.
Show 17 quoted lines
> Signed-off-by: Armin Kunaschik <megabreit@googlemail.com>
>
> ---
>
> diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
> index 76306cf..9279bf5 100755
> --- a/t/t7610-mergetool.sh
> +++ b/t/t7610-mergetool.sh
> @@ -589,7 +589,12 @@ test_expect_success 'filenames seen by tools start with ./' '
>  	git reset --hard master >/dev/null 2>&1
>  '
>
> -test_expect_success 'temporary filenames are used with mergetool.writeToTemp' '
> +test_lazy_prereq MKTEMP '
> +	tempdir=$(mktemp -d -t foo.XXX) &&
> +	test -d "$tempdir"
> +'

This makes me wonder what would happen to the leftover directory, though. Would it be a better idea to clean it up as well, i.e.

	tempdir=$(mktemp -d -t foo.XXXXXX) &&
	test -d "$tempdir" &&
        rmdir "$tempdir"
Jeff King· Jul 6, 2016, 19:01 UTC · re: Junio C Hamano · lore

Re: [PATCH] t7610 test for mktemp existence

On Wed, Jul 06, 2016 at 11:23:51AM -0700, Junio C Hamano wrote:
Show 12 quoted lines
> > -test_expect_success 'temporary filenames are used with mergetool.writeToTemp' '
> > +test_lazy_prereq MKTEMP '
> > +	tempdir=$(mktemp -d -t foo.XXX) &&
> > +	test -d "$tempdir"
> > +'
> 
> This makes me wonder what would happen to the leftover directory,
> though.  Would it be a better idea to clean it up as well, i.e.
> 
> 	tempdir=$(mktemp -d -t foo.XXXXXX) &&
> 	test -d "$tempdir" &&
>         rmdir "$tempdir"

Lazy prereq's are computed inside a temporary directory[1] that is automatically cleaned up, so I think the code here does not have to worry about it.

-Peff
[1] Coincidentally, I recently wanted to have a lazy prereq check
    _another_ prereq inside it. But it turns out you cannot do this:
      test_lazy_prereq RECURSE_INNER '
        echo inner >file
      '
      test_lazy_prereq RECURSE_OUTER '
        echo outer >file &&
	test_have_prereq RECURSE_INNER &&
	echo outer >expect &&
	test_cmp expeect file
      '
      test_expect_success 'lazy prereqs can recurse' '
	test_have_prereq RECURSE_OUTER
      '
    because they both use the same temporary directory (so beyond having
    "outer" see "inner" in the file, it actually complains when the
    inner check removes the directory entirely).
    The fix for that is simple: give the tempdir a unique name. But I
    think this kind of recursion is still not OK in the shell because
    without the "local" keyword, we have no concept of stack variables,
    and so stomp on the globals with each iteration.
    Anyway. Not a big deal, and I ended up simplifying my tests not to
    need it. But I was certainly surprised and confused by it at the
    time, so I figured it was worth sharing the knowledge. :)
Junio C Hamano· Jul 6, 2016, 19:15 UTC · re: Junio C Hamano · lore

Re: [PATCH] t7610 test for mktemp existence

Junio C Hamano <gitster@pobox.com> writes:
Show 12 quoted lines
>> -test_expect_success 'temporary filenames are used with mergetool.writeToTemp' '
>> +test_lazy_prereq MKTEMP '
>> +	tempdir=$(mktemp -d -t foo.XXX) &&
>> +	test -d "$tempdir"
>> +'
>
> This makes me wonder what would happen to the leftover directory,
> though.  Would it be a better idea to clean it up as well, i.e.
>
> 	tempdir=$(mktemp -d -t foo.XXXXXX) &&
> 	test -d "$tempdir" &&
>         rmdir "$tempdir"

It turns out that this is not necessary since day one of lazy_prereq. I forgot what I wrote in 04083f27 (test: allow prerequisite to be evaluated lazily, 2012-07-26).

Thanks.

← back to recent threads