From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Giorgos Keramidas Newsgroups: gmane.emacs.help Subject: Re: assert()ing in elisp Date: Thu, 29 Jun 2006 20:12:00 +0300 Organization: SunSITE.dk - Supporting Open source Message-ID: <868xnfx4wv.fsf@gothmog.pc> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1151602963 30525 80.91.229.2 (29 Jun 2006 17:42:43 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 29 Jun 2006 17:42:43 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 29 19:41:31 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Fw0Vz-0000rf-IU for geh-help-gnu-emacs@m.gmane.org; Thu, 29 Jun 2006 19:41:21 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fw0Vy-0003VY-U0 for geh-help-gnu-emacs@m.gmane.org; Thu, 29 Jun 2006 13:41:18 -0400 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (berkeley-unix) Cancel-Lock: sha1:5/Tjh5PRCQjBKyX8fa2ZVrkvoxE= Original-Lines: 29 Original-NNTP-Posting-Host: 62.103.39.229 Original-X-Trace: news.sunsite.dk DXC=6SFh>oOQAOPOP]JQ=foLd_YSB=nbEKnk[0R7fAh>ERC_L^MjW2:ak; I7eU]WGb30c[>DY7[ List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:35731 Archived-At: On Thu, 29 Jun 2006 06:26:09 -0700, Eric Hanchrow wrote: > Here's one example: > (defun assert= (expected actual) > (when (not (string-equal expected actual)) > (error "expected %S; got %S" expected actual))) Or you could use a macro, which can print the assertion that failed too: ,---------------------------------------------------------------- | (defmacro assert (test-form) | `(when (not ,test-form) | (error "Assertion failed: %s" (format "%s" ',test-form)))) | | (assert (equal t nil)) | => | Debugger entered--Lisp error: (error "Assertion failed: (equal t nil)") | signal(error ("Assertion failed: (equal t nil)")) | error("Assertion failed: %s" "(equal t nil)") | (progn (error "Assertion failed: %s" (format "%s" ...))) | (if (not (equal t nil)) (progn (error "Assertion failed: %s" ...))) | (when (not (equal t nil)) (error "Assertion failed: %s" (format "%s" ...))) | (assert (equal t nil)) | eval((assert (equal t nil))) | eval-last-sexp-1(nil) | eval-last-sexp(nil) | call-interactively(eval-last-sexp) `----------------------------------------------------------------