[WIP2 09/12] cli/search: add metadata element to structured output
David Bremner
david at tethera.net
Sun Apr 5 15:59:11 PDT 2015
As before, we force the test suite to use format version 2 in order
not to break. This is probably not the solution for the final version
of these patches.
---
devel/schemata | 10 +++++-----
notmuch-search.c | 18 +++++++++---------
test/T070-insert.sh | 2 +-
test/T090-search-output.sh | 20 ++++++++++----------
test/T095-address.sh | 4 ++--
test/T160-json.sh | 4 ++--
test/T170-sexp.sh | 4 ++--
test/T470-missing-headers.sh | 2 +-
test/test-lib.sh | 8 ++++++++
9 files changed, 40 insertions(+), 32 deletions(-)
diff --git a/devel/schemata b/devel/schemata
index 02f7cc0..e297adf 100644
--- a/devel/schemata
+++ b/devel/schemata
@@ -144,19 +144,19 @@ notmuch search schema
---------------------
# --output=summary
-search_summary = [thread_summary*]
+search_summary = [database_metadata, thread_summary*]
# --output=threads
-search_threads = [threadid*]
+search_threads = [database_metadata, threadid*]
# --output=messages
-search_messages = [messageid*]
+search_messages = [database_metadata, messageid*]
# --output=files
-search_files = [string*]
+search_files = [database_metadata, string*]
# --output=tags
-search_tags = [string*]
+search_tags = [database_metadata, string*]
thread_summary = {
database: database_metadata
diff --git a/notmuch-search.c b/notmuch-search.c
index 994ae58..5d17dac 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -122,7 +122,8 @@ do_search_threads (search_context_t *ctx)
if (threads == NULL)
return 1;
- format->begin_list (format);
+ sprinter_start_output (format, ctx->query,
+ (ctx->output == OUTPUT_THREADS) ? "threads" : "summary");
for (i = 0;
notmuch_threads_valid (threads) && (ctx->limit < 0 || i < ctx->offset + ctx->limit);
@@ -238,8 +239,7 @@ do_search_threads (search_context_t *ctx)
notmuch_thread_destroy (thread);
}
- format->end (format);
-
+ sprinter_finish_output (format);
return 0;
}
@@ -423,7 +423,7 @@ do_search_messages (search_context_t *ctx)
if (messages == NULL)
return 1;
- format->begin_list (format);
+ sprinter_start_output (format, ctx->query, "messages");
for (i = 0;
notmuch_messages_valid (messages) && (ctx->limit < 0 || i < ctx->offset + ctx->limit);
@@ -486,8 +486,7 @@ do_search_messages (search_context_t *ctx)
notmuch_messages_destroy (messages);
- format->end (format);
-
+ sprinter_finish_output (format);
return 0;
}
@@ -505,6 +504,8 @@ do_search_tags (const search_context_t *ctx)
* specified? */
/* Special-case query of "*" for better performance. */
+
+
if (strcmp (notmuch_query_get_query_string (query), "*") == 0) {
tags = notmuch_database_get_all_tags (notmuch);
} else {
@@ -517,7 +518,7 @@ do_search_tags (const search_context_t *ctx)
if (tags == NULL)
return 1;
- format->begin_list (format);
+ sprinter_start_output (format, query, "tags");
for (;
notmuch_tags_valid (tags);
@@ -535,8 +536,7 @@ do_search_tags (const search_context_t *ctx)
if (messages)
notmuch_messages_destroy (messages);
- format->end (format);
-
+ sprinter_finish_output (format);
return 0;
}
diff --git a/test/T070-insert.sh b/test/T070-insert.sh
index 48d36af..67acbb0 100755
--- a/test/T070-insert.sh
+++ b/test/T070-insert.sh
@@ -64,7 +64,7 @@ output=$(notmuch search --output=files "subject:insert-subject" | wc -l)
test_expect_equal "$output" 2
test_begin_subtest "Duplicate message does not change tags"
-output=$(notmuch search --format=json --output=tags "subject:insert-subject")
+output=$(NOTMUCH_SEARCH --format=json --output=tags "subject:insert-subject")
test_expect_equal_json "$output" '["inbox", "unread"]'
test_begin_subtest "Insert message, add tag"
diff --git a/test/T090-search-output.sh b/test/T090-search-output.sh
index fe2ec9a..1dc74b6 100755
--- a/test/T090-search-output.sh
+++ b/test/T090-search-output.sh
@@ -35,7 +35,7 @@ EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "--output=threads --format=json"
-notmuch search --format=json --output=threads '*' | sed -e s/\".*\"/\"THREADID\"/ >OUTPUT
+NOTMUCH_SEARCH --format=json --output=threads '*' | sed -e s/\".*\"/\"THREADID\"/ >OUTPUT
cat <<EOF >EXPECTED
["THREADID",
"THREADID",
@@ -141,7 +141,7 @@ EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "--output=messages --format=json"
-notmuch search --format=json --output=messages '*' >OUTPUT
+NOTMUCH_SEARCH --format=json --output=messages '*' >OUTPUT
cat <<EOF >EXPECTED
["4EFC743A.3060609 at april.org",
"877h1wv7mg.fsf at inf-8657.int-evry.fr",
@@ -199,19 +199,19 @@ EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "--output=messages --format=json --duplicate=1"
-notmuch search --output=messages --format=json --duplicate=1 '*' >OUTPUT
+NOTMUCH_SEARCH --output=messages --format=json --duplicate=1 '*' >OUTPUT
# reuse same EXPECTED as above
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "--output=messages --format=json --duplicate=2"
-notmuch search --output=messages --format=json --duplicate=2 '*' >OUTPUT
+NOTMUCH_SEARCH --output=messages --format=json --duplicate=2 '*' >OUTPUT
cat <<EOF >EXPECTED
["20091117232137.GA7669 at griffis1.net"]
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "--output=messages --format=json --duplicate=3"
-notmuch search --output=messages --format=json --duplicate=3 '*' >OUTPUT
+NOTMUCH_SEARCH --output=messages --format=json --duplicate=3 '*' >OUTPUT
cat <<EOF >EXPECTED
[]
EOF
@@ -338,7 +338,7 @@ EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "--output=files --format=json"
-notmuch search --format=json --output=files '*' | notmuch_search_files_sanitize \
+NOTMUCH_SEARCH --format=json --output=files '*' | notmuch_search_files_sanitize \
| test_sort_json >OUTPUT
cat <<EOF | test_sort_json >EXPECTED
["MAIL_DIR/cur/52:2,",
@@ -398,14 +398,14 @@ EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "--output=files --format=json --duplicate=2"
-notmuch search --format=json --output=files --duplicate=2 '*' | notmuch_search_files_sanitize >OUTPUT
+NOTMUCH_SEARCH --format=json --output=files --duplicate=2 '*' | notmuch_search_files_sanitize >OUTPUT
cat <<EOF >EXPECTED
["$dup2"]
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "--output=tags"
-notmuch search --output=tags '*' >OUTPUT
+NOTMUCH_SEARCH --output=tags '*' >OUTPUT
cat <<EOF >EXPECTED
attachment
inbox
@@ -415,7 +415,7 @@ EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "--output=tags --format=json"
-notmuch search --format=json --output=tags '*' >OUTPUT
+NOTMUCH_SEARCH --format=json --output=tags '*' >OUTPUT
cat <<EOF >EXPECTED
["attachment",
"inbox",
@@ -439,7 +439,7 @@ echo -n >EXPECTED
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "search --format=json for non-existent message prints proper empty json"
-notmuch search --format=json "no-message-matches-this" > OUTPUT
+NOTMUCH_SEARCH --format=json "no-message-matches-this" > OUTPUT
echo "[]" >EXPECTED
test_expect_equal_file OUTPUT EXPECTED
diff --git a/test/T095-address.sh b/test/T095-address.sh
index ed0cac7..6eae30e 100755
--- a/test/T095-address.sh
+++ b/test/T095-address.sh
@@ -33,7 +33,7 @@ notmuch address '*' >OUTPUT
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "--output=sender --format=json"
-notmuch address --output=sender --format=json '*' >OUTPUT
+NOTMUCH_ADDRESS --output=sender --format=json '*' >OUTPUT
cat <<EOF >EXPECTED
[{"name": "François Boulogne", "address": "boulogne.f at gmail.com", "name-addr": "François Boulogne <boulogne.f at gmail.com>"},
{"name": "Olivier Berger", "address": "olivier.berger at it-sudparis.eu", "name-addr": "Olivier Berger <olivier.berger at it-sudparis.eu>"},
@@ -122,7 +122,7 @@ test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "--output=count --format=json"
# Since the iteration order of GHashTable is not specified, we
# preprocess and sort the results to keep the order stable here.
-notmuch address --output=count --format=json '*' | \
+NOTMUCH_ADDRESS --output=count --format=json '*' | \
sed -e 's/^\[//' -e 's/]$//' -e 's/,$//' | sort >OUTPUT
cat <<EOF >EXPECTED
{"name": "Adrian Perez de Castro", "address": "aperez at igalia.com", "name-addr": "Adrian Perez de Castro <aperez at igalia.com>", "count": 1}
diff --git a/test/T160-json.sh b/test/T160-json.sh
index 46c1314..10df42a 100755
--- a/test/T160-json.sh
+++ b/test/T160-json.sh
@@ -18,7 +18,7 @@ test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true
test_begin_subtest "Search message: json"
add_message "[subject]=\"json-search-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"json-search-message\""
-output=$(notmuch search --format=json "json-search-message" | notmuch_search_sanitize)
+output=$(NOTMUCH_SEARCH --format=json "json-search-message" | notmuch_search_sanitize)
test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
\"timestamp\": 946728000,
\"date_relative\": \"2000-01-01\",
@@ -52,7 +52,7 @@ test_expect_equal_json "$output" "[[[{\"id\": \"$id\", \"match\": true, \"exclud
test_begin_subtest "Search message: json, utf-8"
add_message "[subject]=\"json-search-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-search-méssage\""
-output=$(notmuch search --format=json "jsön-search-méssage" | notmuch_search_sanitize)
+output=$(NOTMUCH_SEARCH --format=json "jsön-search-méssage" | notmuch_search_sanitize)
test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
\"timestamp\": 946728000,
\"date_relative\": \"2000-01-01\",
diff --git a/test/T170-sexp.sh b/test/T170-sexp.sh
index 6c7402a..06a7f98 100755
--- a/test/T170-sexp.sh
+++ b/test/T170-sexp.sh
@@ -18,7 +18,7 @@ test_expect_equal "$output" "((((:id \"${gen_msg_id}\" :match t :excluded nil :f
test_begin_subtest "Search message: sexp"
add_message "[subject]=\"sexp-search-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"sexp-search-message\""
-output=$(notmuch search --format=sexp "sexp-search-message" | notmuch_search_sanitize)
+output=$(NOTMUCH_SEARCH --format=sexp "sexp-search-message" | notmuch_search_sanitize)
test_expect_equal "$output" "((:thread \"0000000000000002\" :timestamp 946728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmuch Test Suite\" :subject \"sexp-search-subject\" :query (\"id:$gen_msg_id\" nil) :tags (\"inbox\" \"unread\")))"
test_begin_subtest "Show message: sexp, utf-8"
@@ -43,7 +43,7 @@ test_expect_equal "$output" "((((:id \"$id\" :match t :excluded nil :filename \"
test_begin_subtest "Search message: sexp, utf-8"
add_message "[subject]=\"sexp-search-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-search-méssage\""
-output=$(notmuch search --format=sexp "jsön-search-méssage" | notmuch_search_sanitize)
+output=$(NOTMUCH_SEARCH --format=sexp "jsön-search-méssage" | notmuch_search_sanitize)
test_expect_equal "$output" "((:thread \"0000000000000005\" :timestamp 946728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmuch Test Suite\" :subject \"sexp-search-utf8-body-sübjéct\" :query (\"id:$gen_msg_id\" nil) :tags (\"inbox\" \"unread\")))"
diff --git a/test/T470-missing-headers.sh b/test/T470-missing-headers.sh
index c3ee430..2e24a74 100755
--- a/test/T470-missing-headers.sh
+++ b/test/T470-missing-headers.sh
@@ -29,7 +29,7 @@ thread:XXX 2001-01-05 [1/1] (null); (inbox unread)
thread:XXX 1970-01-01 [1/1] Notmuch Test Suite; (inbox unread)"
test_begin_subtest "Search: json"
-output=$(notmuch search --format=json '*' | notmuch_search_sanitize)
+output=$(NOTMUCH_SEARCH --format=json '*' | notmuch_search_sanitize)
test_expect_equal_json "$output" '
[
{
diff --git a/test/test-lib.sh b/test/test-lib.sh
index d30608a..d9d8ea1 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -664,11 +664,19 @@ test_emacs_expect_t () {
fi
}
+NOTMUCH_ADDRESS () {
+ notmuch address --format-version=2 "${@}"
+}
+
NOTMUCH_NEW ()
{
notmuch new "${@}" | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
}
+NOTMUCH_SEARCH () {
+ notmuch search --format-version=2 "${@}"
+}
+
NOTMUCH_SHOW () {
notmuch show --format-version=2 "${@}"
}
--
2.1.4
More information about the notmuch
mailing list