unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: Re: [PATCH v3 1/5] test: use bash specific test for feature tests
Date: Thu, 13 Apr 2023 22:24:56 +0300	[thread overview]
Message-ID: <y2yic7x.cs3jet-too@iki.fi> (raw)
In-Reply-To: <20230409142627.2216080-2-david@tethera.net>

On Sun, Apr 09 2023, David Bremner wrote:

> It is desirable to have the tests consider these variables being
> undefined as equivalent to the feature not being present, and in
> particular for the tests not to generate errors.
>
> We know the test suite is tied to bash anyway, so this is a simple
> fix.
> ---
>  test/T060-count.sh               | 2 +-
>  test/T081-sexpr-search.sh        | 2 +-
>  test/T150-tagging.sh             | 2 +-
>  test/T160-json.sh                | 2 +-
>  test/T220-reply.sh               | 2 +-
>  test/T240-dump-restore.sh        | 2 +-
>  test/T391-python-cffi.sh         | 3 +--
>  test/T392-python-cffi-notmuch.sh | 2 +-
>  test/T520-show.sh                | 2 +-
>  test/T570-revision-tracking.sh   | 2 +-
>  test/T700-reindex.sh             | 2 +-
>  test/T800-asan.sh                | 2 +-
>  test/T810-tsan.sh                | 2 +-
>  test/T850-git.sh                 | 2 +-
>  14 files changed, 14 insertions(+), 15 deletions(-)
>
> diff --git a/test/T060-count.sh b/test/T060-count.sh
> index 48146706..4499b4cb 100755
> --- a/test/T060-count.sh
> +++ b/test/T060-count.sh
> @@ -157,7 +157,7 @@ print("4: {} messages".format(query.count_messages()))
>  EOF
>  test_expect_equal_file EXPECTED OUTPUT
>  
> -if [ $NOTMUCH_HAVE_SFSEXP -eq 1 ]; then
> +if [[ $NOTMUCH_HAVE_SFSEXP -eq 1 ]]; then

Hmm, I send reply to Felipe's email, before seeing this, so this is
followup ... which, at the end, reaches the same "conclusion" :D

anyway, while this is good progress the [[ $v -eq 1 ]] is still somewhat
fragile (using -eu shows some interesting behaviors):

the easy try: 

  $ bash -eu -c ' [[ $AAA -ne 1 ]] && echo 1 || echo 0'
  bash: line 1: AAA: unbound variable

weirder...:

  $ bash -eu -c 'a="x"; [[ $a -eq 2 ]]' 
  bash: line 1: x: unbound variable

wat, as $a is not numeric, it tries to re-eval $x ???

  $ bash -eu -c 'x=3; a="x"; [[ $a -eq 2 ]] && echo 1 || echo 0'
  0
  $ bash -eu -c 'x=2; a="x"; [[ $a -eq 2 ]] && echo 1 || echo 0' 
  1

for reference

  $ bash -eu -c 'a="2"; [[ $a -eq 2 ]] && echo 1 || echo 0'
  1


and again, w/ = instead of -eq

  $ bash -eu -c 'a="x"; [[ $a = 2 ]] && echo 1 || echo 0'
  0

and -- modified the first AAA case above:

  $ bash -eu -c ' AAA=b; [[ ${AAA-} = 1 ]] && echo 1 || echo 0'
  0

hmm, when using [[ ]] I recall == and != were to used... uh, see 
bash manual about the pattern matching and such... tried also
with (( ... )) (documenter before [[ ]] in bash manual page 
but now it fails even heavier..:

  $ bash -eu -c 'XXX="a"; (( ${XXX-} == 2 )) && echo 1 || echo 0'
  bash: line 1: a: unbound variable

  $ bash -eu -c 'a=2; XXX="a"; (( ${XXX-} == 2 )) && echo 1 || echo 0' 
  1

I would just use [ "${VAR-}" = 1 ] in shell script code (or barely
[[ ${VAR-0} == 1 ]] if desired not to have ""s around variables...but...)

... using [ "${VAR-}" = 1 ] is also good in a sense that someone may
use it as an example to write shell scripts with #!/bin/sh as a
hashbang -- and it works fine on Fedora since there /bin/sh is bash,
but would fail on Debian since there /bin/sh is dash.

HTH ;D

Tomi

  parent reply	other threads:[~2023-04-13 19:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-09 14:26 v3 test notmuch as installed David Bremner
2023-04-09 14:26 ` [PATCH v3 1/5] test: use bash specific test for feature tests David Bremner
2023-04-13 12:22   ` Felipe Contreras
2023-04-13 18:56     ` Tomi Ollila
2023-04-13 19:24   ` Tomi Ollila [this message]
2023-04-14  0:30     ` Felipe Contreras
2023-04-09 14:26 ` [PATCH v3 2/5] test: check for empty/missing files in test_expect_equal_message_body David Bremner
2023-04-09 14:26 ` [PATCH v3 3/5] test: Guess a value for NOTMUCH_PYTHON David Bremner
2023-04-09 14:26 ` [PATCH v3 4/5] test: support testing notmuch as installed David Bremner
2023-04-09 14:26 ` [PATCH v3 5/5] debian: add autopkgtests David Bremner

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

  List information: https://notmuchmail.org/

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

  git send-email \
    --in-reply-to=y2yic7x.cs3jet-too@iki.fi \
    --to=tomi.ollila@iki.fi \
    --cc=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

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 read-only IMAP folder(s) and NNTP newsgroup(s).