summaryrefslogtreecommitdiff
path: root/t/test-lib-functions.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-02-27 21:27:29 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-02-27 21:58:43 (GMT)
commit11395a3b4b16d9fc637ca2e41a6892ea2e6289ce (patch)
tree81e3d1e93b0025f8b4eafc5dde30f405426140be /t/test-lib-functions.sh
parent38e79b1fdab9244e1727d0698afcf3bb8956c0a4 (diff)
downloadgit-11395a3b4b16d9fc637ca2e41a6892ea2e6289ce.zip
git-11395a3b4b16d9fc637ca2e41a6892ea2e6289ce.tar.gz
git-11395a3b4b16d9fc637ca2e41a6892ea2e6289ce.tar.bz2
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 <gitster@pobox.com>
Diffstat (limited to 't/test-lib-functions.sh')
-rw-r--r--t/test-lib-functions.sh6
1 files changed, 5 insertions, 1 deletions
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 1701fe2..d2eaf5a 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -718,7 +718,11 @@ verbose () {
# otherwise.
test_must_be_empty () {
- if test -s "$1"
+ if ! test -f "$1"
+ then
+ echo "'$1' is missing"
+ return 1
+ elif test -s "$1"
then
echo "'$1' is not empty, it contains:"
cat "$1"