Re: [PATCH 1/4] show: indicate length of omitted body content (json)
[notmuch-archives.git] / 63 / c5578b1c26545792c2c9837faa6883227c5d2d
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
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\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
43 Precedence: list\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
54 \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
61 ---\r
62  lib/getdate.c       |   52 +++++++++++++++++++++++++++++++++++++++-----------\r
63  lib/getdate.y       |   52 +++++++++++++++++++++++++++++++++++++++-----------\r
64  test/Makefile.local |    9 ++++++-\r
65  test/basic          |    2 +-\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
70 \r
71 diff --git a/lib/getdate.c b/lib/getdate.c\r
72 index 57f33e9..685c51f 100644\r
73 --- a/lib/getdate.c\r
74 +++ b/lib/getdate.c\r
75 @@ -3471,19 +3471,50 @@ get_date (struct timespec *result, char const *p, struct timespec const *now)\r
76  #if TEST\r
77  \r
78  int\r
79 +_internal_error (const char *format, ...)\r
80 +{\r
81 +    va_list va_args;\r
82 +\r
83 +    va_start (va_args, format);\r
84 +\r
85 +    fprintf (stderr, "Internal error: ");\r
86 +    vfprintf (stderr, format, va_args);\r
87 +\r
88 +    exit (1);\r
89 +\r
90 +    return 1;\r
91 +}\r
92 +\r
93 +int\r
94  main (int ac, char **av)\r
95  {\r
96    char buff[BUFSIZ];\r
97  \r
98 -  printf ("Enter date, or blank line to exit.\n\t> ");\r
99 -  fflush (stdout);\r
100 -\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
105      {\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
110 +      char *arrow;\r
111 +      arrow = strstr (buff, "->");\r
112 +      if (arrow)\r
113 +         *arrow = 0;\r
114 +      else {\r
115 +         arrow = buff + strlen (buff);\r
116 +         while (arrow > buff && *(arrow-1) == '\n')\r
117 +             arrow--;\r
118 +         *arrow-- = 0;\r
119 +         if (arrow >= buff && ( *arrow != ' ' || *arrow != '\t' ))\r
120 +             strcat (buff, " ");\r
121 +      }\r
122 +      if (ac > 1) {\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
127 +      } else\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
132          {\r
133 @@ -3492,13 +3523,10 @@ main (int ac, char **av)\r
134          }\r
135        else\r
136          {\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
143          }\r
144 -      printf ("\t> ");\r
145 -      fflush (stdout);\r
146      }\r
147    return 0;\r
148  }\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
154  #if TEST\r
155  \r
156  int\r
157 +_internal_error (const char *format, ...)\r
158 +{\r
159 +    va_list va_args;\r
160 +\r
161 +    va_start (va_args, format);\r
162 +\r
163 +    fprintf (stderr, "Internal error: ");\r
164 +    vfprintf (stderr, format, va_args);\r
165 +\r
166 +    exit (1);\r
167 +\r
168 +    return 1;\r
169 +}\r
170 +\r
171 +int\r
172  main (int ac, char **av)\r
173  {\r
174    char buff[BUFSIZ];\r
175  \r
176 -  printf ("Enter date, or blank line to exit.\n\t> ");\r
177 -  fflush (stdout);\r
178 -\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
183      {\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
188 +      char *arrow;\r
189 +      arrow = strstr (buff, "->");\r
190 +      if (arrow)\r
191 +         *arrow = 0;\r
192 +      else {\r
193 +         arrow = buff + strlen (buff);\r
194 +         while (arrow > buff && *(arrow-1) == '\n')\r
195 +             arrow--;\r
196 +         *arrow-- = 0;\r
197 +         if (arrow >= buff && ( *arrow != ' ' || *arrow != '\t' ))\r
198 +             strcat (buff, " ");\r
199 +      }\r
200 +      if (ac > 1) {\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
205 +      } else\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
210          {\r
211 @@ -1568,13 +1599,10 @@ main (int ac, char **av)\r
212          }\r
213        else\r
214          {\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
221          }\r
222 -      printf ("\t> ");\r
223 -      fflush (stdout);\r
224      }\r
225    return 0;\r
226  }\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
234  \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
238 +\r
239 +\r
240  .PHONY: test check\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
244  \r
245  check: test\r
246  \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
251 --- a/test/basic\r
252 +++ b/test/basic\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
260  \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
265 --- /dev/null\r
266 +++ b/test/date-parser\r
267 @@ -0,0 +1,37 @@\r
268 +#!/bin/bash\r
269 +test_description="date parser"\r
270 +. ./test-lib.sh\r
271 +\r
272 +# Note: 2011-1-11 is Tuesday\r
273 +\r
274 +test_begin_subtest "Date/time parsing"\r
275 +cat > input <<EOF\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
286 +EOF\r
287 +output=$(../getdate-test "2011-1-11 11:11" < input)\r
288 +test_expect_equal "$output" "$(cat input)"\r
289 +\r
290 +\r
291 +test_begin_subtest "Broken - implicitely, we mean the past"\r
292 +cat > input <<EOF\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
296 +EOF\r
297 +output=$(../getdate-test "2011-1-11 11:11" < input)\r
298 +test_expect_equal "$output" "$(cat input)"\r
299 +\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
303 +\r
304 +test_done\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
310  \r
311  cd $(dirname "$0")\r
312  \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
315  \r
316  # Clean up any results from a previous run\r
317  rm -r test-results >/dev/null 2>/dev/null\r
318 -- \r
319 1.7.2.3\r
320 \r