From: Jens Lehmann Date: Thu, 19 Jun 2014 20:12:23 GMT Subject: [PATCH v2 01/14] test-lib: add test_dir_is_empty() Message-ID: <53A34427.6010704@web.de> In-Reply-To: <539DD068.6020301@web.de> 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 --- Changes to v1: *) Added "-n" to test expression (you have this as "SQUASH???" commit in pu) t/test-lib-functions.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 -- 2.0.0.406.gf4dce28