unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] test: sort the output of the "prefix" test in T610-message-property as needed
@ 2020-04-17 21:13 Olivier Taïbi
  2020-04-18 10:17 ` Tomi Ollila
  0 siblings, 1 reply; 2+ messages in thread
From: Olivier Taïbi @ 2020-04-17 21:13 UTC (permalink / raw)
  To: notmuch

the "prefix" test in T610-message-property extracts values from a
(key,value) map where multiple entries can have the same key, and the
entries are sorted by key, but not by value.  The test incorrectly
assumes that the values will be sorted as well, so correct this by
splitting the output using head and tail and sorting each chunk using
sort.
NB: the relevant key/values are as follows.
testkey1: alice, testvalue1, testvalue2, bob
testkey3: alice3, bob3, testvalue3
---
 test/T610-message-property.sh | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/test/T610-message-property.sh b/test/T610-message-property.sh
index 53a0be3b..e1be2fc3 100755
--- a/test/T610-message-property.sh
+++ b/test/T610-message-property.sh
@@ -186,6 +186,11 @@ EXPECT0(notmuch_message_add_property (message, "testkey3", "testvalue3"));
 EXPECT0(notmuch_message_add_property (message, "testkey3", "alice3"));
 print_properties (message, "testkey", FALSE);
 EOF
+mv OUTPUT unsorted_OUTPUT
+head -n 5 unsorted_OUTPUT | sort >OUTPUT
+tail -n +6 unsorted_OUTPUT | head -n 3 | sort >>OUTPUT
+tail -n +9 unsorted_OUTPUT >>OUTPUT
+rm unsorted_OUTPUT
 cat <<'EOF' >EXPECTED
 == stdout ==
 alice
-- 
2.26.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] test: sort the output of the "prefix" test in T610-message-property as needed
  2020-04-17 21:13 [PATCH] test: sort the output of the "prefix" test in T610-message-property as needed Olivier Taïbi
@ 2020-04-18 10:17 ` Tomi Ollila
  0 siblings, 0 replies; 2+ messages in thread
From: Tomi Ollila @ 2020-04-18 10:17 UTC (permalink / raw)
  To: Olivier Taïbi, notmuch

On Fri, Apr 17 2020, Olivier Taïbi wrote:

> the "prefix" test in T610-message-property extracts values from a
> (key,value) map where multiple entries can have the same key, and the
> entries are sorted by key, but not by value.  The test incorrectly
> assumes that the values will be sorted as well, so correct this by
> splitting the output using head and tail and sorting each chunk using
> sort.
> NB: the relevant key/values are as follows.
> testkey1: alice, testvalue1, testvalue2, bob
> testkey3: alice3, bob3, testvalue3
> ---
>  test/T610-message-property.sh | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/test/T610-message-property.sh b/test/T610-message-property.sh
> index 53a0be3b..e1be2fc3 100755
> --- a/test/T610-message-property.sh
> +++ b/test/T610-message-property.sh
> @@ -186,6 +186,11 @@ EXPECT0(notmuch_message_add_property (message, "testkey3", "testvalue3"));
>  EXPECT0(notmuch_message_add_property (message, "testkey3", "alice3"));
>  print_properties (message, "testkey", FALSE);
>  EOF

Whichever way done, this should be commented here, not (just) in git
history, that information is not readily available (one has to know
git blame and then go to see to the commit message :)

> +mv OUTPUT unsorted_OUTPUT
> +head -n 5 unsorted_OUTPUT | sort >OUTPUT

Relying that '== stdout ==' sorts first is kinda ugly, as it does not
be part of the sorting range, 

> +tail -n +6 unsorted_OUTPUT | head -n 3 | sort >>OUTPUT

if there were more content in file i would have suggested `sed -n 6,9p`

> +tail -n +9 unsorted_OUTPUT >>OUTPUT
> +rm unsorted_OUTPUT

due to the '== stdout ==' I'd suggest:

awk ' NR == 1 { print; next }
      NR < 6  { print | "sort"; next }
      NR == 6 { close("sort") }
      NR < 9  { print | "sort"; next }
      NR == 9 { close("sort") }
      { print }' unsorted_OUTPUT > OUTPUT

(works w/ gawk and mawk), with some explanation why.

(perhaps how the sorting is done does not need to be explained in commit
message =D

>  cat <<'EOF' >EXPECTED
>  == stdout ==
>  alice
> -- 
> 2.26.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-18 10:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-17 21:13 [PATCH] test: sort the output of the "prefix" test in T610-message-property as needed Olivier Taïbi
2020-04-18 10:17 ` Tomi Ollila

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).