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>
This commit is contained in:

committed by
Junio C Hamano

parent
cb682f8cfe
commit
0be7d9b73d
@ -489,6 +489,17 @@ test_path_is_dir () {
|
|||||||
fi
|
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 () {
|
test_path_is_missing () {
|
||||||
if [ -e "$1" ]
|
if [ -e "$1" ]
|
||||||
then
|
then
|
||||||
|
Reference in New Issue
Block a user