[PATCH] test: compatibility layer
mp39590 at gmail.com
mp39590 at gmail.com
Tue Dec 20 04:07:12 PST 2016
From: Mikhail <mp39590 at gmail.com>
Use compatibility function for base64 encoder in json and sexp tests
instead of native utils.
FreeBSD's and Linux's base64 utility encode content with different
number of columns in output, which makes the tests fail for the former.
---
test/T160-json.sh | 2 +-
test/T170-sexp.sh | 2 +-
test/test-lib.sh | 10 ++++++++++
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/test/T160-json.sh b/test/T160-json.sh
index b346f37e..77a9ef54 100755
--- a/test/T160-json.sh
+++ b/test/T160-json.sh
@@ -47,7 +47,7 @@ emacs_fcc_message \
output=$(notmuch show --format=json "id:$id")
filename=$(notmuch search --output=files "id:$id")
# Get length of README after base64-encoding, minus additional newline.
-attachment_length=$(( $(base64 $TEST_DIRECTORY/README | wc -c) - 1 ))
+attachment_length=$(( $(compat_base64 $TEST_DIRECTORY/README | wc -c) - 1 ))
test_expect_equal_json "$output" "[[[{\"id\": \"$id\", \"match\": true, \"excluded\": false, \"filename\": \"$filename\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\"], \"headers\": {\"Subject\": \"$subject\", \"From\": \"Notmuch Test Suite <test_suite at notmuchmail.org>\", \"To\": \"test_suite at notmuchmail.org\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"multipart/mixed\", \"content\": [{\"id\": 2, \"content-type\": \"text/plain\", \"content\": \"This is a test message with inline attachment with a filename\"}, {\"id\": 3, \"content-type\": \"application/octet-stream\", \"content-length\": $attachment_length, \"content-transfer-encoding\": \"base64\", \"filename\": \"README\"}]}]}, []]]]"
test_begin_subtest "Search message: json, utf-8"
diff --git a/test/T170-sexp.sh b/test/T170-sexp.sh
index 800ebc63..943475e4 100755
--- a/test/T170-sexp.sh
+++ b/test/T170-sexp.sh
@@ -38,7 +38,7 @@ emacs_fcc_message \
output=$(notmuch show --format=sexp "id:$id")
filename=$(notmuch search --output=files "id:$id")
# Get length of README after base64-encoding, minus additional newline.
-attachment_length=$(( $(base64 $TEST_DIRECTORY/README | wc -c) - 1 ))
+attachment_length=$(( $(compat_base64 $TEST_DIRECTORY/README | wc -c) - 1 ))
test_expect_equal "$output" "((((:id \"$id\" :match t :excluded nil :filename \"$filename\" :timestamp 946728000 :date_relative \"2000-01-01\" :tags (\"inbox\") :headers (:Subject \"sexp-show-inline-attachment-filename\" :From \"Notmuch Test Suite <test_suite at notmuchmail.org>\" :To \"test_suite at notmuchmail.org\" :Date \"Sat, 01 Jan 2000 12:00:00 +0000\") :body ((:id 1 :content-type \"multipart/mixed\" :content ((:id 2 :content-type \"text/plain\" :content \"This is a test message with inline attachment with a filename\") (:id 3 :content-type \"application/octet-stream\" :filename \"README\" :content-transfer-encoding \"base64\" :content-length $attachment_length))))) ())))"
test_begin_subtest "Search message: sexp, utf-8"
diff --git a/test/test-lib.sh b/test/test-lib.sh
index f55d2c67..ae3fc004 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -101,6 +101,16 @@ _x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
_x04='[0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
_x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04"
+# OS independent functions
+#
+# Base64 utility formats output in different number of columns in different
+# OS'es, 72 for FreeBSD and 76 for Linux.
+compat_base64() {
+ if [[ ! -z $1 ]]; then
+ base64 $1 | paste -sd'\0' - | fold -w 76
+ fi
+}
+
# Each test should start with something like this, after copyright notices:
#
# test_description='Description of this test...
--
2.11.0
More information about the notmuch
mailing list