From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: David Pirotte Newsgroups: gmane.lisp.guile.devel Subject: Re: guile-lib - devel branch - unit-test 2 new APIs - 1 patch Date: Sun, 15 Jan 2017 17:55:09 -0200 Message-ID: <20170115175509.7328a7d4@capac> References: <20161022230653.492af74b@capac> <874m1113jq.fsf@ac.upc.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; boundary="Sig_/MsJ5K3q7HdL5Eao_ZAIJL3B"; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1484510180 27669 195.159.176.226 (15 Jan 2017 19:56:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 15 Jan 2017 19:56:20 +0000 (UTC) Cc: guile-devel To: =?UTF-8?B?TGx1w61z?= Vilanova Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Jan 15 20:56:15 2017 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cSquF-0005TU-8O for guile-devel@m.gmane.org; Sun, 15 Jan 2017 20:55:59 +0100 Original-Received: from localhost ([::1]:52723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cSquF-0000HR-Lm for guile-devel@m.gmane.org; Sun, 15 Jan 2017 14:55:59 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51670) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cSqty-0000GP-1F for guile-devel@gnu.org; Sun, 15 Jan 2017 14:55:43 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cSqtu-0001Rv-SF for guile-devel@gnu.org; Sun, 15 Jan 2017 14:55:42 -0500 Original-Received: from maximusconfessor.all2all.org ([79.99.200.102]:57251) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cSqtu-0001QP-IB for guile-devel@gnu.org; Sun, 15 Jan 2017 14:55:38 -0500 Original-Received: from localhost (unknown [192.168.0.2]) by maximusconfessor.all2all.org (Postfix) with ESMTP id B3851A04C176; Sun, 15 Jan 2017 20:55:20 +0100 (CET) Original-Received: from maximusconfessor.all2all.org ([192.168.0.1]) by localhost (maximusconfessor.all2all.org [192.168.0.2]) (amavisd-new, port 10024) with ESMTP id 8wPLXRHAQnNR; Sun, 15 Jan 2017 20:55:16 +0100 (CET) Original-Received: from capac (unknown [179.210.16.159]) by maximusconfessor.all2all.org (Postfix) with ESMTPSA id DE762A04C1C9; Sun, 15 Jan 2017 20:55:15 +0100 (CET) In-Reply-To: <874m1113jq.fsf@ac.upc.edu> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 79.99.200.102 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:18856 Archived-At: --Sig_/MsJ5K3q7HdL5Eao_ZAIJL3B Content-Type: multipart/mixed; boundary="MP_/Tgg77M9lM9X9wyfFe.e0xnp" --MP_/Tgg77M9lM9X9wyfFe.e0xnp Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi Llu=C3=ADs, > Nit pick: I don't know what's the coding convention in guile, but your us= e of > tabs is inconsistent within the patch and across the rest of the file. Oh, I thought I had the proper emacs config, but no! I fixed that now, her= e is an updated patch. Thanks, David --MP_/Tgg77M9lM9X9wyfFe.e0xnp Content-Type: text/x-patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=0001-Unit-test-2-new-APIs.patch =46rom 0b34a9196718e030c9e8c9a0095aec8f0da58425 Mon Sep 17 00:00:00 2001 From: David Pirotte Date: Sun, 15 Jan 2017 17:49:10 -0200 Subject: [PATCH] Unit-test 2 new APIs * src/unit-test.scm: New assert-false procedure, new assert macro: both take an expression as their respective argument; assert-false will throw a 'test-failed-exception unless expression returns #f; assert will throw a 'test-failed-exception if expression raises an exception. --- src/unit-test.scm | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/src/unit-test.scm b/src/unit-test.scm index a46b6fc..3adf971 100644 --- a/src/unit-test.scm +++ b/src/unit-test.scm @@ -26,6 +26,7 @@ #:use-module (ice-9 pretty-print) #:export (assert-equal assert-true + assert-false assert-numeric-=3D =20 tests-run=20 @@ -46,7 +47,8 @@ run-all-defined-test-cases exit-with-summary) =20 - #:export-syntax (assert-exception)) + #:export-syntax (assert + assert-exception)) =20 =20 ;; Utility method for finding an object's method given its name. The @@ -105,31 +107,48 @@ (display " got: ") (write got)))))) =20 +(define (assert-false got) + (if got + (throw 'test-failed-exception + (with-output-to-string + (lambda () + (display "assert-false: ") + (display " got: ") + (write got)))))) + (define (assert-numeric-=3D expected got precision) (if (> (abs (- expected got)) precision) (throw 'test-failed-exception (with-output-to-string (lambda () (display "assert-numeric-=3D: expected:\n") - (pretty-print expected) - (display " precision: ") - (pretty-print precision) + (pretty-print expected) + (display " precision: ") + (pretty-print precision) (display " got: ") (write got)))))) =20 +(define-macro (assert expression) + `(catch #t + (lambda () ,expression) + (lambda (key . args) + (throw + 'test-failed-exception + (format #f "assert: exception on ~S" + ',expression))))) =20 (define-macro (assert-exception expression) `(catch #t - (lambda () - ,expression - (throw - 'test-failed-exception - (format #f "assert-exception: no exception on ~S" - ',expression))) - (lambda (key . args) - (case key - ((test-failed-exception) (apply throw key args)) - (else #t))))) + (lambda () + ,expression + (throw + 'test-failed-exception + (format #f "assert-exception: no exception on ~S" + ',expression))) + (lambda (key . args) + (case key + ((test-failed-exception) (apply throw key args)) + (else #t))))) =20 =20 ;;;---------------------------------------------------------------- --=20 2.11.0 --MP_/Tgg77M9lM9X9wyfFe.e0xnp-- --Sig_/MsJ5K3q7HdL5Eao_ZAIJL3B Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEhCJlRZtBM3furJHe83T9k6MFetcFAlh7050ACgkQ83T9k6MF etcuuwf/W+R1ObbtueuAzQG1LdP9O7oHoFRkxKLRXvfcq484Viwa/QldF99Bkts7 thdIVK4E5RsykAKPWnyb5DTj3sKtcKWb+N9R3M4sxB3idXbZYwrVDlKFepIlwcn+ ooTdBb7U4vGQ33GQexTG3EEd0AumeK+XQGOECsfJlnvDnwl15erROUskyv5ADM1I A9IKYpzcDds3HmqAqMMYpivye4mKckyy2DhIW8jG+Hdk74R7W4iPXvD23r+PdYwT JhqG4n1YuY9a7cKlKzAjLKv/A0j+Bj49S9xG+bxb56JN4Pw7IMU3GWqST/QAAtVf 5yMAs0ghkviQLHWTivnCoAHxxnICfg== =PHeT -----END PGP SIGNATURE----- --Sig_/MsJ5K3q7HdL5Eao_ZAIJL3B--