[PATCH] Change in increment_mtime for BSD compatibility of test suite

2011-05-30 Thread Felix Geller
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 000..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 000..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"
-
-

Re: [PATCH] Change in increment_mtime for BSD compatibility of test suite

2011-05-30 Thread Felix Geller
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 000..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 000..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 

[PATCH] Change in increment_mtime for BSD compatibility of test suite

2011-05-26 Thread Carl Worth
On Wed, 25 May 2011 15:07:52 +0200, Felix Geller  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 at intel.com
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 



[PATCH] Change in increment_mtime for BSD compatibility of test suite

2011-05-25 Thread Felix Geller
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
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 202 bytes
Desc: not available
URL: