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 2/4] test: define test_expect_equal_message_body
Date: Fri, 21 Jan 2022 00:16:49 +0200	[thread overview]
Message-ID: <m2o846aw8e.fsf@guru.guru-group.fi> (raw)
In-Reply-To: <20220120123354.3999579-3-david@tethera.net>

On Thu, Jan 20 2022, David Bremner wrote:

> This is a relatively simple sed invocation, but rather than write a
> comment everywhere, give it a descriptive name.
> ---
>  test/test-lib.sh | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index f1275b85..661c0dd5 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -432,6 +432,20 @@ test_expect_equal_file () {
>      test_diff_file_ "$1" "$2"
>  }
>  
> +# Like test_expect_equal_file, but compare the part of the two files after the first blank line
> +test_expect_equal_message_body () {
> +    exec 1>&6 2>&7		# Restore stdout and stderr
> +    if [ -z "$inside_subtest" ]; then
> +	error "bug in the test script: test_expect_equal_file without test_begin_subtest"
> +    fi
> +    test "$#" = 2 ||
> +	error "bug in the test script: not 2 parameters to test_expect_equal_file"
> +
> +    expected=$(sed -n '/^$/,$p' $1)
> +    output=$(sed -n '/^$/,$p' $2)

The above works, as we don't have whitespace ($IFS characters to be
precise) in the filenames. However, for better example, "$1" and "$2"
should be used (as is used in many of the functions in test-lib.sh
already. 
The above prints out also the leading newline (which is OK), but if
one wanted those w/o the leading newline, the sed lines would be:
sed '1,/^$/d'

(If I did not come out with this notion of extra newline I would
not have shown this -- as the original sed -n ... matches more to 
"showing body" than "deleting header" :D)

Tomi

> +    test_expect_equal "$expected" "$output"
> +}
> +
>  # Like test_expect_equal, but takes two filenames. Fails if either is empty
>  test_expect_equal_file_nonempty () {
>      exec 1>&6 2>&7		# Restore stdout and stderr
> -- 
> 2.34.1

  reply	other threads:[~2022-01-20 22:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20 12:33 fix Fcc of signed / encrypted messages David Bremner
2022-01-20 12:33 ` [PATCH 1/4] test/emacs: match mml settings in emacs_{fcc,deliver}_message David Bremner
2022-01-20 12:33 ` [PATCH 2/4] test: define test_expect_equal_message_body David Bremner
2022-01-20 22:16   ` Tomi Ollila [this message]
2022-01-22  2:56     ` David Bremner
2022-01-20 12:33 ` [PATCH 3/4] test/emacs: known broken test for matching fcc and sent message David Bremner
2022-01-20 12:33 ` [PATCH 4/4] emacs: use cached encoded copy for fcc David Bremner
2022-01-26 11:38 ` fix Fcc of signed / encrypted messages 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=m2o846aw8e.fsf@guru.guru-group.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).