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>
Jens Lehmann committed
Jun 19, 2014 at 22:12 UTC
0be7d9b73d21443e216454564dd4df8d2a227789
1 file changed
+11
t/test-lib-functions.sh
+11
@@ -489,6 +489,17 @@ test_path_is_dir () {
489
fi
490
}
491
492
+# Check if the directory exists and is empty as expected, barf otherwise.
493
+test_dir_is_empty () {
494
+ test_path_is_dir "$1" &&
495
+ if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
496
+ then
497
+ echo "Directory '$1' is not empty, it contains:"
498
+ ls -la "$1"
499
+ return 1
500
+ fi
501
+}
502
+
503
test_path_is_missing () {
504
if [ -e "$1" ]
505
then