All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] t7610 test for mktemp existence
@ 2016-07-02 19:01 Armin Kunaschik
  2016-07-06 18:23 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Armin Kunaschik @ 2016-07-02 19:01 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Jeff King

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>

---

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\"" &&


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] t7610 test for mktemp existence
  2016-07-02 19:01 [PATCH] t7610 test for mktemp existence Armin Kunaschik
@ 2016-07-06 18:23 ` Junio C Hamano
  2016-07-06 19:01   ` Jeff King
  2016-07-06 19:15   ` Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: Junio C Hamano @ 2016-07-06 18:23 UTC (permalink / raw)
  To: Armin Kunaschik; +Cc: Git List, Jeff King

Armin Kunaschik <megabreit@googlemail.com> writes:

> 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.

> 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"


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] t7610 test for mktemp existence
  2016-07-06 18:23 ` Junio C Hamano
@ 2016-07-06 19:01   ` Jeff King
  2016-07-06 19:15   ` Junio C Hamano
  1 sibling, 0 replies; 4+ messages in thread
From: Jeff King @ 2016-07-06 19:01 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Armin Kunaschik, Git List

On Wed, Jul 06, 2016 at 11:23:51AM -0700, Junio C Hamano wrote:

> > -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. :)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] t7610 test for mktemp existence
  2016-07-06 18:23 ` Junio C Hamano
  2016-07-06 19:01   ` Jeff King
@ 2016-07-06 19:15   ` Junio C Hamano
  1 sibling, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2016-07-06 19:15 UTC (permalink / raw)
  To: Armin Kunaschik; +Cc: Git List, Jeff King

Junio C Hamano <gitster@pobox.com> writes:

>> -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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-07-06 19:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-02 19:01 [PATCH] t7610 test for mktemp existence Armin Kunaschik
2016-07-06 18:23 ` Junio C Hamano
2016-07-06 19:01   ` Jeff King
2016-07-06 19:15   ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.