[PATCH 1/1] test: support for generating decreasing dates with bash 4.0 and 4.1

Tomi Ollila tomi.ollila at iki.fi
Wed Jan 1 08:25:52 PST 2014


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



More information about the notmuch mailing list