unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: ERT: should-error doesn't catch failed assertions
Date: Mon, 18 Jul 2016 00:57:41 +0200	[thread overview]
Message-ID: <86vb03rhy2.fsf@student.uu.se> (raw)
In-Reply-To: 87d1mb9a3u.fsf@gmail.com

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 -                   


  reply	other threads:[~2016-07-17 22:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-17 22:24 ERT: should-error doesn't catch failed assertions Sean McAfee
2016-07-17 22:57 ` Emanuel Berg [this message]
2016-07-17 23:29   ` Sean McAfee
2016-07-18  0:42     ` Emanuel Berg
2016-07-18  4:19 ` Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86vb03rhy2.fsf@student.uu.se \
    --to=embe8573@student.uu.se \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).