Re: [PATCH] test_must_be_empty: make sure the file exists, not just empty
- From
Jeff King <peff@peff.net>
- Date
- Feb 27, 2018, 22:08 UTC
- Message-ID
- <20180227220821.GC11187@sigill.intra.peff.net>
- In-Reply-To
- <xmqqh8q2p1ha.fsf_-_@gitster-ct.c.googlers.com>
On Tue, Feb 27, 2018 at 01:27:29PM -0800, Junio C Hamano wrote:
Show 20 quoted lines
> The helper function test_must_be_empty is meant to make sure the > given file is empty, but its implementation is: > > if test -s "$1" > then > ... not empty, we detected a failure ... > fi > > Surely, the file having non-zero size is a sign that the condition > "the file must be empty" is violated, but it misses the case where > the file does not even exist. It is an accident waiting to happen > with a buggy test like this: > > git frotz 2>error-message && > test_must_be_empty errro-message > > that won't get caught until you deliberately break 'git frotz' and > notice why the test does not fail. > > Signed-off-by: Junio C Hamano <gitster@pobox.com>
This seems like a huge and obvious improvement to me. I'm amazed it hasn't come up before (and that this doesn't reveal any existing typos like the one you showed).
-Peff