Jens Lehmann <Jens.Lehmann@xxxxxx> writes: > 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@xxxxxx> > --- > > I believe this one is pretty straightforward (unless I missed that this > functionality already exists someplace I forgot to look ;-). I am not very thrilled to see that it depends on "." and ".." to always exist, which may be true for all POSIX filesystems, but still... Do expected callsites of this helper care if "$1" is a symbolic link that points at an empty directory? What do expected callsites really want to ensure? In other words, why do they care if the directory is empty? Is it to make sure, after some operation, they can "rmdir" the directory? > 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 158e10a..93d10cd 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 $(ls -a1 "$1" | wc -l) != 2 > + then > + echo "Directory '$1' is not empty, it contains:" > + ls -la "$1" > + return 1 > + fi > +} > + > test_path_is_missing () { > if [ -e "$1" ] > then -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html