[PATCH] tests: add compatibility layer

mp39590 at gmail.com mp39590 at gmail.com
Tue Dec 20 11:47:05 PST 2016


From: Mikhail <mp39590 at 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



More information about the notmuch mailing list