Re: [PATCH] t7610 test for mktemp existence

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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. :)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]