all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Philipp Stephani <p.stephani2@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Dynamic modules: should should-error work?
Date: Mon, 23 Nov 2015 22:09:16 +0200	[thread overview]
Message-ID: <83si3wzdeb.fsf@gnu.org> (raw)
In-Reply-To: <CAArVCkS_5WfW2jusjH5jxV8c2nvK-4cx=2hGmnM82Lqg4ht_8A@mail.gmail.com>

> From: Philipp Stephani <p.stephani2@gmail.com>
> Date: Mon, 23 Nov 2015 19:28:09 +0000
> 
> Eli Zaretskii <eliz@gnu.org> schrieb am So., 22. Nov. 2015 um 19:29 Uhr:
> 
>     It looks like should-error doesn't work with functions implemented in
>     modules. For example, try this in modules/mod-test/test.el:
>     
>     (ert-deftest mod-test-sum-test ()
>     (should-error (mod-test-sum 1 2 3)))
>     
>     I cannot get this test to succeed, although the error message about
>     wrong number of arguments is emitted. What am I missing?
>     
> This works for me. Maybe there was some intermittent bug that has since been
> fixed?

Probably.  It works for me now.  Sorry for the noise.

> --- a/modules/mod-test/test.el
> +++ b/modules/mod-test/test.el
> @@ -28,7 +28,8 @@
>  ;;
>  
>  (ert-deftest mod-test-sum-test ()
> -  (should (= (mod-test-sum 1 2) 3)))
> +  (should (= (mod-test-sum 1 2) 3))
> +  (should-error (mod-test-sum 1 2 3) :type 'wrong-number-of-arguments))

Thanks.  I suggest the more thorough test below.  WDYT?

diff --git a/modules/mod-test/test.el b/modules/mod-test/test.el
index 98ce464..7924e3b 100644
--- a/modules/mod-test/test.el
+++ b/modules/mod-test/test.el
@@ -28,7 +28,14 @@
 ;;
 
 (ert-deftest mod-test-sum-test ()
-  (should (= (mod-test-sum 1 2) 3)))
+  (should (= (mod-test-sum 1 2) 3))
+  (let ((descr (should-error (mod-test-sum 1 2 3))))
+    (should (eq (car descr) 'wrong-number-of-arguments))
+    (should (stringp (nth 1 descr)))
+    (should (eq 0
+                (string-match "#<module function at \\(0x\\)?[0-9a-fA-F]+>"
+                              (nth 1 descr))))
+    (should (= (nth 2 descr) 3))))
 
 (ert-deftest mod-test-sum-docstring ()
   (should (string= (documentation 'mod-test-sum) "Return A + B")))



  reply	other threads:[~2015-11-23 20:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-22 18:28 Dynamic modules: should should-error work? Eli Zaretskii
2015-11-23 19:28 ` Philipp Stephani
2015-11-23 20:09   ` Eli Zaretskii [this message]
2015-11-24 19:27     ` Philipp Stephani
2015-11-24 19:32       ` Eli Zaretskii
2015-12-07 20:09         ` Philipp Stephani
2015-12-07 20:18           ` Eli Zaretskii
2015-11-24 19:15   ` Eli Zaretskii

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

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

  git send-email \
    --in-reply-to=83si3wzdeb.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=p.stephani2@gmail.com \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.