git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Armin Kunaschik <megabreit@googlemail.com>,
	Git List <git@vger.kernel.org>
Subject: Re: [PATCH] t7610 test for mktemp existence
Date: Wed, 6 Jul 2016 15:01:58 -0400	[thread overview]
Message-ID: <20160706190158.GA31148@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqqr3b6sk08.fsf@gitster.mtv.corp.google.com>

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

  reply	other threads:[~2016-07-06 19:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2016-07-06 19:15   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160706190158.GA31148@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=megabreit@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).