[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ERT: should-error doesn't catch failed assertions
From: |
Sean McAfee |
Subject: |
Re: ERT: should-error doesn't catch failed assertions |
Date: |
Sun, 17 Jul 2016 16:29:51 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) |
Emanuel Berg <embe8573@student.uu.se> writes:
> Sean McAfee <eefacm@gmail.com> writes:
>
>> (should-error (cl-assert nil))
>
> What is "should-error"?
It's part of ERT, Emacs Lisp Regression Testing, mentioned in the
subject. should-error is documented here:
https://www.gnu.org/software/emacs/manual/html_node/ert/The-should-Macro.html#The-should-Macro
As described on that page, I see (should-error (/ 1 0)) evaluate to
(arith-error). But assertion failures seem to not count as "errors" as
far as should-error is concerned.
>> (def my-checksum (str) (cl-assert (= 5 (length
>> str))) ; ... )
>
> With `defun' instead of "def", your code works:
Ah yes, I dashed that off a little too quickly. Apologies.
> In this case you can have an ordinary `if' form
> with an `error' if the string length is
> inconsistent with the the purpose of
> the function.
I could, but I'm a little leery of letting my testing framework dictate
how I write my code.