git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] t7610 test for mktemp existence

From
Jeff King <peff@peff.net>
Date
Jul 6, 2016, 19:01 UTC
Message-ID
<20160706190158.GA31148@sigill.intra.peff.net>
In-Reply-To
<xmqqr3b6sk08.fsf@gitster.mtv.corp.google.com>
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. :)
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 4 in “t7610 test for mktemp existence”
  1. t7610 test for mktemp existenceArmin Kunaschik, Jul 2, 2016
  2. Junio C HamanoJul 6, 2016
  3. Jeff KingJul 6, 2016
  4. Junio C HamanoJul 6, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.