From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 2EB17431FC0 for ; Wed, 1 Jan 2014 08:26:07 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] 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 JtGXSmDYFxsH for ; Wed, 1 Jan 2014 08:26:00 -0800 (PST) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by olra.theworths.org (Postfix) with ESMTP id 812B2431FAF for ; Wed, 1 Jan 2014 08:26:00 -0800 (PST) Received: by guru.guru-group.fi (Postfix, from userid 501) id 3811E10014F; Wed, 1 Jan 2014 18:25:54 +0200 (EET) From: Tomi Ollila To: notmuch@notmuchmail.org Subject: [PATCH 1/1] test: support for generating decreasing dates with bash 4.0 and 4.1 Date: Wed, 1 Jan 2014 18:25:52 +0200 Message-Id: <1388593552-25920-1-git-send-email-tomi.ollila@iki.fi> X-Mailer: git-send-email 1.8.0 Cc: tomi.ollila@iki.fi 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: Wed, 01 Jan 2014 16:26:07 -0000 The printf builtin "%(fmt)T" specifier (which allows time values to use strftime-like formatting) is introduced in bash 4.2. Added a new function `secs_to_rfc2822date` which uses the above specifier with post 4.1 bash and perl(1) construct with pre-4.2 bash. --- test/test-lib.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/test/test-lib.sh b/test/test-lib.sh index 2fcaba6..7d88867 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -272,6 +272,21 @@ remove_cr () { tr '\015' Q | sed -e 's/Q$//' } +# The printf '%(fmt)T' specifier is bash 4.2+ feature. +if [[ ${BASH_VERSINFO[0]} -gt 4 || ${BASH_VERSINFO[1]} -ge 2 ]] +then + secs_to_rfc2822date () + { + TZ=UTC printf "%(%a, %d %b %Y %T %z)T\n" "$1" + } +else + secs_to_rfc2822date () + { + perl -le 'use POSIX "strftime"; @time = gmtime $ARGV[0]; + print strftime "%a, %d %b %Y %T +0000", @time' "$1" + } +fi + # Generate a new message in the mail directory, with a unique message # ID and subject. The message is not added to the index. # @@ -373,8 +388,8 @@ generate_message () # we use decreasing timestamps here for historical reasons; # the existing test suite when we converted to unique timestamps just # happened to have signicantly fewer failures with that choice. - template[date]=$(TZ=UTC printf "%(%a, %d %b %Y %T %z)T\n" \ - $((978709437 - gen_msg_cnt))) + + template[date]=$(secs_to_rfc2822date $((978709437 - gen_msg_cnt))) fi additional_headers="" -- 1.8.0