Hi Lluís,

> Nit pick: I don't know what's the coding convention in guile, but your use 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, here is 
an
updated patch.

Thanks,
David
From 0b34a9196718e030c9e8c9a0095aec8f0da58425 Mon Sep 17 00:00:00 2001
From: David Pirotte <da...@altosw.be>
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-=
             <test-result> 
             tests-run 
@@ -46,7 +47,8 @@
             run-all-defined-test-cases
             exit-with-summary)
   
-  #:export-syntax (assert-exception))
+  #:export-syntax (assert
+                   assert-exception))
 
 
  ;; Utility method for finding an object's method given its name. The
@@ -105,31 +107,48 @@
                  (display " got: ")
                  (write got))))))
 
+(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-= expected got precision)
   (if (> (abs (- expected got)) precision)
       (throw 'test-failed-exception
              (with-output-to-string
                (lambda ()
                  (display "assert-numeric-=: expected:\n")
-		 (pretty-print expected)
-		 (display " precision: ")
-		 (pretty-print precision)
+                 (pretty-print expected)
+                 (display " precision: ")
+                 (pretty-print precision)
                  (display " got: ")
                  (write got))))))
 
+(define-macro (assert expression)
+  `(catch #t
+     (lambda () ,expression)
+     (lambda (key . args)
+       (throw
+        'test-failed-exception
+        (format #f "assert: exception on ~S"
+                ',expression)))))
 
 (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)))))
 
 
 ;;;----------------------------------------------------------------
-- 
2.11.0

Attachment: pgpKesoSKDuKC.pgp
Description: OpenPGP digital signature

Reply via email to