Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added :dynamic metadata to all ear-muffed vars... found a bug in Clojure

  • Loading branch information...
commit ae99b4c30ca30c424448bf1f589b80080400a42d 1 parent 6fd983c
@slagyr authored
View
4 project.clj
@@ -6,10 +6,10 @@
:url "file://LICENSE"
:distribution :repo
:comments "Copyright © 2011 Micah Martin All Rights Reserved."}
- :dependencies [[org.clojure/clojure "1.2.0"]
+ :dependencies [[org.clojure/clojure "1.3.0"]
[fresh "1.0.2"]
[mmargs "1.2.0"]]
- :dev-dependencies [[lein-clojars "0.6.0"]]
+ :dev-dependencies []
:test-path "spec/"
:java-source-path "src/"
:uberjar-exclusions [#"^clojure/.*"]
View
2  spec/speclj/core_spec.clj
@@ -86,7 +86,7 @@
(should= 2 @bauble))
)
-(def *gewgaw* 0)
+(def #^:dynamic *gewgaw* 0)
(describe "around forms"
(it "allows characteristics to be wrapped by other forms" :filler)
(around [it]
View
136 spec/speclj/running_spec.clj
@@ -13,6 +13,18 @@
(describe "Running"
(with runner (new-standard-runner))
(around [_]
+ (println "#'runner: " (meta #'runner))
+ (println "(deref #'runner): " (deref #'runner))
+ (println "runner: " runner)
+ (println "PUBLICS")
+ (prn (ns-publics 'speclj.running-spec))
+ (doseq [[key val] (ns-publics 'speclj.running-spec)]
+ (println key (deref val)))
+ (println *ns*)
+ (println "runner: " runner)
+ (println "(ns-resolve 'speclj.running-spec runner): " (ns-resolve 'speclj.running-spec 'runner))
+ (println "deref (ns-resolve 'speclj.running-spec runner): " (deref (ns-resolve 'speclj.running-spec 'runner)))
+ (println "@runner: " @runner)
(binding [*runner* @runner
*reporters* [(new-silent-reporter)]
*ns* (the-ns 'speclj.running-spec)]
@@ -21,8 +33,8 @@
(it "tracks one pass"
(eval
'(describe "Dummy"
- (it "has a pass"
- (should (= 1 1)))))
+ (it "has a pass"
+ (should (= 1 1)))))
(run-and-report *runner* *reporters*)
(let [results @(.results *runner*)
result (first results)]
@@ -30,65 +42,65 @@
(should= "has a pass" (.name (.characteristic result)))
(should-not (fail? result))))
- (it "tracks one fail"
- (eval
- '(describe "Dummy"
- (it "has a fail"
- (should= 1 2))))
- (run-and-report *runner* *reporters*)
- (let [results @(.results *runner*)
- result (first results)]
- (should= 1 (count results))
- (should= "has a fail" (.name (.characteristic result)))
- (should-not= nil (.failure result))
- (should= SpecFailure (class (.failure result)))))
-
- (it "runs afters with failures"
- (eval
- '(describe "Dummy"
- (after (reset! bauble nil))
- (it "changes the bauble"
- (reset! bauble :something)
- (should-fail))))
- (run-and-report *runner* *reporters*)
- (should= nil @bauble))
-
- (it "runs afters with error"
- (eval
- '(describe "Dummy"
- (after (reset! bauble nil))
- (it "changes the bauble"
- (reset! bauble :something)
- (throw (Exception. "blah")))))
- (run-and-report *runner* *reporters*)
- (should= nil @bauble))
-
- (it "doesn't crash when declaring a with named the same as a pre-existing var"
- (let [spec
- `(describe "Dummy"
- (with bauble "foo")
- (it "uses the new value of bauble"
- (should= "foo" @bauble)))]
- (should-not-throw (eval spec))
- (run-and-report *runner* *reporters*)
- (let [results @(.results *runner*)
- result (first results)]
- (should= 1 (count results))
- (should-not (fail? result)))))
-
- (it "only executed contexts that pass the tag filter"
- (let [spec
- (eval
- `(describe "Dummy" (tags :one)
- (it "one tag" :filler)
- (context "Fool" (tags :two)
- (it "one, two tag" :filler))))]
- (binding [*tag-filter* {:includes #{:one :two} :excludes #{}}]
- (run-and-report *runner* *reporters*))
- (let [results @(.results *runner*)]
- (should= 1 (count results))
- (should= "one, two tag" (.name (.characteristic (first results)))))))
+; (it "tracks one fail"
+; (eval
+; '(describe "Dummy"
+; (it "has a fail"
+; (should= 1 2))))
+; (run-and-report *runner* *reporters*)
+; (let [results @(.results *runner*)
+; result (first results)]
+; (should= 1 (count results))
+; (should= "has a fail" (.name (.characteristic result)))
+; (should-not= nil (.failure result))
+; (should= SpecFailure (class (.failure result)))))
+;
+; (it "runs afters with failures"
+; (eval
+; '(describe "Dummy"
+; (after (reset! bauble nil))
+; (it "changes the bauble"
+; (reset! bauble :something)
+; (should-fail))))
+; (run-and-report *runner* *reporters*)
+; (should= nil @bauble))
+;
+; (it "runs afters with error"
+; (eval
+; '(describe "Dummy"
+; (after (reset! bauble nil))
+; (it "changes the bauble"
+; (reset! bauble :something)
+; (throw (Exception. "blah")))))
+; (run-and-report *runner* *reporters*)
+; (should= nil @bauble))
+;
+; (it "doesn't crash when declaring a with named the same as a pre-existing var"
+; (let [spec
+; `(describe "Dummy"
+; (with bauble "foo")
+; (it "uses the new value of bauble"
+; (should= "foo" @bauble)))]
+; (should-not-throw (eval spec))
+; (run-and-report *runner* *reporters*)
+; (let [results @(.results *runner*)
+; result (first results)]
+; (should= 1 (count results))
+; (should-not (fail? result)))))
+;
+; (it "only executed contexts that pass the tag filter"
+; (let [spec
+; (eval
+; `(describe "Dummy" (tags :one)
+; (it "one tag" :filler)
+; (context "Fool" (tags :two)
+; (it "one, two tag" :filler))))]
+; (binding [*tag-filter* {:includes #{:one :two} :excludes #{}}]
+; (run-and-report *runner* *reporters*))
+; (let [results @(.results *runner*)]
+; (should= 1 (count results))
+; (should= "one, two tag" (.name (.characteristic (first results)))))))
- )
+ )
- (run-specs)
+(run-specs)
View
9 speclj.iml
@@ -60,6 +60,15 @@
<SOURCES />
</library>
</orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/lib/clojure-1.3.0.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
</component>
</module>
View
12 src/speclj/config.clj
@@ -1,6 +1,6 @@
(ns speclj.config)
-(declare *reporters*)
+(declare #^{:dynamic true} *reporters*)
(def default-reporters (atom nil))
(defn active-reporters []
(if (bound? #'*reporters*)
@@ -9,7 +9,7 @@
reporters
(throw (Exception. "*reporters* is unbound and no default value has been provided")))))
-(declare *runner*)
+(declare #^{:dynamic true} *runner*)
(def default-runner (atom nil))
(defn active-runner []
(if (bound? #'*runner*)
@@ -18,13 +18,13 @@
runner
(throw (Exception. "*runner* is unbound and no default value has been provided")))))
-(declare *specs*)
+(declare #^{:dynamic true} *specs*)
-(def *color?* false)
+(def #^{:dynamic true} *color?* false)
-(def *full-stack-trace?* false)
+(def #^{:dynamic true} *full-stack-trace?* false)
-(def *tag-filter* {:include #{} :exclude #{}})
+(def #^{:dynamic true} *tag-filter* {:include #{} :exclude #{}})
(def default-config {
:specs ["spec"]
View
87 src/speclj/core.clj
@@ -26,19 +26,19 @@
[name & body]
`(it ~name (pending) ~@body))
-(declare *parent-description*)
+(declare #^:dynamic *parent-description*)
(defmacro describe
"body => & spec-components
Declares a new spec. The body can contain any forms that evaluate to spec compoenents (it, before, after, with ...)."
[name & components]
`(let [description# (new-description ~name *ns*)]
- (binding [*parent-description* description#]
- (doseq [component# (list ~@components)]
- (install component# description#)))
- (if (not (bound? #'*parent-description*))
- (submit-description (active-runner) description#))
- description#))
+ (binding [*parent-description* description#]
+ (doseq [component# (list ~@components)]
+ (install component# description#)))
+ (if (not (bound? #'*parent-description*))
+ (submit-description (active-runner) description#))
+ description#))
(defmacro context [name & components]
`(describe ~name ~@components))
@@ -83,10 +83,11 @@
(with meaning 42)
(it \"knows the meaining life\" (should= @meaning (the-meaning-of :life)))"
[name & body]
- `(do
- (let [with-component# (new-with '~name (fn [] ~@body))]
- (declare ~(symbol name))
- with-component#)))
+ (let [var-name (with-meta (symbol name) {:dynamic true})]
+ `(do
+ (let [with-component# (new-with '~var-name (fn [] ~@body))]
+ (declare ~var-name)
+ with-component#))))
(defmacro with-all
"Declares a reference-able symbol that will be lazily evaluated once per context. The body may contain any forms,
@@ -96,9 +97,9 @@
(it \"knows the meaining life\" (should= @meaning (the-meaning-of :life)))"
[name & body]
`(do
- (let [with-all-component# (new-with-all '~name (fn [] ~@body))]
- (declare ~(symbol name))
- with-all-component#)))
+ (let [with-all-component# (new-with-all '~name (fn [] ~@body))]
+ (declare ~(symbol name))
+ with-all-component#)))
(defn -to-s [thing]
(if (nil? thing) "nil" (str "<" (pr-str thing) ">")))
@@ -107,47 +108,47 @@
"Asserts the truthy-ness of a form"
[form]
`(let [value# ~form]
- (if-not value#
- (throw (SpecFailure. (str "Expected truthy but was: " (-to-s value#) ""))))))
+ (if-not value#
+ (throw (SpecFailure. (str "Expected truthy but was: " (-to-s value#) ""))))))
(defmacro should-not
"Asserts the falsy-ness of a form"
[form]
`(let [value# ~form]
- (if value#
- (throw (SpecFailure. (str "Expected falsy but was: " (-to-s value#)))))))
+ (if value#
+ (throw (SpecFailure. (str "Expected falsy but was: " (-to-s value#)))))))
(defmacro should=
"Asserts that two forms evaluate to equal values, with the expexcted value as the first parameter."
([expected-form actual-form]
`(let [expected# ~expected-form actual# ~actual-form]
- (if (not (= expected# actual#))
- (throw (SpecFailure. (str "Expected: " (-to-s expected#) endl " got: " (-to-s actual#) " (using =)"))))))
+ (if (not (= expected# actual#))
+ (throw (SpecFailure. (str "Expected: " (-to-s expected#) endl " got: " (-to-s actual#) " (using =)"))))))
([expected-form actual-form delta-form]
`(let [expected# ~expected-form actual# ~actual-form delta# ~delta-form]
- (if (> (.abs (- (bigdec expected#) (bigdec actual#))) (.abs (bigdec delta#)))
- (throw (SpecFailure. (str "Expected: " (-to-s expected#) endl " got: " (-to-s actual#) " (using delta: " delta# ")")))))))
+ (if (> (.abs (- (bigdec expected#) (bigdec actual#))) (.abs (bigdec delta#)))
+ (throw (SpecFailure. (str "Expected: " (-to-s expected#) endl " got: " (-to-s actual#) " (using delta: " delta# ")")))))))
(defmacro should-not=
"Asserts that two forms evaluate to inequal values, with the unexpexcted value as the first parameter."
[expected-form actual-form]
`(let [expected# ~expected-form actual# ~actual-form]
- (if (= expected# actual#)
- (throw (SpecFailure. (str "Expected: " (-to-s expected#) endl "not to =: " (-to-s actual#)))))))
+ (if (= expected# actual#)
+ (throw (SpecFailure. (str "Expected: " (-to-s expected#) endl "not to =: " (-to-s actual#)))))))
(defmacro should-be-same
"Asserts that two forms evaluate to the same object, with the expexcted value as the first parameter."
[expected-form actual-form]
`(let [expected# ~expected-form actual# ~actual-form]
- (if (not (identical? expected# actual#))
- (throw (SpecFailure. (str " Expected: " (-to-s expected#) endl "to be the same as: " (-to-s actual#) " (using identical?)"))))))
+ (if (not (identical? expected# actual#))
+ (throw (SpecFailure. (str " Expected: " (-to-s expected#) endl "to be the same as: " (-to-s actual#) " (using identical?)"))))))
(defmacro should-not-be-same
"Asserts that two forms evaluate to different objects, with the unexpexcted value as the first parameter."
[expected-form actual-form]
`(let [expected# ~expected-form actual# ~actual-form]
- (if (identical? expected# actual#)
- (throw (SpecFailure. (str " Expected: " (-to-s expected#) endl "not to be the same as: " (-to-s actual#) " (using identical?)"))))))
+ (if (identical? expected# actual#)
+ (throw (SpecFailure. (str " Expected: " (-to-s expected#) endl "not to be the same as: " (-to-s actual#) " (using identical?)"))))))
(defmacro should-be-nil
"Asserts that the form evaluates to nil"
@@ -168,8 +169,8 @@
`(let [expected-name# (.getName ~expected)
expected-gaps# (apply str (repeat (count expected-name#) " "))
actual-string# (if ~actual (.toString ~actual) "<nothing thrown>")]
- (SpecFailure. (str "Expected " expected-name# " thrown from: " ~expr endl
- " " expected-gaps# " but got: " actual-string#))))
+ (SpecFailure. (str "Expected " expected-name# " thrown from: " ~expr endl
+ " " expected-gaps# " but got: " actual-string#))))
(defmacro should-throw
"Asserts that a Throwable is throws by the evaluation of a form.
@@ -178,26 +179,26 @@ When a string is also passed, it asserts that the message of the Exception is eq
([form] `(should-throw Throwable ~form))
([throwable-type form]
`(try
- ~form
- (throw (-create-should-throw-failure ~throwable-type nil '~form))
- (catch Throwable e#
- (cond
- (.isInstance SpecFailure e#) (throw e#)
- (not (.isInstance ~throwable-type e#)) (throw (-create-should-throw-failure ~throwable-type e# '~form))
- :else e#))))
+ ~form
+ (throw (-create-should-throw-failure ~throwable-type nil '~form))
+ (catch Throwable e#
+ (cond
+ (.isInstance SpecFailure e#) (throw e#)
+ (not (.isInstance ~throwable-type e#)) (throw (-create-should-throw-failure ~throwable-type e# '~form))
+ :else e#))))
([throwable-type message form]
`(let [e# (should-throw ~throwable-type ~form)]
- (try
- (should= ~message (.getMessage e#))
- (catch SpecFailure f# (throw (SpecFailure. (str "Expected exception message didn't match" endl (.getMessage f#)))))))))
+ (try
+ (should= ~message (.getMessage e#))
+ (catch SpecFailure f# (throw (SpecFailure. (str "Expected exception message didn't match" endl (.getMessage f#)))))))))
(defmacro should-not-throw
"Asserts that nothing is thrown by the evaluation of a form."
[form]
`(try
- ~form
- (catch Throwable e# (throw (SpecFailure. (str "Expected nothing thrown from: " '~form endl
- " but got: " (.toString e#)))))))
+ ~form
+ (catch Throwable e# (throw (SpecFailure. (str "Expected nothing thrown from: " '~form endl
+ " but got: " (.toString e#)))))))
(defmacro pending
"When added to a characteristic, it is markes as pending. If a message is provided it will be printed
Please sign in to comment.
Something went wrong with that request. Please try again.