Permalink
Browse files

Extended compiling-out support to sweet mode.

  • Loading branch information...
1 parent 8a9e070 commit 7627fb975fb50d76cc849c53b2cd98a622c9b75b @marick committed Oct 28, 2010
View
@@ -9,6 +9,7 @@
is good for that.
* Added a leiningen plugin to get tidy test reports.
* Chatty checkers
+* Set midje.semi-sweet/*include-midje-checks* to false to compile tests out of production code.
= 0.6.1 (stable)
* Midje-mode is (more) compatible with clojure-test-mode.
View
@@ -7,11 +7,9 @@
(def => "=>") ; So every namespace uses the same qualified name.
(defonce
- #^{:doc "True by default. If set to false, no expect compiles
- into nothing. Do that to omit tests from production code."}
- *check* true)
-
-
+ #^{:doc "True by default. If set to false, Midje checks are not
+ included into production code, whether compiled or loaded."}
+ *include-midje-checks* true)
(defmacro only-mocked
"Defines a list of names as functions that have no implementation yet. They will
@@ -49,6 +47,13 @@
)
+(defn user-desires-checking? []
+ (cond (if-let [ns (find-ns 'clojure.test)] ;; clojure.test might not always be loaded.
+ (not (var-get ((ns-map ns) '*load-tests*))))
+ false
+
+ :else
+ *include-midje-checks*))
(defmacro expect
"Run the call form, check that all the mocks defined in the expectations
@@ -61,14 +61,3 @@
:file-position (user-file-position)}
(midje-override-map ~overrides)))
-(defn user-desires-checking? []
- (cond (if-let [ns (find-ns 'clojure.test)] ;; clojure.test might not always be loaded.
- (not (var-get ((ns-map ns) '*load-tests*))))
- false
-
- :else
- ;; I don't want to screw around writing the code to immigrate a
- ;; single var from this namespace into midje.semi-sweet.
- (var-get ((ns-map (find-ns 'midje.semi-sweet)) '*check*))))
-
-
View
@@ -14,11 +14,10 @@
(deferror odd-test-forms [] [forms])
(defmacro fact [& forms]
- (let [runs (folded/rewrite (transform/rewrite (position/add-line-numbers forms)))]
- ; (pprint runs)
- (define-metaconstants runs)
- `(every? true? (list ~@runs)))
- )
+ (when (user-desires-checking?)
+ (let [runs (folded/rewrite (transform/rewrite (position/add-line-numbers forms)))]
+ (define-metaconstants runs)
+ `(every? true? (list ~@runs)))))
(defmacro facts [& forms]
`(fact ~@forms))
@@ -1,5 +1,5 @@
;; This file is used to check whether checks can be compiled out.
-(expect false => true)
+(expect (throw (Exception. "Should never be called")) => true)
(deftest tests-can-be-compiled-out
(expect false => true))
@@ -0,0 +1,5 @@
+
+;; This file is used to check whether facts can be compiled out.
+
+(fact
+ (throw (Exception. "This is supposed to compile out")))
@@ -271,8 +271,8 @@
(fake (testfun 1) => 32)))
(binding [clojure.test/*load-tests* false]
- (load "semi_sweet/binding_source"))
+ (load "semi_sweet_compile_out"))
-(binding [midje.semi-sweet/*check* false]
- (load "semi_sweet/binding_source"))
+(binding [midje.semi-sweet/*include-midje-checks* false]
+ (load "semi_sweet_compile_out"))
@@ -3,7 +3,6 @@
(:use [midje.sweet] :reload-all)
(:use [midje.test-util]))
-
(deftest simple-assertion-examples
(after
(fact (+ 1 1) => 3)
@@ -101,3 +100,8 @@
(deftest issue-2-test ; http://github.com/marick/Midje/issues/#issue/2
(fact
(expect (always-one 5) => 1 (not-called some-fn))))
+
+(binding [midje.semi-sweet/*include-midje-checks* false]
+ (load "sweet_compile_out"))
+
+

0 comments on commit 7627fb9

Please sign in to comment.