summaryrefslogtreecommitdiff
path: root/t/test-lib.sh
diff options
context:
space:
mode:
authorLibravatar Matthieu Moy <Matthieu.Moy@imag.fr>2010-08-10 17:17:52 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2010-08-11 10:21:36 -0700
commit2caf20c52b7f646d0a7481c25415c48d687773b2 (patch)
tree0d6ea01a4b9cff3719c67ceede9b94f303982941 /t/test-lib.sh
parentrebase -i: add exec command to launch a shell command (diff)
downloadtgif-2caf20c52b7f646d0a7481c25415c48d687773b2.tar.xz
test-lib: user-friendly alternatives to test [-d|-f|-e]
The helper functions are implemented, documented, and used in a few places to validate them, but not everywhere to avoid useless code churn. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/test-lib.sh')
-rw-r--r--t/test-lib.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/t/test-lib.sh b/t/test-lib.sh
index e5523dd690..e913286e2d 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -542,6 +542,38 @@ test_external_without_stderr () {
fi
}
+# debugging-friendly alternatives to "test [-f|-d|-e]"
+# The commands test the existence or non-existence of $1. $2 can be
+# given to provide a more precise diagnosis.
+test_path_is_file () {
+ if ! [ -f "$1" ]
+ then
+ echo "File $1 doesn't exist. $*"
+ false
+ fi
+}
+
+test_path_is_dir () {
+ if ! [ -d "$1" ]
+ then
+ echo "Directory $1 doesn't exist. $*"
+ false
+ fi
+}
+
+test_path_is_missing () {
+ if [ -e "$1" ]
+ then
+ echo "Path exists:"
+ ls -ld "$1"
+ if [ $# -ge 1 ]; then
+ echo "$*"
+ fi
+ false
+ fi
+}
+
+
# This is not among top-level (test_expect_success | test_expect_failure)
# but is a prefix that can be used in the test script, like:
#