Re: [PATCH 03/13] test: remove USER_FULL_NAME when not present

Subject: Re: [PATCH 03/13] test: remove USER_FULL_NAME when not present

Date: Sat, 01 May 2021 23:13:55 +0300

To: Felipe Contreras, notmuch@notmuchmail.org

Cc: Daniel Kahn Gillmor

From: Tomi Ollila


On Sat, May 01 2021, Felipe Contreras wrote:

> If a full name is not configured, the output is empty.

> This is possibly not portable, but it's a start.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  test/T590-libconfig.sh | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
> index 51dd29c8..36d9af1b 100755
> --- a/test/T590-libconfig.sh
> +++ b/test/T590-libconfig.sh
> @@ -5,6 +5,14 @@ test_description="library config API"
>  
>  add_email_corpus
>  
> +get_name () {
> +    if hash getent 2>/dev/null; then
> +        getent passwd "$USER" | cut -d ':' -f 5
> +    else
> +        echo "Foo Bar"
> +    fi
> +}

I'd do

if test -n "$(getent passwd "$USER" | cut -d ':' -f 5)
then
        USER_FULL_NAME=USER_FULL_NAME
else
        USER_FULL_NAME=
fi

and then e.g.

cat <<"EOF" >EXPECTED
== stdout ==
MAIL_DIR
...
$USER_FULL_NAME
== stderr ==
EOF

if getent does not exist, then we'd get empty string
and $USER_FULL_NAME empty (as good as "Foo bar")


> +
>  cat <<EOF > c_head
>  #include <string.h>
>  #include <stdlib.h>
> @@ -402,6 +410,7 @@ NULL
>  USER_FULL_NAME
>  == stderr ==
>  EOF
> +test "$(get_name)" = "" && sed -e "s/USER_FULL_NAME//" -i EXPECTED
>  unset MAILDIR
>  test_expect_equal_file EXPECTED OUTPUT.clean
>  
> @@ -744,6 +753,7 @@ NULL
>  USER_FULL_NAME
>  == stderr ==
>  EOF
> +test "$(get_name)" = "" && sed -e "s/USER_FULL_NAME//" -i EXPECTED
>  test_expect_equal_file EXPECTED OUTPUT.clean
>  
>  backup_database
> -- 
> 2.31.0
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: