unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] tests: add compatibility layer
@ 2016-12-20 19:47 mp39590
  2016-12-20 22:24 ` David Bremner
  0 siblings, 1 reply; 16+ messages in thread
From: mp39590 @ 2016-12-20 19:47 UTC (permalink / raw)
  To: notmuch

From: Mikhail <mp39590@gmail.com>

Allow to expand aliases in test scritps and add glue to alias native BSD
utils into GNU equivalents.
---
 test/README      |  6 ++++++
 test/test-lib.sh | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/test/README b/test/README
index 104a120e..094e1d33 100644
--- a/test/README
+++ b/test/README
@@ -33,6 +33,12 @@ chosen directory to your PATH before running the tests.
 
 e.g. env PATH=/opt/gnu/bin:$PATH make test
 
+For FreeBSD you will need to install coreutils, which provides GNU
+versions of basic utils like 'date' or 'wc'. Also you will need to
+install latest gdb from ports or packages and provide path to it in
+BSD_GDB variable before executing the tests, native FreeBSD gdb will not
+work.
+
 Running Tests
 -------------
 The easiest way to run tests is to say "make test", (or simply run the
diff --git a/test/test-lib.sh b/test/test-lib.sh
index f55d2c67..96c1e095 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -26,6 +26,23 @@ fi
 # Make sure echo builtin does not expand backslash-escape sequences by default.
 shopt -u xpg_echo
 
+# OS independent functions
+#
+# Alias native BSD utilities to usable GNU equivalents.
+case `uname` in
+FreeBSD)
+	# allow using aliases in scripts
+	shopt -s expand_aliases
+
+	alias date=gdate
+	alias base64=gbase64
+	alias gdb=$BSD_GDB
+	alias wc=gwc
+	alias sed="gsed"
+	alias sha256sum=gsha256sum
+	;;
+esac
+
 this_test=${0##*/}
 this_test=${this_test%.sh}
 this_test_bare=${this_test#T[0-9][0-9][0-9]-}
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 16+ messages in thread
* [PATCH] tests: add compatibility layer
@ 2017-03-09 13:32 David Bremner
  2017-03-09 15:47 ` Tomi Ollila
  2017-03-24 20:33 ` Mikhail
  0 siblings, 2 replies; 16+ messages in thread
From: David Bremner @ 2017-03-09 13:32 UTC (permalink / raw)
  To: notmuch; +Cc: Mikhail

From: Mikhail <mp39590@gmail.com>

Make test-lib-common.sh load test-lib-<$PLATFORM>.sh to create
additional shim for platform specifics.

Use test-lib-FREEBSD.sh to call GNU utilities instead of native ones.

- amended by db following Tomi's suggestions
---

I haven't tested this, except to verify it doesn't crash under GNU/Linux

 configure                |  3 +++
 test/README              | 11 +++++++++++
 test/test-lib-FREEBSD.sh |  9 +++++++++
 test/test-lib-common.sh  |  5 +++++
 4 files changed, 28 insertions(+)
 create mode 100644 test/test-lib-FREEBSD.sh

diff --git a/configure b/configure
index fa77eb8f..eb452a12 100755
--- a/configure
+++ b/configure
@@ -1186,6 +1186,9 @@ NOTMUCH_PYTHON=${python}
 # Are the ruby development files (and ruby) available? If not skip
 # building/testing ruby bindings.
 NOTMUCH_HAVE_RUBY_DEV=${have_ruby_dev}
+
+# Platform we are run on
+PLATFORM=${platform}
 EOF
 
 # Finally, after everything configured, inform the user how to continue.
diff --git a/test/README b/test/README
index 104a120e..ae22d6e0 100644
--- a/test/README
+++ b/test/README
@@ -33,6 +33,17 @@ chosen directory to your PATH before running the tests.
 
 e.g. env PATH=/opt/gnu/bin:$PATH make test
 
+For FreeBSD you need to install latest gdb from ports or packages and
+provide path to it in TEST_GDB environment variable before executing
+the tests, native FreeBSD gdb does not not work.  If you install
+coreutils, which provides GNU versions of basic utils like 'date' and
+'base64' on FreeBSD, the test suite will use these instead of the
+native ones. This provides robustness against portability issues with
+these system tools. Most often the tests are written, reviewed and
+tested on Linux system so such portability issues arise from time to
+time.
+
+
 Running Tests
 -------------
 The easiest way to run tests is to say "make test", (or simply run the
diff --git a/test/test-lib-FREEBSD.sh b/test/test-lib-FREEBSD.sh
new file mode 100644
index 00000000..d1840b56
--- /dev/null
+++ b/test/test-lib-FREEBSD.sh
@@ -0,0 +1,9 @@
+# If present, use GNU Coreutils instead of a native BSD utils
+if command -v gdate >/dev/null
+   then
+       date () { gdate "$@"; }
+       base64 () { gbase64 "$@"; }
+       wc () { gwc "$@"; }
+       sed () { gsed "$@"; }
+       sha256sum () { gsha256sum "$@"; }
+   fi
diff --git a/test/test-lib-common.sh b/test/test-lib-common.sh
index a96cfbeb..ef409171 100644
--- a/test/test-lib-common.sh
+++ b/test/test-lib-common.sh
@@ -66,6 +66,11 @@ export LD_LIBRARY_PATH
 # configure output
 . $notmuch_path/sh.config || exit 1
 
+# load OS specifics
+if [ -e ./test-lib-$PLATFORM.sh ]; then
+	. ./test-lib-$PLATFORM.sh || exit 1
+fi
+
 if test -n "$valgrind"
 then
 	make_symlink () {
-- 
2.11.0

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

end of thread, other threads:[~2017-03-25 11:10 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-20 19:47 [PATCH] tests: add compatibility layer mp39590
2016-12-20 22:24 ` David Bremner
2016-12-21  5:12   ` Tomi Ollila
2016-12-21 14:56   ` Mikhail
2016-12-22  9:31   ` mp39590
2016-12-31 11:03     ` David Bremner
2017-01-02 13:57       ` mp39590
2017-01-03 15:48         ` Tomi Ollila
2017-01-03 15:52           ` Tomi Ollila
2017-01-03 17:21           ` Tomi Ollila
2017-01-04  1:57           ` Mikhail
2016-12-31 15:17     ` Tomi Ollila
  -- strict thread matches above, loose matches on Subject: below --
2017-03-09 13:32 David Bremner
2017-03-09 15:47 ` Tomi Ollila
2017-03-24 20:33 ` Mikhail
2017-03-25 11:10   ` 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).