[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ERT: should-error doesn't catch failed assertions
From: |
Emanuel Berg |
Subject: |
Re: ERT: should-error doesn't catch failed assertions |
Date: |
Mon, 18 Jul 2016 00:57:41 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
Sean McAfee <eefacm@gmail.com> writes:
> (should-error (cl-assert nil))
What is "should-error"?
> (def my-checksum (str) (cl-assert (= 5 (length
> str))) ; ... )
With `defun' instead of "def", your code works:
(require 'cl-lib)
(defun my-checksum (str)
(cl-assert (= 5 (length str)))
)
(my-checksum "abcdfg") ; error
(my-checksum "abcdf") ; nil
(my-checksum "abcd") ; error
Unit testing and input verification isn't
necessary but can be helpful.
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.
Also, `condition-case' may be useful if you
don't know about it already.
Here is an article about testing - it should be
done, but not overemphasized. The best method
of testing is to have a lot of people using
your software. The second best method is for
you to use the system a lot. I guess the
various methods proposed are a distant third...
http://user.it.uu.se/~embe8573/testing.txt
--
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
- so far: 58 Blogomatic articles -