unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: mp39590@gmail.com
To: notmuch@notmuchmail.org
Subject: [PATCH] test: compatibility layer
Date: Tue, 20 Dec 2016 15:07:12 +0300	[thread overview]
Message-ID: <20161220120712.98083-1-mp39590@gmail.com> (raw)

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

                 reply	other threads:[~2016-12-20 12:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161220120712.98083-1-mp39590@gmail.com \
    --to=mp39590@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).