aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Austin Clements <amdragon@MIT.EDU>2014-04-21 14:37:39 -0400
committerGravatar David Bremner <david@tethera.net>2014-09-21 21:23:45 +0200
commitf4cdabccd0e75d94d7f6f4d50684afc67bbf7f0d (patch)
tree273bd6ea6d663db63305c4d9aa331ad479973992 /test
parent0b94dd7fd3dcd071ebbe498cd80f5fd687a78e08 (diff)
test: New tests for Emacs charset handling
The test of viewing 8bit messages is known-broken. The rest pass, but for very fragile reasons. The next several commits will fix the known-broken test and make our charset handling robust.
Diffstat (limited to 'test')
-rwxr-xr-xtest/T455-emacs-charsets.sh141
-rw-r--r--test/test-lib.el4
2 files changed, 144 insertions, 1 deletions
diff --git a/test/T455-emacs-charsets.sh b/test/T455-emacs-charsets.sh
new file mode 100755
index 00000000..a42a1d20
--- /dev/null
+++ b/test/T455-emacs-charsets.sh
@@ -0,0 +1,141 @@
+#!/usr/bin/env bash
+
+test_description="emacs notmuch-show charset handling"
+. ./test-lib.sh
+
+
+UTF8_YEN=$'\xef\xbf\xa5'
+BIG5_YEN=$'\xa2\x44'
+
+# Add four messages with unusual encoding requirements:
+#
+# 1) text/plain in quoted-printable big5
+generate_message \
+ [id]=test-plain@example.com \
+ '[content-type]="text/plain; charset=big5"' \
+ '[content-transfer-encoding]=quoted-printable' \
+ '[body]="Yen: =A2=44"'
+
+# 2) text/plain in 8bit big5
+generate_message \
+ [id]=test-plain-8bit@example.com \
+ '[content-type]="text/plain; charset=big5"' \
+ '[content-transfer-encoding]=8bit' \
+ '[body]="Yen: '$BIG5_YEN'"'
+
+# 3) text/html in quoted-printable big5
+generate_message \
+ [id]=test-html@example.com \
+ '[content-type]="text/html; charset=big5"' \
+ '[content-transfer-encoding]=quoted-printable' \
+ '[body]="<html><body>Yen: =A2=44</body></html>"'
+
+# 4) application/octet-stream in quoted-printable of big5 text
+generate_message \
+ [id]=test-binary@example.com \
+ '[content-type]="application/octet-stream"' \
+ '[content-transfer-encoding]=quoted-printable' \
+ '[body]="Yen: =A2=44"'
+
+notmuch new > /dev/null
+
+# Test rendering
+
+test_begin_subtest "Text parts are decoded when rendering"
+test_emacs '(notmuch-show "id:test-plain@example.com")
+ (test-visible-output "OUTPUT.raw")'
+awk 'show {print} /^$/ {show=1}' < OUTPUT.raw > OUTPUT
+cat <<EOF >EXPECTED
+Yen: $UTF8_YEN
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "8bit text parts are decoded when rendering"
+test_emacs '(notmuch-show "id:test-plain-8bit@example.com")
+ (test-visible-output "OUTPUT.raw")'
+awk 'show {print} /^$/ {show=1}' < OUTPUT.raw > OUTPUT
+cat <<EOF >EXPECTED
+Yen: $UTF8_YEN
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "HTML parts are decoded when rendering"
+test_emacs '(notmuch-show "id:test-html@example.com")
+ (test-visible-output "OUTPUT.raw")'
+awk 'show {print} /^$/ {show=1}' < OUTPUT.raw > OUTPUT
+cat <<EOF >EXPECTED
+[ text/html ]
+Yen: $UTF8_YEN
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+# Test saving
+
+test_begin_subtest "Text parts are not decoded when saving"
+rm -f part
+test_emacs '(notmuch-show "id:test-plain@example.com")
+ (search-forward "Yen")
+ (let ((standard-input "\"part\""))
+ (notmuch-show-save-part))'
+cat <<EOF >EXPECTED
+Yen: $BIG5_YEN
+EOF
+test_expect_equal_file part EXPECTED
+
+test_begin_subtest "8bit text parts are not decoded when saving"
+rm -f part
+test_emacs '(notmuch-show "id:test-plain-8bit@example.com")
+ (search-forward "Yen")
+ (let ((standard-input "\"part\""))
+ (notmuch-show-save-part))'
+cat <<EOF >EXPECTED
+Yen: $BIG5_YEN
+EOF
+test_expect_equal_file part EXPECTED
+
+test_begin_subtest "HTML parts are not decoded when saving"
+rm -f part
+test_emacs '(notmuch-show "id:test-html@example.com")
+ (search-forward "Yen")
+ (let ((standard-input "\"part\""))
+ (notmuch-show-save-part))'
+cat <<EOF >EXPECTED
+<html><body>Yen: $BIG5_YEN</body></html>
+EOF
+test_expect_equal_file part EXPECTED
+
+test_begin_subtest "Binary parts are not decoded when saving"
+rm -f part
+test_emacs '(notmuch-show "id:test-binary@example.com")
+ (search-forward "application/")
+ (let ((standard-input "\"part\""))
+ (notmuch-show-save-part))'
+cat <<EOF >EXPECTED
+Yen: $BIG5_YEN
+EOF
+test_expect_equal_file part EXPECTED
+
+# Test message viewing
+
+test_begin_subtest "Text message are not decoded when viewing"
+test_emacs '(notmuch-show "id:test-plain@example.com")
+ (notmuch-show-view-raw-message)
+ (test-visible-output "OUTPUT.raw")'
+awk 'show {print} /^$/ {show=1}' < OUTPUT.raw > OUTPUT
+cat <<EOF >EXPECTED
+Yen: =A2=44
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "8bit text message are not decoded when viewing"
+test_subtest_known_broken
+test_emacs '(notmuch-show "id:test-plain-8bit@example.com")
+ (notmuch-show-view-raw-message)
+ (test-visible-output "OUTPUT.raw")'
+awk 'show {print} /^$/ {show=1}' < OUTPUT.raw > OUTPUT
+cat <<EOF >EXPECTED
+Yen: $BIG5_YEN
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_done
diff --git a/test/test-lib.el b/test/test-lib.el
index bbc03cba..04c8d634 100644
--- a/test/test-lib.el
+++ b/test/test-lib.el
@@ -59,7 +59,9 @@
"Save visible text in current buffer to file FILENAME. Default
FILENAME is OUTPUT."
(notmuch-post-command)
- (let ((text (visible-buffer-string)))
+ (let ((text (visible-buffer-string))
+ ;; Tests expect output in UTF-8 encoding
+ (coding-system-for-write 'utf-8))
(with-temp-file (or filename "OUTPUT") (insert text))))
(defun visible-buffer-string ()