Renamed the default suite to T; allow a suite parameter of NIL to mean a test/suite...
[fiveam.git] / t / tests.lisp
index 65918d1..27b4229 100644 (file)
@@ -4,13 +4,14 @@
 
 (in-suite :it.bese.fiveam)
 
-(def-suite test-suite :description "Suite for tests which should fail.")
+(def-suite test-suite
+    :description "Suite for tests which should fail."
+    :in nil)
 
 (defmacro with-test-results ((results test-name) &body body)
   `(let ((,results (with-*test-dribble* nil (run ',test-name))))
      ,@body))
 
-(rem-fixture 'null-fixture)
 (def-fixture null-fixture ()
   `(progn ,@(&body)))
 
     (is (= 1 (length (remove-if-not #'test-failure-p results))))))
 
 (def-test circular-0 (:depends-on (and circular-1 circular-2 or1) 
-                  :suite test-suite)
+                      :suite test-suite)
   (fail "we depend on a circular dependency, we should not be tested."))
 
 (def-test circular-1 (:depends-on (and circular-2)
-                  :suite test-suite)
+                      :suite test-suite)
   (fail "we have a circular depednency, we should not be tested."))
 
 (def-test circular-2 (:depends-on (and circular-1)
-                  :suite test-suite)
+                      :suite test-suite)
   (fail "we have a circular depednency, we should not be tested."))
 
 (def-test circular ()
     (run 'circular-2)))
 
 
-(def-suite before-test-suite :description "Suite for before test")
+(def-suite before-test-suite :description "Suite for before test" :in nil)
 
 (def-test before-0 (:suite before-test-suite)
   (pass))
 
 (def-test before-1 (:depends-on (:before before-0)
-                :suite before-test-suite)
+                    :suite before-test-suite)
   (fail))
 
-(def-suite before-test-suite-2 :description "Suite for before test")
+(def-suite before-test-suite-2 :description "Suite for before test" :in nil)
 
 (def-test before-2 (:depends-on (:before before-3)
-                :suite before-test-suite-2)
+                    :suite before-test-suite-2)
   (pass))
 
 (def-test before-3 (:suite before-test-suite-2)
     (test-gen-float single-float)
     (test-gen-float short-float)
     (test-gen-float double-float)
-    (test-gen-float long-float)))
+    (test-gen-float long-float)
+
+    (for-all ((value (gen-float :type 'single-float :min 1 :max 2)))
+      (is (typep value 'single-float))
+      (is (<= (coerce 1 'single-float) value (coerce 2 'single-float))))))
 
 (def-test gen-character ()
   (for-all ((c (gen-character)))
   (for-all (((a b) (dummy-mv-generator)))
     (is (= 1 a))
     (is (= 1 b))))
+
+(def-test introspection ()
+  (is (= (length (list-all-suites))
+         (hash-table-count *suites*))))
+
+(defvar *special-variable* nil)
+
+(def-fixture fixture-for-suite (value)
+  (progn
+    (setf *special-variable* value)
+    (&body)))
+
+(def-suite suite-with-fixture :fixture (fixture-for-suite 42) :in :it.bese.fiveam)
+
+(def-test test-with-suite-fixture (:suite suite-with-fixture)
+  (is (= 42 *special-variable*)))
+
+(def-test add-remove-test-from-suite ()
+  (let ((*test* (make-hash-table :test 'eql))
+        (*suites* (make-hash-table :test 'eql)))
+    (in-suite* empty :in nil)
+    (is (null (get-test 'foo)))
+
+    (def-test foo (:suite nil) t)
+    (is-true (get-test 'foo))
+    (is-false (gethash 'foo (tests *suite*)))
+
+    (def-test foo () t)
+    (is-true (gethash 'foo (tests *suite*)))
+
+    (def-test foo (:suite nil) t)
+    (is-false (gethash 'foo (tests *suite*)))))