unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/2] test: Search for non-existent message should return nothing
@ 2010-11-01 16:15 Michal Sojka
  2010-11-01 16:15 ` [PATCH 2/2] Print nothing when search result is empty Michal Sojka
  2010-11-04 19:39 ` [PATCH 1/2] test: Search for non-existent message should return nothing Carl Worth
  0 siblings, 2 replies; 3+ messages in thread
From: Michal Sojka @ 2010-11-01 16:15 UTC (permalink / raw)
  To: notmuch

My scripts expect that empty search result is actually empty. Since
commit 6dcb7592, even empty search prints a newline character and this
breaks my scripts.

This patch adds a test for this bug. In the test I cannot use
test_expect_equal function as $() operator suppresses the final
newline and this kind of difference is not detected.

 test/search |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
---
 test/search |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/test/search b/test/search
index 9132555..5939c6a 100755
--- a/test/search
+++ b/test/search
@@ -96,4 +96,9 @@ add_message '[subject]="utf8-message-body-subject"' '[date]="Sat, 01 Jan 2000 12
 output=$(notmuch search "bödý" | notmuch_search_sanitize)
 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-message-body-subject (inbox unread)"
 
+test_expect_success "Search for non-existent message prints nothing" '
+echo -n > expected &&
+notmuch search "no-message-matches-this" > actual &&
+test_cmp expected actual'
+
 test_done
-- 
1.7.2.3

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

* [PATCH 2/2] Print nothing when search result is empty
  2010-11-01 16:15 [PATCH 1/2] test: Search for non-existent message should return nothing Michal Sojka
@ 2010-11-01 16:15 ` Michal Sojka
  2010-11-04 19:39 ` [PATCH 1/2] test: Search for non-existent message should return nothing Carl Worth
  1 sibling, 0 replies; 3+ messages in thread
From: Michal Sojka @ 2010-11-01 16:15 UTC (permalink / raw)
  To: notmuch

This change affects both text and json formats. Now, text format
behaves as before commit 6dcb7592, but json format is changed.
Earlier, the empty search returned '[]', now it returns ''. The emacs
interface seems not to be affected by this change.
---
 notmuch-search.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/notmuch-search.c b/notmuch-search.c
index 5907c2e..bb989da 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -189,7 +189,9 @@ do_search_threads (const void *ctx,
     {
 	int first_tag = 1;
 
-	if (! first_thread)
+	if (first_thread)
+	    fputs (format->results_start, stdout);
+	else
 	    fputs (format->item_sep, stdout);
 
 	thread = notmuch_threads_get (threads);
@@ -235,6 +237,9 @@ do_search_threads (const void *ctx,
 	notmuch_thread_destroy (thread);
     }
 
+    if (! first_thread)
+	fputs (format->results_end, stdout);
+
     return 0;
 }
 
@@ -258,7 +263,9 @@ do_search_messages (const void *ctx,
     {
 	message = notmuch_messages_get (messages);
 
-	if (! first_message)
+	if (first_message)
+	    fputs (format->results_start, stdout);
+	else
 	    fputs (format->item_sep, stdout);
 
 	if (output == OUTPUT_FILES) {
@@ -276,6 +283,9 @@ do_search_messages (const void *ctx,
 
     notmuch_messages_destroy (messages);
 
+    if (! first_message)
+	fputs (format->results_end, stdout);
+
     return 0;
 }
 
@@ -415,8 +425,6 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
 
     notmuch_query_set_sort (query, sort);
 
-    fputs (format->results_start, stdout);
-
     switch (output) {
     default:
     case OUTPUT_SUMMARY:
@@ -432,8 +440,6 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
 	break;
     }
 
-    fputs (format->results_end, stdout);
-
     notmuch_query_destroy (query);
     notmuch_database_close (notmuch);
 
-- 
1.7.2.3

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

* Re: [PATCH 1/2] test: Search for non-existent message should return nothing
  2010-11-01 16:15 [PATCH 1/2] test: Search for non-existent message should return nothing Michal Sojka
  2010-11-01 16:15 ` [PATCH 2/2] Print nothing when search result is empty Michal Sojka
@ 2010-11-04 19:39 ` Carl Worth
  1 sibling, 0 replies; 3+ messages in thread
From: Carl Worth @ 2010-11-04 19:39 UTC (permalink / raw)
  To: Michal Sojka, notmuch

[-- Attachment #1: Type: text/plain, Size: 758 bytes --]

On Mon,  1 Nov 2010 17:15:39 +0100, Michal Sojka <sojkam1@fel.cvut.cz> wrote:
> My scripts expect that empty search result is actually empty. Since
> commit 6dcb7592, even empty search prints a newline character and this
> breaks my scripts.

Thanks for this fix, Michal.

I get to apologize doubly on this one.

First, I'm sorry that I was greedy and tried to factor out some common
code, not realizing the bug I introduced in the process.

Second, I'm sorry I didn't get your fix into the 0.4 release, (since I
think you did send it before I wrapped that up).

I've at least pushed your fix now. Thanks especially for including a new
test (and fix!) with your bug report. That's hugely appreciated.

-Carl

-- 
carl.d.worth@intel.com

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

end of thread, other threads:[~2010-11-04 19:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-01 16:15 [PATCH 1/2] test: Search for non-existent message should return nothing Michal Sojka
2010-11-01 16:15 ` [PATCH 2/2] Print nothing when search result is empty Michal Sojka
2010-11-04 19:39 ` [PATCH 1/2] test: Search for non-existent message should return nothing Carl Worth

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