unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: notmuch@notmuchmail.org
Cc: tomi.ollila@iki.fi
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	[thread overview]
Message-ID: <1388593552-25920-1-git-send-email-tomi.ollila@iki.fi> (raw)

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

             reply	other threads:[~2014-01-01 16:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-01 16:25 Tomi Ollila [this message]
2014-01-12  0:15 ` [PATCH 1/1] test: support for generating decreasing dates with bash 4.0 and 4.1 David Bremner
2014-02-10 21:15 ` [PATCH v2] support for generating decreasing dates in " Tomi Ollila
2014-03-09 13:19   ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1388593552-25920-1-git-send-email-tomi.ollila@iki.fi \
    --to=tomi.ollila@iki.fi \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).