1 Return-Path: <jani@nikula.org>
\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 6DF91431FC0
\r
6 for <notmuch@notmuchmail.org>; Fri, 3 Aug 2012 14:52:09 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id EeTDFi46zCvY for <notmuch@notmuchmail.org>;
\r
17 Fri, 3 Aug 2012 14:52:07 -0700 (PDT)
\r
18 Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com
\r
19 [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 66127431FAF
\r
22 for <notmuch@notmuchmail.org>; Fri, 3 Aug 2012 14:52:06 -0700 (PDT)
\r
23 Received: by mail-lpp01m010-f53.google.com with SMTP id u2so681800lag.26
\r
24 for <notmuch@notmuchmail.org>; Fri, 03 Aug 2012 14:52:06 -0700 (PDT)
\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=google.com; s=20120113;
\r
27 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references
\r
28 :in-reply-to:references:mime-version:content-type
\r
29 :content-transfer-encoding:x-gm-message-state;
\r
30 bh=Xz4EV6zcUuunFx+642pEKaTQoStHEO8PJ07uzI+eTQU=;
\r
31 b=GM+/dAyhmjMurc/AIW8njEoWj6DUi9gNmevKGxp5FnRkqBJ8ItlqoaEv4HLVb09aMo
\r
32 f78rFOhfeItt3QCm6gM0AkbWXVYMyajlJLaVaNRTnAvJovhuAy1RrGdrtJiuE58RQ85U
\r
33 nZ743ONUvPCXTgqNXcRXaMxVDWJEf0eQxbDEr1+zmaQDfgu5esV0ajG5HFSe6CAtQ9nb
\r
34 ZyXxVSDH6Sip+YrT+Vh/oZuT006D4kwmCcaHsYqxX7KnWF+FzElyz0LfbTUVBNCHgvmV
\r
35 2k8/SGDJIKhQAHHAFXBZdFsrzO2UCrGb4qK7meeJ4ahhwaaZQWqj+bgNkOppoDFZIiQ3
\r
37 Received: by 10.112.46.166 with SMTP id w6mr1202283lbm.100.1344030725959;
\r
38 Fri, 03 Aug 2012 14:52:05 -0700 (PDT)
\r
39 Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi.
\r
41 by mx.google.com with ESMTPS id jj5sm9743671lab.1.2012.08.03.14.52.04
\r
42 (version=SSLv3 cipher=OTHER); Fri, 03 Aug 2012 14:52:05 -0700 (PDT)
\r
43 From: Jani Nikula <jani@nikula.org>
\r
44 To: notmuch@notmuchmail.org
\r
45 Subject: [PATCH 3/7] test: add new test tool parse-time for date/time parser
\r
46 Date: Sat, 4 Aug 2012 00:51:48 +0300
\r
48 <6ef33295de46833913336b9e5be8b8f4845f6394.1344028781.git.jani@nikula.org>
\r
49 X-Mailer: git-send-email 1.7.9.5
\r
50 In-Reply-To: <cover.1344028781.git.jani@nikula.org>
\r
51 References: <cover.1344028781.git.jani@nikula.org>
\r
52 In-Reply-To: <cover.1344028781.git.jani@nikula.org>
\r
53 References: <cover.1344028781.git.jani@nikula.org>
\r
55 Content-Type: text/plain; charset=UTF-8
\r
56 Content-Transfer-Encoding: 8bit
\r
58 ALoCoQmO2UkdKDWCdOzrfxKWAige6IlcBzWyRmv+75Q28csnzk2RIDMmFg2V9ytwRW7TusiT7ajn
\r
59 X-BeenThere: notmuch@notmuchmail.org
\r
60 X-Mailman-Version: 2.1.13
\r
62 List-Id: "Use and development of the notmuch mail system."
\r
63 <notmuch.notmuchmail.org>
\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
67 List-Post: <mailto:notmuch@notmuchmail.org>
\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
70 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
71 X-List-Received-Date: Fri, 03 Aug 2012 21:52:09 -0000
\r
73 Add a tool to support testing the date/time parser module directly and
\r
74 independent of the rest of notmuch.
\r
76 test/Makefile.local | 9 +++-
\r
78 test/parse-time.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++
\r
79 3 files changed, 153 insertions(+), 3 deletions(-)
\r
80 create mode 100644 test/parse-time.c
\r
82 diff --git a/test/Makefile.local b/test/Makefile.local
\r
83 index 4a6a4b1..729f38e 100644
\r
84 --- a/test/Makefile.local
\r
85 +++ b/test/Makefile.local
\r
86 @@ -19,9 +19,13 @@ $(dir)/smtp-dummy: $(smtp_dummy_modules)
\r
87 $(dir)/symbol-test: $(dir)/symbol-test.o
\r
88 $(call quiet,CXX) $^ -o $@ -Llib -lnotmuch -lxapian
\r
90 +$(dir)/parse-time: $(dir)/parse-time.o lib/parse-time-string.o
\r
91 + $(call quiet,CC) $^ -o $@
\r
95 -test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test
\r
96 +test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test \
\r
99 test: all test-binaries
\r
100 @${dir}/notmuch-test $(OPTIONS)
\r
101 @@ -31,4 +35,5 @@ check: test
\r
102 SRCS := $(SRCS) $(smtp_dummy_srcs)
\r
103 CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \
\r
104 $(dir)/symbol-test $(dir)/symbol-test.o \
\r
105 - $(dir)/arg-test $(dir)/arg-test.o
\r
106 + $(dir)/arg-test $(dir)/arg-test.o \
\r
107 + $(dir)/parse-time $(dir)/parse-time.o
\r
108 diff --git a/test/basic b/test/basic
\r
109 index d6aed24..c658b95 100755
\r
112 @@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'
\r
113 eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)
\r
114 tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)
\r
115 available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \
\r
116 - sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test)$/d" | \
\r
117 + sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|parse-time)$/d" | \
\r
119 test_expect_equal "$tests_in_suite" "$available"
\r
121 diff --git a/test/parse-time.c b/test/parse-time.c
\r
122 new file mode 100644
\r
123 index 0000000..b4de76b
\r
125 +++ b/test/parse-time.c
\r
128 + * parse time string - user friendly date and time parser
\r
129 + * Copyright © 2012 Jani Nikula
\r
131 + * This program is free software: you can redistribute it and/or modify
\r
132 + * it under the terms of the GNU General Public License as published by
\r
133 + * the Free Software Foundation, either version 2 of the License, or
\r
134 + * (at your option) any later version.
\r
136 + * This program is distributed in the hope that it will be useful,
\r
137 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
138 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
139 + * GNU General Public License for more details.
\r
141 + * You should have received a copy of the GNU General Public License
\r
142 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
144 + * Author: Jani Nikula <jani@nikula.org>
\r
147 +#include <getopt.h>
\r
148 +#include <stdio.h>
\r
149 +#include <stdlib.h>
\r
150 +#include <string.h>
\r
152 +#include "parse-time-string.h"
\r
155 + * concat argv[start]...argv[end - 1], separating them by a single
\r
156 + * space, to a malloced string
\r
159 +concat_args (int start, int end, char *argv[])
\r
165 + for (i = start; i < end; i++)
\r
166 + len += strlen (argv[i]) + 1;
\r
168 + p = malloc (len);
\r
174 + for (i = start; i < end; i++) {
\r
177 + strcat (p, argv[i]);
\r
183 +#define DEFAULT_FORMAT "%a %b %d %T %z %Y"
\r
186 +usage (const char *name)
\r
188 + printf ("Usage: %s [options ...] <date/time>\n\n", name);
\r
190 + "Parse <date/time> and display it in given format.\n\n"
\r
191 + " -f, --format=FMT output format, FMT according to strftime(3)\n"
\r
192 + " (default: \"%s\")\n"
\r
193 + " -n, --now=N use N seconds since epoch as now (default: now)\n"
\r
194 + " -u, --up round result up (default: no rounding)\n"
\r
195 + " -d, --down round result down (default: no rounding)\n"
\r
196 + " -h, --help print this help\n",
\r
201 +main (int argc, char *argv[])
\r
207 + time_t *nowp = NULL;
\r
209 + int round = PARSE_TIME_NO_ROUND;
\r
211 + const char *format = DEFAULT_FORMAT;
\r
212 + struct option options[] = {
\r
213 + { "help", no_argument, NULL, 'h' },
\r
214 + { "up", no_argument, NULL, 'u' },
\r
215 + { "down", no_argument, NULL, 'd' },
\r
216 + { "format", required_argument, NULL, 'f' },
\r
217 + { "now", required_argument, NULL, 'n' },
\r
218 + { NULL, 0, NULL, 0 },
\r
224 + c = getopt_long (argc, argv, "hudf:n:", options, NULL);
\r
230 + /* output format */
\r
234 + round = PARSE_TIME_ROUND_UP;
\r
237 + round = PARSE_TIME_ROUND_DOWN;
\r
240 + /* specify now in seconds since epoch */
\r
241 + now = (time_t) strtol (optarg, NULL, 10);
\r
242 + if (now >= (time_t) 0)
\r
253 + argstr = concat_args (optind, argc, argv);
\r
257 + r = parse_time_string (argstr, &result, nowp, round);
\r
264 + if (!localtime_r (&result, &tm))
\r
267 + strftime (buf, sizeof (buf), format, &tm);
\r
268 + printf ("%s\n", buf);
\r