 	[lazytest.result :only (pass fail thrown result-group)])
   (:import (lazytest ExpectationFailed)))
 
-(comment
-  (defn- debug [& args]
-    (spit "log" 
-	  (str (pr-str args) "\n")
-	  :append true)))
-
-(defmacro debug [& args] nil)
-
 (defn- apply-test-case [tc arguments]
-  (debug "apply-test-case" tc arguments)
   (let [this (vary-meta tc assoc :states arguments)]
     (try (apply (:f tc) arguments)
 	 (pass this)

	 (catch Throwable e (thrown this e)))))

(defn- run-test-case [tc]
  (debug "run-test-case" tc)
  (try (let [states (map setup (:fixtures tc))
	     result (apply-test-case tc states)]
	 (dorun (map teardown (:fixtures tc)))

       (catch Throwable e (thrown tc e))))

(defn- run-test-sequence [tc]
  (try 
    (let [state-sequences (map (fn [fix]
				 (if (:sequential (meta fix))
				   (setup fix)
				   (repeatedly (fn [] (setup fix)))))
			       (:fixtures tc))
	  argument-lists (apply map list state-sequences)]
      (map (partial apply-test-case tc) argument-lists))
    (catch Throwable e (list (thrown tc e)))))

