Re: [PATCH 01/14] test-lib: add test_dir_is_empty()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 16, 2014, 22:05 UTC
- Message-ID
- <xmqq7g4gpl1g.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <539DD068.6020301@web.de>
Jens Lehmann <Jens.Lehmann@web.de> writes:
Show 21 quoted lines
> 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>
> ---
> 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..546f0a6 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" | egrep -v '^\.\.?$')"It is safer to say "test -n" when testing an emptyness of a string whose contents you do not know or control (e.g. the string may begin with "-something").
Show 10 quoted lines
> + then
> + echo "Directory '$1' is not empty, it contains:"
> + ls -la "$1"
> + return 1
> + fi
> +}
> +
> test_path_is_missing () {
> if [ -e "$1" ]
> then