[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to assert "throw" by ERT?
From: |
Dmitry Gutov |
Subject: |
Re: How to assert "throw" by ERT? |
Date: |
Fri, 18 Jan 2013 07:15:43 +0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (windows-nt) |
Oleksandr Gavenko <gavenkoa@gmail.com> writes:
> ERT is Emacs Lisp Regression Testing and ERT packed in GNU Emacs.
>
> I want to check that my function throw on some input data:
>
> (defun foo (arg) (unless arg (throw :invalid-arg nil)))
>
> I write:
>
> (ert-deftest foo-fail-test ()
> (should-error (foo nil) :type :invalid-arg)
> )
>
> but seems this is wrong usege or 'should-error'.
In Emacs Lisp, `throw' and `catch' are a control flow mechanism, not
exception handling primitives. But your function will indeed error,
because it can't find a matching `catch' block. This test passes:
(ert-deftest foo-fail-test ()
(should-error (foo nil) :type 'no-catch))