unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] Change in increment_mtime for BSD compatibility of test suite
@ 2011-05-25 13:07 Felix Geller
  2011-05-26 22:12 ` Carl Worth
  0 siblings, 1 reply; 3+ messages in thread
From: Felix Geller @ 2011-05-25 13:07 UTC (permalink / raw)
  To: notmuch

[-- Attachment #1: Type: text/plain, Size: 1011 bytes --]

Use `-t' option rather than `-d' which is not supported by BSD's
touch. I'm not sure whether this is the cleanest way to do this, please
let me know if there is a better way. There are additional changes
(e.g., sed does not support `-r' but instead `-E') but they seem to be
incompatible between GNU and BSD. What's the recommended way to handle
this?

Cheers,
Felix


diff --git a/test/test-lib.sh b/test/test-lib.sh
index f536172..d2af857 100755
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -218,9 +218,10 @@ increment_mtime_amount=0
 increment_mtime ()
 {
     dir="$1"
-
+    last_mod_date=`date -j -f %Y%m%d%H%M%S \`stat -f %Sm -t %Y%m%d%H%M%S ${dir}\` +%s`
     increment_mtime_amount=$((increment_mtime_amount + 1))
-    touch -d "+${increment_mtime_amount} seconds" "$dir"
+    new_date=`date -j -r ${last_mod_date} -v+${increment_mtime_amount}S +%Y%m%d%H%M.%S`
+    touch -t ${new_date} ${dir}
 }
 
 # Generate a new message in the mail directory, with a unique message

[-- Attachment #2: Type: application/pgp-signature, Size: 202 bytes --]

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

* Re: [PATCH] Change in increment_mtime for BSD compatibility of test suite
  2011-05-25 13:07 [PATCH] Change in increment_mtime for BSD compatibility of test suite Felix Geller
@ 2011-05-26 22:12 ` Carl Worth
  2011-05-30 12:40   ` Felix Geller
  0 siblings, 1 reply; 3+ messages in thread
From: Carl Worth @ 2011-05-26 22:12 UTC (permalink / raw)
  To: Felix Geller, notmuch

[-- Attachment #1: Type: text/plain, Size: 1264 bytes --]

On Wed, 25 May 2011 15:07:52 +0200, Felix Geller <fgeller@gmail.com> wrote:
Non-text part: multipart/mixed
Non-text part: multipart/signed
> Use `-t' option rather than `-d' which is not supported by BSD's
> touch. I'm not sure whether this is the cleanest way to do this, please
> let me know if there is a better way.

I don't know of a better way, but...

> +    last_mod_date=`date -j -f %Y%m%d%H%M%S \`stat -f %Sm -t %Y%m%d%H%M%S ${dir}\` +%s`
>      increment_mtime_amount=$((increment_mtime_amount + 1))
> -    touch -d "+${increment_mtime_amount} seconds" "$dir"
> +    new_date=`date -j -r ${last_mod_date} -v+${increment_mtime_amount}S +%Y%m%d%H%M.%S`
> +    touch -t ${new_date} ${dir}

$ date -j
date: invalid option -- 'j'
Try `date --help' for more information.

:-P

> There are additional changes
> (e.g., sed does not support `-r' but instead `-E') but they seem to be
> incompatible between GNU and BSD. What's the recommended way to handle
> this?

That sounds like something we could test inside our configure
script. In addition to the current Makefile.config file it's creating,
it could also create a little test-config.sh file for things like this.

What do you think?

-Carl

-- 
carl.d.worth@intel.com

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: [PATCH] Change in increment_mtime for BSD compatibility of test suite
  2011-05-26 22:12 ` Carl Worth
@ 2011-05-30 12:40   ` Felix Geller
  0 siblings, 0 replies; 3+ messages in thread
From: Felix Geller @ 2011-05-30 12:40 UTC (permalink / raw)
  To: Carl Worth, notmuch

[-- Attachment #1: Type: text/plain, Size: 5531 bytes --]

Another try :)

[...]

    Support for platform-specific test configuration
     - Platform-specific functionality is stored in test-config-PLATFORM.sh files
     - configure script creates a test/test-config.sh depending on the platform
     - test-lib.sh loads test-config.sh file
     - Some platform-specific functionality included for gnu/bsd:
       - Work-around for touch -d on BSD
       - Variable to store sed command for extended expressions

diff --git a/configure b/configure
index bbf30cd..053a4a1 100755
--- a/configure
+++ b/configure
@@ -16,6 +16,13 @@ if [ "$srcdir" != "." ]; then
     # whole thing into the build directory.
     cp -a "$srcdir"/test/* test
 
+    # Platform specific test configuration
+    if [ $platform = MACOSX ] ; then
+	cp test/test-config-bsd.sh test/test-config.sh
+    else
+	cp test/test-config-gnu.sh test/test-config.sh
+    fi
+
     # Emacs only likes to generate compiled files next to the .el files
     # by default so copy these as well (which is not ideal0.
     cp -a "$srcdir"/emacs/*.el emacs
diff --git a/test/basic b/test/basic
index 808c968..5fbedfe 100755
--- a/test/basic
+++ b/test/basic
@@ -54,13 +54,14 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'
 eval $(sed -n -e '/^TESTS="$/,/^"$/p' notmuch-test ../notmuch-test)
 tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)
 available=$(ls -1 ../ | \
-    sed -r -e "/^(aggregate-results.sh|Makefile|Makefile.local|notmuch-test)/d" \
-	   -e "/^(README|test-lib.sh|test-lib.el|test-results|tmp.*|valgrind|corpus*)/d" \
-	   -e "/^(emacs.expected-output|smtp-dummy|smtp-dummy.c|test-verbose)/d" \
-	   -e "/^(test.expected-output|.*~)/d" \
-	   -e "/^(gnupg-secret-key.asc)/d" \
-	   -e "/^(gnupg-secret-key.NOTE)/d" \
-	   | sort)
+    $SED_EXTENDED -e "/^(aggregate-results.sh|Makefile|Makefile.local|notmuch-test)/d" \
+    		  -e "/^(README|test-lib.sh|test-lib.el|test-results|tmp.*|valgrind|corpus*)/d" \
+    		  -e "/^(emacs.expected-output|smtp-dummy|smtp-dummy.c|test-verbose)/d" \
+	   	  -e "/^(test.expected-output|.*~)/d" \
+	   	  -e "/^(gnupg-secret-key.asc)/d" \
+	   	  -e "/^(gnupg-secret-key.NOTE)/d" \
+	   	  -e "/^(test-config*)/d" \
+	   	  | sort)
 test_expect_equal "$tests_in_suite" "$available"
 
 EXPECTED=../test.expected-output
diff --git a/test/test-config-bsd.sh b/test/test-config-bsd.sh
new file mode 100644
index 0000000..e35d2fa
--- /dev/null
+++ b/test/test-config-bsd.sh
@@ -0,0 +1,23 @@
+# This file contains helper functions and other values that are
+# require platform-specific functionality (e.g., differing between GNU
+# and BSD). The configure script is used to identify the appropriate
+# file for a given platform, and copies the file test-config-FOO.sh to
+# test-config.sh, where FOO is the respective platform (bsd or gnu).
+#
+# This file is BSD-specific.
+
+# Syntax for extended expressions
+SED_EXTENDED="sed -E"
+
+# There is no touch -d on BSD, therefore we have to use a more tedious
+# version that uses date/stat to increment a date by a single second.
+increment_mtime_amount=0
+increment_mtime ()
+{
+    dir="$1"
+    
+    last_mod_date=`date -j -f %Y%m%d%H%M%S \`stat -f %Sm -t %Y%m%d%H%M%S ${dir}\` +%s`
+    increment_mtime_amount=$((increment_mtime_amount + 1))
+    new_date=`date -j -r ${last_mod_date} -v+${increment_mtime_amount}S +%Y%m%d%H%M.%S`
+    touch -t ${new_date} ${dir}
+}
diff --git a/test/test-config-gnu.sh b/test/test-config-gnu.sh
new file mode 100644
index 0000000..596505a
--- /dev/null
+++ b/test/test-config-gnu.sh
@@ -0,0 +1,20 @@
+# This file contains helper functions and other values that are
+# require platform-specific functionality (e.g., differing between GNU
+# and BSD). The configure script is used to identify the appropriate
+# file for a given platform, and copies the file test-config-FOO.sh to
+# test-config.sh, where FOO is the respective platform (bsd or gnu).
+#
+# This file is GNU-specific.
+
+# Syntax for extended expressions
+SED_EXTENDED="sed -r"
+
+# Use touch to increment the modification date by a single second.
+increment_mtime_amount=0
+increment_mtime ()
+{
+    dir="$1"
+
+    increment_mtime_amount=$((increment_mtime_amount + 1))
+    touch -d "+${increment_mtime_amount} seconds" "$dir"
+}
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 922b1ef..1aa3a1c 100755
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -23,6 +23,9 @@ if [ ${BASH_VERSINFO[0]} -lt 4 ]; then
     exit 1
 fi
 
+# Load platform-specific values
+. ./test-config.sh
+
 # if --tee was passed, write the output not only to the terminal, but
 # additionally to the file test-results/$BASENAME.out, too.
 case "$GIT_TEST_TEE_STARTED, $* " in
@@ -214,14 +217,6 @@ remove_cr () {
 }
 
 # Notmuch helper functions
-increment_mtime_amount=0
-increment_mtime ()
-{
-    dir="$1"
-
-    increment_mtime_amount=$((increment_mtime_amount + 1))
-    touch -d "+${increment_mtime_amount} seconds" "$dir"
-}
 
 # Generate a new message in the mail directory, with a unique message
 # ID and subject. The message is not added to the index.
@@ -514,7 +509,7 @@ NOTMUCH_NEW ()
 
 notmuch_search_sanitize ()
 {
-    sed -r -e 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
+    $SED_EXTENDED 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
 }
 
 NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'

[-- Attachment #2: Type: application/pgp-signature, Size: 202 bytes --]

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

end of thread, other threads:[~2011-05-30 12:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-25 13:07 [PATCH] Change in increment_mtime for BSD compatibility of test suite Felix Geller
2011-05-26 22:12 ` Carl Worth
2011-05-30 12:40   ` Felix Geller

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