Skip to content

Commit 11395a3

Browse files
committed
test_must_be_empty: make sure the file exists, not just empty
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 <[email protected]>
1 parent 38e79b1 commit 11395a3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

t/test-lib-functions.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,11 @@ verbose () {
718718
# otherwise.
719719

720720
test_must_be_empty () {
721-
if test -s "$1"
721+
if ! test -f "$1"
722+
then
723+
echo "'$1' is missing"
724+
return 1
725+
elif test -s "$1"
722726
then
723727
echo "'$1' is not empty, it contains:"
724728
cat "$1"

0 commit comments

Comments
 (0)