I have been using the test-is library from clojure.contrib very
effectively - thanks Stuart and contributors!
One thing I have noticed is that errors like StackOverflowError cause
"run-tests" to terminate prematurely.
I know java.lang.Errors should not be caught in general but I think
it's acceptable for a unit testing framework.
Here is a patch to add support for errors:
Index: test_is.clj
===================================================================
--- test_is.clj (revision 227)
+++ test_is.clj (working copy)
@@ -68,6 +68,7 @@
(defcounter *assertions* count-assertion)
(defcounter *failures* count-failure)
(defcounter *exceptions* count-exception)
+(defcounter *errors* count-error)
(defmacro failure [reason message]
`(throw (new java.lang.AssertionError
@@ -125,12 +126,14 @@
`(binding [*tests* (ref 0)
*assertions* (ref 0)
*failures* (ref 0)
- *exceptions* (ref 0)]
+ *exceptions* (ref 0)
+ *errors* (ref 0)]
[EMAIL PROTECTED]
{:tests @*tests*
:assertions @*assertions*
:failures @*failures*
- :exceptions @*exceptions*}))
+ :exceptions @*exceptions*
+ :errors @*errors*}))
(defn- run-test-fn
"Calls the function; reports errors/exceptions."
@@ -145,8 +148,14 @@
(catch java.lang.Exception e
(count-exception)
(. *test-out* (println (str "EXCEPTION in " name ":")))
- (.printStackTrace e *test-out*))))
+ (.printStackTrace e *test-out*))
+ (catch java.lang.Error e
+ (count-error)
+ (. *test-out* (print (str "ERROR in " name ": ")))
+ (. *test-out* (println e)))))
+
+
(defn- test-var
"Finds and calls the fn in a var's :test metadata."
[v]
@@ -202,7 +211,8 @@
(println (str "\nRan " (:tests r) " tests with "
(:assertions r) " assertions.\n"
(:failures r) " failures, "
- (:exceptions r) " exceptions."))) )
+ (:exceptions r) " exceptions, "
+ (:errors r) " errors."))))
(defn test-ns
"Runs tests on all interned symbols in the namespaces
@@ -213,6 +223,7 @@
:assertions => number of assertions checked
:failures => number of failed assertions
:exceptions => number of exceptions raised
+ :errors => number of errors raised
If no namespace is given, uses *ns*."
([] (test-ns *ns*))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---