unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] test: compatibility layer
@ 2016-12-20 12:07 mp39590
  0 siblings, 0 replies; only message in thread
From: mp39590 @ 2016-12-20 12:07 UTC (permalink / raw)
  To: notmuch

From: Mikhail <mp39590@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@notmuchmail.org>\", \"To\": \"test_suite@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@notmuchmail.org>\" :To \"test_suite@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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-12-20 12:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-20 12:07 [PATCH] test: compatibility layer mp39590

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