git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jens Lehmann <Jens.Lehmann@web.de>
Cc: Git Mailing List <git@vger.kernel.org>,
	Jonathan Nieder p <jrnieder@gmail.com>, Jeff King <peff@peff.net>,
	Heiko Voigt <hvoigt@hvoigt.net>
Subject: Re: [RFC/PATCH 1/4] test-lib: add test_dir_is_empty()
Date: Tue, 25 Mar 2014 13:49:28 -0700	[thread overview]
Message-ID: <xmqq4n2mknqf.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <5331B717.5010600@web.de> (Jens Lehmann's message of "Tue, 25 Mar 2014 18:04:23 +0100")

Jens Lehmann <Jens.Lehmann@web.de> 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@web.de>
> ---
>
> 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

  reply	other threads:[~2014-03-25 20:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-25 17:03 [RFC/PATCH 0/4] Add submodule test harness Jens Lehmann
2014-03-25 17:04 ` [RFC/PATCH 1/4] test-lib: add test_dir_is_empty() Jens Lehmann
2014-03-25 20:49   ` Junio C Hamano [this message]
2014-03-25 21:06     ` David Kastrup
2014-03-26  8:29     ` Jens Lehmann
2014-03-26 10:43       ` Michael Haggerty
2014-03-26 19:22         ` Jens Lehmann
2014-03-25 17:05 ` [RFC/PATCH 2/4] Submodules: Add the lib-submodule-update.sh test library Jens Lehmann
2014-04-17 16:41   ` W. Trevor King
2014-04-17 19:23     ` Junio C Hamano
2014-04-17 21:30       ` Jens Lehmann
2014-04-18 12:39         ` Heiko Voigt
2014-04-17 21:08     ` Jens Lehmann
2014-04-17 21:55       ` W. Trevor King
2014-04-18 12:31         ` Jens Lehmann
2014-03-25 17:05 ` [RFC/PATCH 3/4] checkout: call the new submodule update test framework Jens Lehmann
2014-03-25 17:06 ` [RFC/PATCH 4/4] apply: add t4137 for submodule updates Jens Lehmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq4n2mknqf.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=hvoigt@hvoigt.net \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).