From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: ERT: should-error doesn't catch failed assertions Date: Mon, 18 Jul 2016 00:57:41 +0200 Organization: Aioe.org NNTP Server Message-ID: <86vb03rhy2.fsf@student.uu.se> References: <87d1mb9a3u.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1468796433 3087 80.91.229.3 (17 Jul 2016 23:00:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 17 Jul 2016 23:00:33 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 18 01:00:32 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bOv2z-0002hH-R1 for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Jul 2016 01:00:29 +0200 Original-Received: from localhost ([::1]:43335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bOv2y-0004dP-SM for geh-help-gnu-emacs@m.gmane.org; Sun, 17 Jul 2016 19:00:28 -0400 Original-Path: usenet.stanford.edu!news.glorb.com!feeder.erje.net!2.eu.feeder.erje.net!news.unit0.net!news.mixmin.net!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 44 Original-NNTP-Posting-Host: EoOtCC1fCYcttx6jjhWUlA.user.gioia.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:eJ5RZOqSDzUbqoaGMOxtuKAuhR8= Mail-Copies-To: never Original-Xref: usenet.stanford.edu gnu.emacs.help:218565 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:110876 Archived-At: Sean McAfee 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 -