unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/1] test: support for generating decreasing dates with bash 4.0 and 4.1
@ 2014-01-01 16:25 Tomi Ollila
  2014-01-12  0:15 ` David Bremner
  2014-02-10 21:15 ` [PATCH v2] support for generating decreasing dates in " Tomi Ollila
  0 siblings, 2 replies; 4+ messages in thread
From: Tomi Ollila @ 2014-01-01 16:25 UTC (permalink / raw)
  To: notmuch; +Cc: tomi.ollila

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] test: support for generating decreasing dates with bash 4.0 and 4.1
  2014-01-01 16:25 [PATCH 1/1] test: support for generating decreasing dates with bash 4.0 and 4.1 Tomi Ollila
@ 2014-01-12  0:15 ` David Bremner
  2014-02-10 21:15 ` [PATCH v2] support for generating decreasing dates in " Tomi Ollila
  1 sibling, 0 replies; 4+ messages in thread
From: David Bremner @ 2014-01-12  0:15 UTC (permalink / raw)
  To: Tomi Ollila, notmuch; +Cc: tomi.ollila

Tomi Ollila <tomi.ollila@iki.fi> writes:

> 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.

Wouldn't it be simpler to always use perl?

d

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] support for generating decreasing dates in bash 4.0 and 4.1
  2014-01-01 16:25 [PATCH 1/1] test: support for generating decreasing dates with bash 4.0 and 4.1 Tomi Ollila
  2014-01-12  0:15 ` David Bremner
@ 2014-02-10 21:15 ` Tomi Ollila
  2014-03-09 13:19   ` David Bremner
  1 sibling, 1 reply; 4+ messages in thread
From: Tomi Ollila @ 2014-02-10 21:15 UTC (permalink / raw)
  To: notmuch; +Cc: tomi.ollila

The printf builtin "%(fmt)T" specifier (which allows time values
to use strftime-like formatting) is introduced in bash 4.2.

Trying to execute this in pre-4.2 bash will fail -- and if this
happens execute the fallback piece of perl code to do the same thing.
---
 test/test-lib.sh | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/test/test-lib.sh b/test/test-lib.sh
index 78af170..a1c0f27 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -374,8 +374,12 @@ 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)))
+	local date_secs=$((978709437 - gen_msg_cnt))
+	# printf %(..)T is bash 4.2+ feature. use perl fallback if needed...
+	TZ=UTC printf -v template[date] "%(%a, %d %b %Y %T %z)T" $date_secs 2>/dev/null ||
+	    template[date]=`perl -le 'use POSIX "strftime";
+				@time = gmtime '"$date_secs"';
+				print strftime "%a, %d %b %Y %T +0000", @time'`
     fi
 
     additional_headers=""
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] support for generating decreasing dates in bash 4.0 and 4.1
  2014-02-10 21:15 ` [PATCH v2] support for generating decreasing dates in " Tomi Ollila
@ 2014-03-09 13:19   ` David Bremner
  0 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2014-03-09 13:19 UTC (permalink / raw)
  To: Tomi Ollila, notmuch; +Cc: tomi.ollila

Tomi Ollila <tomi.ollila@iki.fi> writes:

> The printf builtin "%(fmt)T" specifier (which allows time values
> to use strftime-like formatting) is introduced in bash 4.2.
>
> Trying to execute this in pre-4.2 bash will fail -- and if this
> happens execute the fallback piece of perl code to do the same 

pushed.

d

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-03-09 13:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-01 16:25 [PATCH 1/1] test: support for generating decreasing dates with bash 4.0 and 4.1 Tomi Ollila
2014-01-12  0:15 ` David Bremner
2014-02-10 21:15 ` [PATCH v2] support for generating decreasing dates in " Tomi Ollila
2014-03-09 13:19   ` David Bremner

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).