1 Return-Path: <sojkam1@fel.cvut.cz>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 32F7342D28D
\r
6 for <notmuch@notmuchmail.org>; Sun, 23 Jan 2011 03:48:08 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id qzh4m-zf4cdL for <notmuch@notmuchmail.org>;
\r
16 Sun, 23 Jan 2011 03:48:06 -0800 (PST)
\r
17 Received: from mail.loccal.net (gw.loccal.net [94.142.235.206])
\r
18 by olra.theworths.org (Postfix) with ESMTP id C6B1642D280
\r
19 for <notmuch@notmuchmail.org>; Sun, 23 Jan 2011 03:48:02 -0800 (PST)
\r
20 Received: from localhost (localhost [127.0.0.1])
\r
21 by mail.loccal.net (Postfix) with ESMTP id E43C11043A;
\r
22 Sun, 23 Jan 2011 13:01:17 +0100 (CET)
\r
23 X-Virus-Scanned: amavisd-new at loccal.net
\r
24 Received: from mail.loccal.net ([127.0.0.1])
\r
25 by localhost (mail.loccal.net [127.0.0.1]) (amavisd-new, port 10024)
\r
26 with LMTP id N48jDBcPsm-s; Sun, 23 Jan 2011 13:01:10 +0100 (CET)
\r
27 Received: from steelpick.2x.cz (unknown [10.21.129.4])
\r
28 by mail.loccal.net (Postfix) with ESMTPS id 9DB5B1BDAF;
\r
29 Sun, 23 Jan 2011 13:00:54 +0100 (CET)
\r
30 Received: from wsh by steelpick.2x.cz with local (Exim 4.72)
\r
31 (envelope-from <sojkam1@fel.cvut.cz>)
\r
32 id 1PgyPu-0005i8-RD; Sun, 23 Jan 2011 12:47:34 +0100
\r
33 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
34 To: notmuch@notmuchmail.org
\r
35 Subject: [PATCH 4/4] Add first date parser tests
\r
36 Date: Sun, 23 Jan 2011 12:47:27 +0100
\r
37 Message-Id: <1295783247-21900-5-git-send-email-sojkam1@fel.cvut.cz>
\r
38 X-Mailer: git-send-email 1.7.2.3
\r
39 In-Reply-To: <1295783247-21900-1-git-send-email-sojkam1@fel.cvut.cz>
\r
40 References: <1295783247-21900-1-git-send-email-sojkam1@fel.cvut.cz>
\r
41 X-BeenThere: notmuch@notmuchmail.org
\r
42 X-Mailman-Version: 2.1.13
\r
44 List-Id: "Use and development of the notmuch mail system."
\r
45 <notmuch.notmuchmail.org>
\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
49 List-Post: <mailto:notmuch@notmuchmail.org>
\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
53 X-List-Received-Date: Sun, 23 Jan 2011 11:48:08 -0000
\r
55 Some tests are currently broken for several reasons:
\r
56 1) in the context of e-mails, we implicitly mean past dates e.g. Monday
\r
57 means the last Monday and not the next one, as it is currently
\r
58 implemented by the parser.
\r
59 2) yesterday means "now -24 hours" and I think that should be
\r
60 "midnight -24 hours".
\r
62 lib/getdate.c | 52 +++++++++++++++++++++++++++++++++++++++-----------
\r
63 lib/getdate.y | 52 +++++++++++++++++++++++++++++++++++++++-----------
\r
64 test/Makefile.local | 9 ++++++-
\r
66 test/date-parser | 37 ++++++++++++++++++++++++++++++++++++
\r
67 test/notmuch-test | 2 +-
\r
68 6 files changed, 126 insertions(+), 28 deletions(-)
\r
69 create mode 100755 test/date-parser
\r
71 diff --git a/lib/getdate.c b/lib/getdate.c
\r
72 index 57f33e9..685c51f 100644
\r
75 @@ -3471,19 +3471,50 @@ get_date (struct timespec *result, char const *p, struct timespec const *now)
\r
79 +_internal_error (const char *format, ...)
\r
83 + va_start (va_args, format);
\r
85 + fprintf (stderr, "Internal error: ");
\r
86 + vfprintf (stderr, format, va_args);
\r
94 main (int ac, char **av)
\r
98 - printf ("Enter date, or blank line to exit.\n\t> ");
\r
101 - buff[BUFSIZ - 1] = '\0';
\r
102 - while (fgets (buff, BUFSIZ - 1, stdin) && buff[0])
\r
103 + buff[BUFSIZ - 2] = '\0';
\r
104 + while (fgets (buff, BUFSIZ - 2, stdin) && buff[0])
\r
106 - struct timespec d;
\r
107 + struct timespec d, ref = { 0, 0 };
\r
108 struct tm const *tm;
\r
109 - if (! get_date (&d, buff, NULL))
\r
111 + arrow = strstr (buff, "->");
\r
115 + arrow = buff + strlen (buff);
\r
116 + while (arrow > buff && *(arrow-1) == '\n')
\r
119 + if (arrow >= buff && ( *arrow != ' ' || *arrow != '\t' ))
\r
120 + strcat (buff, " ");
\r
123 + struct tm tm_arg;
\r
124 + memset (&tm_arg, 0, sizeof (tm_arg));
\r
125 + strptime (av[1], "%Y-%m-%d %H:%M", &tm_arg);
\r
126 + ref.tv_sec = mktime (&tm_arg);
\r
128 + clock_gettime (CLOCK_REALTIME, &ref);
\r
129 + if (! get_date (&d, buff, &ref))
\r
130 printf ("Bad format - couldn't convert.\n");
\r
131 else if (! (tm = localtime (&d.tv_sec)))
\r
133 @@ -3492,13 +3523,10 @@ main (int ac, char **av)
\r
137 - int ns = d.tv_nsec;
\r
138 - printf ("%04ld-%02d-%02d %02d:%02d:%02d.%09d\n",
\r
139 + printf ("%s-> %04ld-%02d-%02d %02d:%02d:%02d\n", buff,
\r
140 tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday,
\r
141 - tm->tm_hour, tm->tm_min, tm->tm_sec, ns);
\r
142 + tm->tm_hour, tm->tm_min, tm->tm_sec);
\r
149 diff --git a/lib/getdate.y b/lib/getdate.y
\r
150 index d423f5b..657416e 100644
\r
151 --- a/lib/getdate.y
\r
152 +++ b/lib/getdate.y
\r
153 @@ -1547,19 +1547,50 @@ get_date (struct timespec *result, char const *p, struct timespec const *now)
\r
157 +_internal_error (const char *format, ...)
\r
161 + va_start (va_args, format);
\r
163 + fprintf (stderr, "Internal error: ");
\r
164 + vfprintf (stderr, format, va_args);
\r
172 main (int ac, char **av)
\r
176 - printf ("Enter date, or blank line to exit.\n\t> ");
\r
179 - buff[BUFSIZ - 1] = '\0';
\r
180 - while (fgets (buff, BUFSIZ - 1, stdin) && buff[0])
\r
181 + buff[BUFSIZ - 2] = '\0';
\r
182 + while (fgets (buff, BUFSIZ - 2, stdin) && buff[0])
\r
184 - struct timespec d;
\r
185 + struct timespec d, ref = { 0, 0 };
\r
186 struct tm const *tm;
\r
187 - if (! get_date (&d, buff, NULL))
\r
189 + arrow = strstr (buff, "->");
\r
193 + arrow = buff + strlen (buff);
\r
194 + while (arrow > buff && *(arrow-1) == '\n')
\r
197 + if (arrow >= buff && ( *arrow != ' ' || *arrow != '\t' ))
\r
198 + strcat (buff, " ");
\r
201 + struct tm tm_arg;
\r
202 + memset (&tm_arg, 0, sizeof (tm_arg));
\r
203 + strptime (av[1], "%Y-%m-%d %H:%M", &tm_arg);
\r
204 + ref.tv_sec = mktime (&tm_arg);
\r
206 + clock_gettime (CLOCK_REALTIME, &ref);
\r
207 + if (! get_date (&d, buff, &ref))
\r
208 printf ("Bad format - couldn't convert.\n");
\r
209 else if (! (tm = localtime (&d.tv_sec)))
\r
211 @@ -1568,13 +1599,10 @@ main (int ac, char **av)
\r
215 - int ns = d.tv_nsec;
\r
216 - printf ("%04ld-%02d-%02d %02d:%02d:%02d.%09d\n",
\r
217 + printf ("%s-> %04ld-%02d-%02d %02d:%02d:%02d\n", buff,
\r
218 tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday,
\r
219 - tm->tm_hour, tm->tm_min, tm->tm_sec, ns);
\r
220 + tm->tm_hour, tm->tm_min, tm->tm_sec);
\r
227 diff --git a/test/Makefile.local b/test/Makefile.local
\r
228 index 302482b..72c5d74 100644
\r
229 --- a/test/Makefile.local
\r
230 +++ b/test/Makefile.local
\r
231 @@ -8,10 +8,15 @@ $(dir)/smtp-dummy: $(dir)/smtp-dummy.c
\r
232 $(dir)/qparser-test: $(dir)/qparser-test.o notmuch-config.o query-string.o lib/libnotmuch.a
\r
233 $(call quiet,CXX $(CXXFLAGS)) $^ $(FINAL_LIBNOTMUCH_LDFLAGS) -o $@
\r
235 +getdate-src := getdate.c xutil.c c-ctype.c gettime.c
\r
236 +$(dir)/getdate-test: $(getdate-src:%=lib/%)
\r
237 + $(call quiet,CC $(CFLAGS)) $(FINAL_CFLAGS) -lrt -DTEST $^ -o $@
\r
241 -test: all $(dir)/smtp-dummy $(dir)/qparser-test
\r
242 +test: all $(dir)/smtp-dummy $(dir)/qparser-test $(dir)/getdate-test
\r
243 @${dir}/notmuch-test $(OPTIONS)
\r
247 -CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/qparser-test.o $(dir)/qparser-test
\r
248 +CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/qparser-test.o $(dir)/qparser-test $(dir)/getdate-test
\r
249 diff --git a/test/basic b/test/basic
\r
250 index 3191bcc..bbf452f 100755
\r
253 @@ -52,7 +52,7 @@ test_expect_code 2 'failure to clean up causes the test to fail' '
\r
254 # Ensure that all tests are being run
\r
255 test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'
\r
256 tests_in_suite=$(grep TESTS= ../notmuch-test | sed -e "s/TESTS=\"\(.*\)\"/\1/" | tr " " "\n" | sort)
\r
257 -available=$(ls -1 ../ | grep -v -E "^(aggregate-results.sh|Makefile|Makefile.local|notmuch-test|README|test-lib.sh|test-results|tmp.*|valgrind|corpus*|emacs.expected-output|smtp-dummy|smtp-dummy.c|test-verbose|test.expected-output|qparser-test.*|qparser-test|qparser.expected-output)" | sort)
\r
258 +available=$(ls -1 ../ | grep -v -E "^(aggregate-results.sh|Makefile|Makefile.local|notmuch-test|README|test-lib.sh|test-results|tmp.*|valgrind|corpus*|emacs.expected-output|smtp-dummy|smtp-dummy.c|test-verbose|test.expected-output|qparser-test.*|qparser-test|qparser.expected-output|getdate-test)" | sort)
\r
259 test_expect_equal "$tests_in_suite" "$available"
\r
261 EXPECTED=../test.expected-output
\r
262 diff --git a/test/date-parser b/test/date-parser
\r
263 new file mode 100755
\r
264 index 0000000..1c13748
\r
266 +++ b/test/date-parser
\r
269 +test_description="date parser"
\r
272 +# Note: 2011-1-11 is Tuesday
\r
274 +test_begin_subtest "Date/time parsing"
\r
276 +now -> 2011-01-11 11:11:00
\r
277 +2010-1-1 -> 2010-01-01 00:00:00
\r
278 +Jan 2 -> 2011-01-02 00:00:00
\r
279 +last Friday -> 2011-01-07 00:00:00
\r
280 +2 hours ago -> 2011-01-11 09:11:00
\r
281 +last month -> 2010-12-11 11:11:00
\r
282 +month ago -> 2010-12-11 11:11:00
\r
283 +8am -> 2011-01-11 08:00:00
\r
284 +9:15 -> 2011-01-11 09:15:00
\r
285 +12:34 -> 2011-01-11 12:34:00
\r
287 +output=$(../getdate-test "2011-1-11 11:11" < input)
\r
288 +test_expect_equal "$output" "$(cat input)"
\r
291 +test_begin_subtest "Broken - implicitely, we mean the past"
\r
293 +monday -> 2011-01-10 00:00:00
\r
294 +yesterday -> 2011-01-10 00:00:00
\r
295 +tomorrow -> 2011-01-12 00:00:00
\r
297 +output=$(../getdate-test "2011-1-11 11:11" < input)
\r
298 +test_expect_equal "$output" "$(cat input)"
\r
300 +# TODO: Some values should depend whether used with after/before (e.g.
\r
301 +# query "before:yesterday or after:yesterday" should return everything
\r
302 +# except mails from yesterday)
\r
305 diff --git a/test/notmuch-test b/test/notmuch-test
\r
306 index 1e331b3..167e920 100755
\r
307 --- a/test/notmuch-test
\r
308 +++ b/test/notmuch-test
\r
309 @@ -16,7 +16,7 @@ fi
\r
313 -TESTS="basic new qparser search search-output json thread-naming raw reply dump-restore uuencode thread-order author-order from-guessing long-id encoding emacs maildir-sync"
\r
314 +TESTS="basic new qparser date-parser search search-output json thread-naming raw reply dump-restore uuencode thread-order author-order from-guessing long-id encoding emacs maildir-sync"
\r
316 # Clean up any results from a previous run
\r
317 rm -r test-results >/dev/null 2>/dev/null
\r