all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to assert "throw" by ERT?
@ 2013-01-17 21:03 Oleksandr Gavenko
  2013-01-18  3:15 ` Dmitry Gutov
  0 siblings, 1 reply; 2+ messages in thread
From: Oleksandr Gavenko @ 2013-01-17 21:03 UTC (permalink / raw)
  To: help-gnu-emacs

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'.

Please help me with example...

-- 
Best regards!




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to assert "throw" by ERT?
  2013-01-17 21:03 How to assert "throw" by ERT? Oleksandr Gavenko
@ 2013-01-18  3:15 ` Dmitry Gutov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Gutov @ 2013-01-18  3:15 UTC (permalink / raw)
  To: Oleksandr Gavenko; +Cc: help-gnu-emacs

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))



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-01-18  3:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-17 21:03 How to assert "throw" by ERT? Oleksandr Gavenko
2013-01-18  3:15 ` Dmitry Gutov

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.