Re: [RFC/PATCH 1/4] test-lib: add test_dir_is_empty()
Am 26.03.2014 11:43, schrieb Michael Haggerty:
Show 35 quoted lines
> On 03/26/2014 09:29 AM, Jens Lehmann wrote:
>> Am 25.03.2014 21:49, schrieb Junio C Hamano:
>>> Jens Lehmann <Jens.Lehmann@web.de> writes:
>>>> 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
>
> Why not do something like
>
> test -z "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
>
> I.e., make the test ignore "." and ".." without depending on their
> existence?Thanks, will do so in the next round.