summaryrefslogtreecommitdiff
path: root/t/test-lib-functions.sh
diff options
context:
space:
mode:
authorJens Lehmann <Jens.Lehmann@web.de>2014-06-19 20:12:23 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-06-20 17:20:42 (GMT)
commit0be7d9b73d21443e216454564dd4df8d2a227789 (patch)
treec6d40d9339f5730593d72ee69768665ff693f439 /t/test-lib-functions.sh
parentcb682f8cfe63ecd0da08a526f404d295e51e3ab1 (diff)
downloadgit-0be7d9b73d21443e216454564dd4df8d2a227789.zip
git-0be7d9b73d21443e216454564dd4df8d2a227789.tar.gz
git-0be7d9b73d21443e216454564dd4df8d2a227789.tar.bz2
test-lib: add test_dir_is_empty()
For the upcoming submodule test framework we often need to assert that an empty directory exists in the work tree. Add the test_dir_is_empty() function which asserts that the given argument is an empty directory. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/test-lib-functions.sh')
-rw-r--r--t/test-lib-functions.sh11
1 files changed, 11 insertions, 0 deletions
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index c617c82..acd9a55 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -489,6 +489,17 @@ test_path_is_dir () {
fi
}
+# Check if the directory exists and is empty as expected, barf otherwise.
+test_dir_is_empty () {
+ test_path_is_dir "$1" &&
+ if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
+ then
+ echo "Directory '$1' is not empty, it contains:"
+ ls -la "$1"
+ return 1
+ fi
+}
+
test_path_is_missing () {
if [ -e "$1" ]
then