[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Dynamic modules: should should-error work?
From: |
Eli Zaretskii |
Subject: |
Re: Dynamic modules: should should-error work? |
Date: |
Mon, 23 Nov 2015 22:09:16 +0200 |
> From: Philipp Stephani <address@hidden>
> Date: Mon, 23 Nov 2015 19:28:09 +0000
>
> Eli Zaretskii <address@hidden> 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")))