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
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org