[PATCH] test: Add test for messages with missing headers
Hi This generally looks good but there is a bug in the test from a hardcoded /tmp/ path (see below). And as confirmation with the patch in id:"874noe1o0r.fsf at qmul.ac.uk" the tests (modulo the test bug) pass. On Tue, 07 Aug 2012, Austin Clements wrote: > Currently the JSON tests for search and show are broken because > notmuch attempts to dereference a NULL pointer. > --- > Things to bikeshed: > > * Should we include From and Subject in the headers object when there > are no from or subject headers? Currently the schema says that > everything but those two and "Date" is optional (indeed, "To" is > missing from the second message) but that was just post facto > standardization. I think Date and From are compulsory in an email but the others are not (but I am unsure which Date and which From so that may be unhelpful). If I am correct it might be sensible to always include those two. > * How should we format expected JSON in the test suite, now that we > can format it however we want? Here I've just pasted in the result > of python -mjson.tool. While that was very easy and the result is > quite readable, it's the antithesis of compact and the keys have > been alphabetized. I like this: making the tests readable is a big plus. > test/missing-headers | 162 > ++ > test/notmuch-test|1 + > 2 files changed, 163 insertions(+) > create mode 100755 test/missing-headers > > diff --git a/test/missing-headers b/test/missing-headers > new file mode 100755 > index 000..744c04e > --- /dev/null > +++ b/test/missing-headers > @@ -0,0 +1,162 @@ > +#!/usr/bin/env bash > +test_description='messages with missing headers' > +. ./test-lib.sh > + > +# Notmuch requires at least one of from, subject, or to or it will > +# ignore the file. Generate two messages so that together they cover > +# all possible missing headers. We also give one of the messages a > +# date to ensure stable result ordering. > + > +cat < "${MAIL_DIR}/msg-2" > +To: Notmuch Test Suite > +Date: Fri, 05 Jan 2001 15:43:57 + > + > +Body > +EOF > + > +cat < "${MAIL_DIR}/msg-1" > +From: Notmuch Test Suite > + > +Body > +EOF > + > +NOTMUCH_NEW > + > +test_begin_subtest "Search: text" > +output=$(notmuch search '*' | notmuch_search_sanitize) > +test_expect_equal "$output" "\ > +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" > +test_subtest_known_broken > +output=$(notmuch search --format=json '*' | notmuch_search_sanitize) > +test_expect_equal_json "$output" ' > +[ > +{ > +"authors": "", > +"date_relative": "2001-01-05", > +"matched": 1, > +"subject": "", > +"tags": [ > +"inbox", > +"unread" > +], > +"thread": "XXX", > +"timestamp": 978709437, > +"total": 1 > +}, > +{ > +"authors": "Notmuch Test Suite", > +"date_relative": "1970-01-01", > +"matched": 1, > +"subject": "", > +"tags": [ > +"inbox", > +"unread" > +], > +"thread": "XXX", > +"timestamp": 0, > +"total": 1 > +} > +]' > + > +test_begin_subtest "Show: text" > +output=$(notmuch show '*') > +test_expect_equal "$output" "\ > +message{ id:notmuch-sha1-7a6e4eac383ef958fcd3ebf2143db71b8ff01161 depth:0 > match:1 excluded:0 filename:/tmp/nmtest/tmp.missing-headers/mail/msg-2 The filename above has not been sanitised so contains your tmp path. Best wishes Mark > +header{ > + (2001-01-05) (inbox unread) > +Subject: (null) > +From: (null) > +To: Notmuch Test Suite > +Date: Fri, 05 Jan 2001 15:43:57 + > +header} > +body{ > +part{ ID: 1, Content-type: text/plain > +Body > +part} > +body} > +message} > +message{ id:notmuch-sha1-ca55943aff7a72baf2ab21fa74fab3d632401334 depth:0 > match:1 excluded:0 filename:/tmp/nmtest/tmp.missing-headers/mail/msg-1 > +header{ > +Notmuch Test Suite (1970-01-01) (inbox > unread) > +Subject: (null) > +From: Notmuch Test Suite > +Date: Thu, 01 Jan 1970 00:00:00 + > +header} > +body{ > +part{ ID: 1, Content-type: text/plain > +Body > +part} > +body} > +message}" > + > +test_begin_subtest "Show: json" > +test_subtest_known_broken > +output=$(notmuch show --format=json '*' | notmuch_json_show_sanitize) > +test_expect_equal_json "$output" ' > +[ > +[ > +[ > +{ > +"body": [ > +{ > +"content": "Body\n", > +"content-type": "text/plain", > +"id": 1 > +} > +], > +"date_relative": "2001-01-05", > +"excluded": false, > +"filename": "Y", > +"headers": { > +"Date": "Fri, 05 Jan 2001 15:43:57 +", > +
[PATCH] test: Add test for messages with missing headers
Currently the JSON tests for search and show are broken because notmuch attempts to dereference a NULL pointer. --- Things to bikeshed: * Should we include From and Subject in the headers object when there are no from or subject headers? Currently the schema says that everything but those two and "Date" is optional (indeed, "To" is missing from the second message) but that was just post facto standardization. * How should we format expected JSON in the test suite, now that we can format it however we want? Here I've just pasted in the result of python -mjson.tool. While that was very easy and the result is quite readable, it's the antithesis of compact and the keys have been alphabetized. test/missing-headers | 162 ++ test/notmuch-test|1 + 2 files changed, 163 insertions(+) create mode 100755 test/missing-headers diff --git a/test/missing-headers b/test/missing-headers new file mode 100755 index 000..744c04e --- /dev/null +++ b/test/missing-headers @@ -0,0 +1,162 @@ +#!/usr/bin/env bash +test_description='messages with missing headers' +. ./test-lib.sh + +# Notmuch requires at least one of from, subject, or to or it will +# ignore the file. Generate two messages so that together they cover +# all possible missing headers. We also give one of the messages a +# date to ensure stable result ordering. + +cat < "${MAIL_DIR}/msg-2" +To: Notmuch Test Suite +Date: Fri, 05 Jan 2001 15:43:57 + + +Body +EOF + +cat < "${MAIL_DIR}/msg-1" +From: Notmuch Test Suite + +Body +EOF + +NOTMUCH_NEW + +test_begin_subtest "Search: text" +output=$(notmuch search '*' | notmuch_search_sanitize) +test_expect_equal "$output" "\ +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" +test_subtest_known_broken +output=$(notmuch search --format=json '*' | notmuch_search_sanitize) +test_expect_equal_json "$output" ' +[ +{ +"authors": "", +"date_relative": "2001-01-05", +"matched": 1, +"subject": "", +"tags": [ +"inbox", +"unread" +], +"thread": "XXX", +"timestamp": 978709437, +"total": 1 +}, +{ +"authors": "Notmuch Test Suite", +"date_relative": "1970-01-01", +"matched": 1, +"subject": "", +"tags": [ +"inbox", +"unread" +], +"thread": "XXX", +"timestamp": 0, +"total": 1 +} +]' + +test_begin_subtest "Show: text" +output=$(notmuch show '*') +test_expect_equal "$output" "\ +message{ id:notmuch-sha1-7a6e4eac383ef958fcd3ebf2143db71b8ff01161 depth:0 match:1 excluded:0 filename:/tmp/nmtest/tmp.missing-headers/mail/msg-2 +header{ + (2001-01-05) (inbox unread) +Subject: (null) +From: (null) +To: Notmuch Test Suite +Date: Fri, 05 Jan 2001 15:43:57 + +header} +body{ +part{ ID: 1, Content-type: text/plain +Body +part} +body} +message} +message{ id:notmuch-sha1-ca55943aff7a72baf2ab21fa74fab3d632401334 depth:0 match:1 excluded:0 filename:/tmp/nmtest/tmp.missing-headers/mail/msg-1 +header{ +Notmuch Test Suite (1970-01-01) (inbox unread) +Subject: (null) +From: Notmuch Test Suite +Date: Thu, 01 Jan 1970 00:00:00 + +header} +body{ +part{ ID: 1, Content-type: text/plain +Body +part} +body} +message}" + +test_begin_subtest "Show: json" +test_subtest_known_broken +output=$(notmuch show --format=json '*' | notmuch_json_show_sanitize) +test_expect_equal_json "$output" ' +[ +[ +[ +{ +"body": [ +{ +"content": "Body\n", +"content-type": "text/plain", +"id": 1 +} +], +"date_relative": "2001-01-05", +"excluded": false, +"filename": "Y", +"headers": { +"Date": "Fri, 05 Jan 2001 15:43:57 +", +"From": "", +"Subject": "", +"To": "Notmuch Test Suite " +}, +"id": "X", +"match": true, +"tags": [ +"inbox", +"unread" +], +"timestamp": 978709437 +}, +[] +] +], +[ +[ +{ +"body": [ +{ +"content": "Body\n", +"content-type": "text/plain", +"id": 1 +} +], +"date_relative": "1970-01-01", +"excluded": false, +"filename": "Y", +"headers": { +"Date": "Thu, 01 Jan 1970 00:00:00 +", +"From": "N
Re: [PATCH] test: Add test for messages with missing headers
Hi This generally looks good but there is a bug in the test from a hardcoded /tmp/ path (see below). And as confirmation with the patch in id:"874noe1o0r@qmul.ac.uk" the tests (modulo the test bug) pass. On Tue, 07 Aug 2012, Austin Clements wrote: > Currently the JSON tests for search and show are broken because > notmuch attempts to dereference a NULL pointer. > --- > Things to bikeshed: > > * Should we include From and Subject in the headers object when there > are no from or subject headers? Currently the schema says that > everything but those two and "Date" is optional (indeed, "To" is > missing from the second message) but that was just post facto > standardization. I think Date and From are compulsory in an email but the others are not (but I am unsure which Date and which From so that may be unhelpful). If I am correct it might be sensible to always include those two. > * How should we format expected JSON in the test suite, now that we > can format it however we want? Here I've just pasted in the result > of python -mjson.tool. While that was very easy and the result is > quite readable, it's the antithesis of compact and the keys have > been alphabetized. I like this: making the tests readable is a big plus. > test/missing-headers | 162 > ++ > test/notmuch-test|1 + > 2 files changed, 163 insertions(+) > create mode 100755 test/missing-headers > > diff --git a/test/missing-headers b/test/missing-headers > new file mode 100755 > index 000..744c04e > --- /dev/null > +++ b/test/missing-headers > @@ -0,0 +1,162 @@ > +#!/usr/bin/env bash > +test_description='messages with missing headers' > +. ./test-lib.sh > + > +# Notmuch requires at least one of from, subject, or to or it will > +# ignore the file. Generate two messages so that together they cover > +# all possible missing headers. We also give one of the messages a > +# date to ensure stable result ordering. > + > +cat < "${MAIL_DIR}/msg-2" > +To: Notmuch Test Suite > +Date: Fri, 05 Jan 2001 15:43:57 + > + > +Body > +EOF > + > +cat < "${MAIL_DIR}/msg-1" > +From: Notmuch Test Suite > + > +Body > +EOF > + > +NOTMUCH_NEW > + > +test_begin_subtest "Search: text" > +output=$(notmuch search '*' | notmuch_search_sanitize) > +test_expect_equal "$output" "\ > +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" > +test_subtest_known_broken > +output=$(notmuch search --format=json '*' | notmuch_search_sanitize) > +test_expect_equal_json "$output" ' > +[ > +{ > +"authors": "", > +"date_relative": "2001-01-05", > +"matched": 1, > +"subject": "", > +"tags": [ > +"inbox", > +"unread" > +], > +"thread": "XXX", > +"timestamp": 978709437, > +"total": 1 > +}, > +{ > +"authors": "Notmuch Test Suite", > +"date_relative": "1970-01-01", > +"matched": 1, > +"subject": "", > +"tags": [ > +"inbox", > +"unread" > +], > +"thread": "XXX", > +"timestamp": 0, > +"total": 1 > +} > +]' > + > +test_begin_subtest "Show: text" > +output=$(notmuch show '*') > +test_expect_equal "$output" "\ > +message{ id:notmuch-sha1-7a6e4eac383ef958fcd3ebf2143db71b8ff01161 depth:0 > match:1 excluded:0 filename:/tmp/nmtest/tmp.missing-headers/mail/msg-2 The filename above has not been sanitised so contains your tmp path. Best wishes Mark > +header{ > + (2001-01-05) (inbox unread) > +Subject: (null) > +From: (null) > +To: Notmuch Test Suite > +Date: Fri, 05 Jan 2001 15:43:57 + > +header} > +body{ > +part{ ID: 1, Content-type: text/plain > +Body > +part} > +body} > +message} > +message{ id:notmuch-sha1-ca55943aff7a72baf2ab21fa74fab3d632401334 depth:0 > match:1 excluded:0 filename:/tmp/nmtest/tmp.missing-headers/mail/msg-1 > +header{ > +Notmuch Test Suite (1970-01-01) (inbox unread) > +Subject: (null) > +From: Notmuch Test Suite > +Date: Thu, 01 Jan 1970 00:00:00 + > +header} > +body{ > +part{ ID: 1, Content-type: text/plain > +Body > +part} > +body} > +message}" > + > +test_begin_subtest "Show: json" > +test_subtest_known_broken > +output=$(notmuch show --format=json '*' | notmuch_json_show_sanitize) > +test_expect_equal_json "$output" ' > +[ > +[ > +[ > +{ > +"body": [ > +{ > +"content": "Body\n", > +"content-type": "text/plain", > +"id": 1 > +} > +], > +"date_relative": "2001-01-05", > +"excluded": false, > +"filename": "Y", > +"headers": { > +"Date": "Fri, 05 Jan 2001 15:43:57 +", > +
[PATCH] test: Add test for messages with missing headers
Currently the JSON tests for search and show are broken because notmuch attempts to dereference a NULL pointer. --- Things to bikeshed: * Should we include From and Subject in the headers object when there are no from or subject headers? Currently the schema says that everything but those two and "Date" is optional (indeed, "To" is missing from the second message) but that was just post facto standardization. * How should we format expected JSON in the test suite, now that we can format it however we want? Here I've just pasted in the result of python -mjson.tool. While that was very easy and the result is quite readable, it's the antithesis of compact and the keys have been alphabetized. test/missing-headers | 162 ++ test/notmuch-test|1 + 2 files changed, 163 insertions(+) create mode 100755 test/missing-headers diff --git a/test/missing-headers b/test/missing-headers new file mode 100755 index 000..744c04e --- /dev/null +++ b/test/missing-headers @@ -0,0 +1,162 @@ +#!/usr/bin/env bash +test_description='messages with missing headers' +. ./test-lib.sh + +# Notmuch requires at least one of from, subject, or to or it will +# ignore the file. Generate two messages so that together they cover +# all possible missing headers. We also give one of the messages a +# date to ensure stable result ordering. + +cat < "${MAIL_DIR}/msg-2" +To: Notmuch Test Suite +Date: Fri, 05 Jan 2001 15:43:57 + + +Body +EOF + +cat < "${MAIL_DIR}/msg-1" +From: Notmuch Test Suite + +Body +EOF + +NOTMUCH_NEW + +test_begin_subtest "Search: text" +output=$(notmuch search '*' | notmuch_search_sanitize) +test_expect_equal "$output" "\ +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" +test_subtest_known_broken +output=$(notmuch search --format=json '*' | notmuch_search_sanitize) +test_expect_equal_json "$output" ' +[ +{ +"authors": "", +"date_relative": "2001-01-05", +"matched": 1, +"subject": "", +"tags": [ +"inbox", +"unread" +], +"thread": "XXX", +"timestamp": 978709437, +"total": 1 +}, +{ +"authors": "Notmuch Test Suite", +"date_relative": "1970-01-01", +"matched": 1, +"subject": "", +"tags": [ +"inbox", +"unread" +], +"thread": "XXX", +"timestamp": 0, +"total": 1 +} +]' + +test_begin_subtest "Show: text" +output=$(notmuch show '*') +test_expect_equal "$output" "\ +message{ id:notmuch-sha1-7a6e4eac383ef958fcd3ebf2143db71b8ff01161 depth:0 match:1 excluded:0 filename:/tmp/nmtest/tmp.missing-headers/mail/msg-2 +header{ + (2001-01-05) (inbox unread) +Subject: (null) +From: (null) +To: Notmuch Test Suite +Date: Fri, 05 Jan 2001 15:43:57 + +header} +body{ +part{ ID: 1, Content-type: text/plain +Body +part} +body} +message} +message{ id:notmuch-sha1-ca55943aff7a72baf2ab21fa74fab3d632401334 depth:0 match:1 excluded:0 filename:/tmp/nmtest/tmp.missing-headers/mail/msg-1 +header{ +Notmuch Test Suite (1970-01-01) (inbox unread) +Subject: (null) +From: Notmuch Test Suite +Date: Thu, 01 Jan 1970 00:00:00 + +header} +body{ +part{ ID: 1, Content-type: text/plain +Body +part} +body} +message}" + +test_begin_subtest "Show: json" +test_subtest_known_broken +output=$(notmuch show --format=json '*' | notmuch_json_show_sanitize) +test_expect_equal_json "$output" ' +[ +[ +[ +{ +"body": [ +{ +"content": "Body\n", +"content-type": "text/plain", +"id": 1 +} +], +"date_relative": "2001-01-05", +"excluded": false, +"filename": "Y", +"headers": { +"Date": "Fri, 05 Jan 2001 15:43:57 +", +"From": "", +"Subject": "", +"To": "Notmuch Test Suite " +}, +"id": "X", +"match": true, +"tags": [ +"inbox", +"unread" +], +"timestamp": 978709437 +}, +[] +] +], +[ +[ +{ +"body": [ +{ +"content": "Body\n", +"content-type": "text/plain", +"id": 1 +} +], +"date_relative": "1970-01-01", +"excluded": false, +"filename": "Y", +"headers": { +"Date": "Thu, 01 Jan 1970 00:00:00 +", +"From": "N