[PATCH 2/4] test: Add address cleaning tests.

Dmitry Kurochkin dmitry.kurochkin at gmail.com
Tue Jan 17 05:11:58 PST 2012


On Tue, 17 Jan 2012 12:52:26 +0000, David Edmondson <dme at dme.org> wrote:
> Including some more test framework in test-lib.el.
> ---
>  test/address-cleaning.el |   29 +++++++++++++++++++++++++++++
>  test/address-cleaning.sh |   11 +++++++++++
>  test/notmuch-test        |    1 +
>  test/test-lib.el         |   29 +++++++++++++++++++++++++++++
>  4 files changed, 70 insertions(+), 0 deletions(-)
>  create mode 100644 test/address-cleaning.el
>  create mode 100755 test/address-cleaning.sh
> 

Since test/ directory is used for all kind of tests not just Emacs
UI-specific, so I think address-cleaning.* files should be
emacs-address-cleaning.

Regards,
  Dmitry

> diff --git a/test/address-cleaning.el b/test/address-cleaning.el
> new file mode 100644
> index 0000000..59e8d92
> --- /dev/null
> +++ b/test/address-cleaning.el
> @@ -0,0 +1,29 @@
> +(defun notmuch-test-address-cleaning-1 ()
> +  (notmuch-test-compare (notmuch-show-clean-address "dme at dme.org")
> +			"dme at dme.org"))
> +
> +(defun notmuch-test-address-cleaning-2 ()
> +  (let* ((input '("foo at bar.com"
> +		  "<foo at bar.com>"
> +		  "Foo Bar <foo at bar.com>"
> +		  "foo at bar.com <foo at bar.com>"
> +		  "\"Foo Bar\" <foo at bar.com>"))
> +	 (expected '("foo at bar.com"
> +		     "foo at bar.com"
> +		     "Foo Bar <foo at bar.com>"
> +		     "foo at bar.com"
> +		     "Foo Bar <foo at bar.com>"))
> +	 (output (mapcar #'notmuch-show-clean-address input)))
> +    (notmuch-test-compare output expected)))
> +
> +(defun notmuch-test-address-cleaning-3 ()
> +  (let* ((input '("ДБ <db-uknot at stop.me.uk>"
> +		  "foo (at home) <foo at bar.com>"
> +		  "foo [at home] <foo at bar.com>"
> +		  "Foo Bar"))
> +	 (expected '("ДБ <db-uknot at stop.me.uk>"
> +		     "foo (at home) <foo at bar.com>"
> +		     "foo [at home] <foo at bar.com>"
> +		     "Foo Bar"))
> +	 (output (mapcar #'notmuch-show-clean-address input)))
> +    (notmuch-test-compare output expected)))
> diff --git a/test/address-cleaning.sh b/test/address-cleaning.sh
> new file mode 100755
> index 0000000..7ec011a
> --- /dev/null
> +++ b/test/address-cleaning.sh
> @@ -0,0 +1,11 @@
> +#!/usr/bin/env bash
> +
> +test_description="emacs address cleaning"
> +. test-lib.sh
> +
> +for i in 1 2 3; do
> +    test_emacs_expect_t "notmuch-test-address-clean-$i" \
> +    '(load "address-cleaning.el") (notmuch-test-address-cleaning-'$i')'
> +done
> +
> +test_done
> diff --git a/test/notmuch-test b/test/notmuch-test
> index d034f99..7768c32 100755
> --- a/test/notmuch-test
> +++ b/test/notmuch-test
> @@ -53,6 +53,7 @@ TESTS="
>    hooks
>    argument-parsing
>    emacs-test-functions.sh
> +  address-cleaning.sh
>  "
>  TESTS=${NOTMUCH_TESTS:=$TESTS}
>  
> diff --git a/test/test-lib.el b/test/test-lib.el
> index 3b817c3..cf8a46d 100644
> --- a/test/test-lib.el
> +++ b/test/test-lib.el
> @@ -20,6 +20,8 @@
>  ;;
>  ;; Authors: Dmitry Kurochkin <dmitry.kurochkin at gmail.com>
>  
> +(require 'cl)	;; This code is generally used uncompiled.
> +
>  ;; `read-file-name' by default uses `completing-read' function to read
>  ;; user input.  It does not respect `standard-input' variable which we
>  ;; use in tests to provide user input.  So replace it with a plain
> @@ -76,3 +78,30 @@ nothing."
>  
>  (add-hook-counter 'notmuch-hello-mode-hook)
>  (add-hook-counter 'notmuch-hello-refresh-hook)
> +
> +;; Functions to help when writing tests:
> +
> +(defun notmuch-test-reporter (output expected)
> +  "Report that the `output' does not match the `expected' result."
> +  (concat "Expect:\t" (prin1-to-string expected) "\n"
> +	  "Output:\t" (prin1-to-string output) "\n"))
> +
> +(defun notmuch-test-unsimilar (output expected)
> +  "`output' and `expected' are dissimilar. Show a summary of
> +the differences, ignoring similarities."
> +  (cond ((and (listp output)
> +	      (listp expected))
> +	 (apply #'concat (loop for o in output
> +			       for e in expected
> +			       if (not (equal o e))
> +			       collect (notmuch-test-reporter o e))))
> +
> +	(t
> +	 ;; Catch all case.
> +	 (notmuch-test-reporter output expected))))
> +
> +(defun notmuch-test-compare (output expected)
> +  "Compare `output' with `expected'. Report any discrepencies."
> +  (if (equal output expected)
> +      t
> +    (notmuch-test-unsimilar output expected)))
> -- 
> 1.7.7.3
> 
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


More information about the notmuch mailing list