From: Jani Nikula Date: Tue, 30 Oct 2012 20:32:34 +0000 (+0200) Subject: [PATCH v6 3/9] test: add new test tool parse-time for date/time parser X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=ad7ed261ab04a71dccdefb38bc9f21a779612439;p=notmuch-archives.git [PATCH v6 3/9] test: add new test tool parse-time for date/time parser --- diff --git a/bf/44516c2d50d126cadfe1814ebeffadc0dadb20 b/bf/44516c2d50d126cadfe1814ebeffadc0dadb20 new file mode 100644 index 000000000..021625b75 --- /dev/null +++ b/bf/44516c2d50d126cadfe1814ebeffadc0dadb20 @@ -0,0 +1,446 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 9E5C6431FD9 + for ; Tue, 30 Oct 2012 13:33:15 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 8PnWgvqyyK22 for ; + Tue, 30 Oct 2012 13:33:12 -0700 (PDT) +Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com + [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 81F8C431FDC + for ; Tue, 30 Oct 2012 13:32:56 -0700 (PDT) +Received: by mail-lb0-f181.google.com with SMTP id gg6so567600lbb.26 + for ; Tue, 30 Oct 2012 13:32:56 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references + :in-reply-to:references:mime-version:content-type + :content-transfer-encoding:x-gm-message-state; + bh=vMILaKO6smR7vl2i4sM9jBz5pOCabcqzPmPfd6V5VVo=; + b=RHK+BGp5teXvSQFmYinkRREeL/kiCl5w7i6W4rmmlLSi4dNnbYs5mqLa4n1WV4tnE+ + a2XPwhExvdsQIrelXS+yH69QIIDQs1MerHUE+U24ZomDINw3E2MLDC19EAKlzkG33+rm + sEDQA/HKurUdAHuFu23Qpe+z0XdLPICsADhOD3GtRHOlhflfaXLD+ya0JVLtOcmf1JEL + wGF1494vKs2jLH3QpBT/pYYiX+6Z7eYrPLhxZCRW2kigT2hgDV25xmbIdDnXFuoQBZpd + NfuTwkNqcE2ZfpIabVG3ly6G1Ka8BuN1G+e9VBcKVBUBp4G9XjXKjLG+3hPFgrZRjuTn + 2Nww== +Received: by 10.152.104.148 with SMTP id ge20mr30985253lab.51.1351629175980; + Tue, 30 Oct 2012 13:32:55 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi. + [80.223.81.27]) + by mx.google.com with ESMTPS id jk8sm665831lab.7.2012.10.30.13.32.54 + (version=SSLv3 cipher=OTHER); Tue, 30 Oct 2012 13:32:55 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: + [PATCH v6 3/9] test: add new test tool parse-time for date/time parser +Date: Tue, 30 Oct 2012 22:32:34 +0200 +Message-Id: + +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: +References: +In-Reply-To: +References: +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +X-Gm-Message-State: + ALoCoQlbgj4AxEGxVu2A+zxoD7Paw61REWkLR5YurUqXGNjrRYj/NYbWbgSjqzT2UJ7KHYgsEViN +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Tue, 30 Oct 2012 20:33:16 -0000 + +Add a smoke testing tool to support testing the date/time parser +module directly and independent of the rest of notmuch. + +Credits to Michal Sojka for the stdin parsing +idea and consequent massive improvement in testability. +--- + test/Makefile.local | 7 +- + test/basic | 2 +- + test/parse-time.c | 314 +++++++++++++++++++++++++++++++++++++++++++++++++++ + 3 files changed, 321 insertions(+), 2 deletions(-) + create mode 100644 test/parse-time.c + +diff --git a/test/Makefile.local b/test/Makefile.local +index 45df4c7..9ae130a 100644 +--- a/test/Makefile.local ++++ b/test/Makefile.local +@@ -19,9 +19,13 @@ $(dir)/smtp-dummy: $(smtp_dummy_modules) + $(dir)/symbol-test: $(dir)/symbol-test.o + $(call quiet,CXX) $^ -o $@ -Llib -lnotmuch $(XAPIAN_LDFLAGS) + ++$(dir)/parse-time: $(dir)/parse-time.o parse-time-string/parse-time-string.o ++ $(call quiet,CC) $^ -o $@ ++ + .PHONY: test check + +-test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test ++test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test \ ++ $(dir)/parse-time + + test: all test-binaries + @${dir}/notmuch-test $(OPTIONS) +@@ -32,4 +36,5 @@ SRCS := $(SRCS) $(smtp_dummy_srcs) + CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \ + $(dir)/symbol-test $(dir)/symbol-test.o \ + $(dir)/arg-test $(dir)/arg-test.o \ ++ $(dir)/parse-time $(dir)/parse-time.o \ + $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.* +diff --git a/test/basic b/test/basic +index 3b635c8..c47197c 100755 +--- a/test/basic ++++ b/test/basic +@@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test' + eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test) + tests_in_suite=$(for i in $TESTS; do echo $i; done | sort) + available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -perm +111 | \ +- sed -r -e "s,.*/,," -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test)$/d" | \ ++ sed -r -e "s,.*/,," -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|parse-time)$/d" | \ + sort) + test_expect_equal "$tests_in_suite" "$available" + +diff --git a/test/parse-time.c b/test/parse-time.c +new file mode 100644 +index 0000000..901a4dd +--- /dev/null ++++ b/test/parse-time.c +@@ -0,0 +1,314 @@ ++/* ++ * parse time string - user friendly date and time parser ++ * Copyright © 2012 Jani Nikula ++ * ++ * This program is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program. If not, see . ++ * ++ * Author: Jani Nikula ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "parse-time-string.h" ++ ++#define ARRAY_SIZE(a) (sizeof (a) / sizeof (a[0])) ++ ++static const char *parse_time_error_strings[] = { ++ [PARSE_TIME_OK] = "OK", ++ [PARSE_TIME_ERR] = "ERR", ++ [PARSE_TIME_ERR_LIB] = "LIB", ++ [PARSE_TIME_ERR_ALREADYSET] = "ALREADYSET", ++ [PARSE_TIME_ERR_FORMAT] = "FORMAT", ++ [PARSE_TIME_ERR_DATEFORMAT] = "DATEFORMAT", ++ [PARSE_TIME_ERR_TIMEFORMAT] = "TIMEFORMAT", ++ [PARSE_TIME_ERR_INVALIDDATE] = "INVALIDDATE", ++ [PARSE_TIME_ERR_INVALIDTIME] = "INVALIDTIME", ++ [PARSE_TIME_ERR_KEYWORD] = "KEYWORD", ++}; ++ ++static const char * ++parse_time_strerror (unsigned int errnum) ++{ ++ if (errnum < ARRAY_SIZE (parse_time_error_strings)) ++ return parse_time_error_strings[errnum]; ++ else ++ return NULL; ++} ++ ++/* ++ * concat argv[start]...argv[end - 1], separating them by a single ++ * space, to a malloced string ++ */ ++static char * ++concat_args (int start, int end, char *argv[]) ++{ ++ int i; ++ size_t len = 1; ++ char *p; ++ ++ for (i = start; i < end; i++) ++ len += strlen (argv[i]) + 1; ++ ++ p = malloc (len); ++ if (!p) ++ return NULL; ++ ++ *p = 0; ++ ++ for (i = start; i < end; i++) { ++ if (i != start) ++ strcat (p, " "); ++ strcat (p, argv[i]); ++ } ++ ++ return p; ++} ++ ++#define DEFAULT_FORMAT "%a %b %d %T %z %Y" ++ ++static void ++usage (const char *name) ++{ ++ printf ("Usage: %s [options ...] []\n\n", name); ++ printf ( ++ "Parse and display it in given format. If is\n" ++ "not given, parse each line in stdin according to:\n\n" ++ " [(==>|==_>|==^>|==^^>)] [#]\n\n" ++ "and produce output:\n\n" ++ " (==>|==_>|==^>|==^^>)