Permalink
Browse files

exception changed to macros to get correct line number in stack trace

  • Loading branch information...
1 parent 5ff2de7 commit 49e256725c436572b3e6bb64e08300850145364d @slagyr committed Feb 27, 2014
View
@@ -35,7 +35,7 @@
:profiles {:dev {:dependencies [[com.keminglabs/cljx "0.3.2"]
[org.clojure/clojurescript "0.0-2014"]]
- ;[org.clojure/clojurescript "0.0-2173"]]
+ ;[org.clojure/clojurescript "0.0-2173"]]
:plugins [[com.keminglabs/cljx "0.3.2"]
[lein-cljsbuild "1.0.1"]]}}
@@ -1,11 +1,11 @@
(ns speclj.report.clojure-test-spec
(:require ;cljs-macros
- [speclj.core :refer [around before context describe it should should= should-contain with]])
+ [speclj.core :refer [around before context describe it should should= should-contain with -new-exception -new-failure]])
(:require [clojure.string :as str]
;cljs-include [goog.string] ;cljs bug?
[speclj.components :refer [new-description new-characteristic install]]
[speclj.config :refer [*color?* *full-stack-trace?*]]
- [speclj.platform :refer [new-exception new-failure format-seconds]]
+ [speclj.platform :refer [format-seconds]]
[speclj.report.clojure-test :refer [new-clojure-test-reporter]]
[speclj.reporting :refer [report-description report-pass report-pending
report-fail report-error red green yellow grey report-runs]]
@@ -21,8 +21,8 @@
(describe "Clojure Test Reporter"
(with reporter (new-clojure-test-reporter))
- (with a-failure (fail-result (new-characteristic "flips" (new-description "Crazy" "some.ns") "flip") 0.3 (new-failure "Expected flips")))
- (with an-error (error-result (new-exception "Compilation failed")))
+ (with a-failure (fail-result (new-characteristic "flips" (new-description "Crazy" "some.ns") "flip") 0.3 (-new-failure "Expected flips")))
+ (with an-error (error-result (-new-exception "Compilation failed")))
(it "reports pass"
(with-test-out-str (report-pass @reporter nil))
@@ -61,7 +61,7 @@
(after (reset! bauble nil))
(it "changes the bauble"
(reset! bauble :something)
- (throw (platform/new-exception "blah")))))
+ (throw (Exception. "blah")))))
(run-and-report *runner* *reporters*)
(should= nil @bauble))
@@ -1,16 +1,15 @@
(ns speclj.spec-helper
(:require [speclj.core :refer [-fail]]))
-;cljs? is a duplicate of the cljs? function found in core
+;cljs? is a duplicate of the cljs? found in core
;this decision was made so that the Core namespace API and dependencies are simple as possible
-(defn cljs? []
- (boolean (find-ns 'cljs.analyzer)))
+(def cljs? (boolean (find-ns 'cljs.analyzer)))
(defmacro run-result [& body]
`(try
~@body
:pass
- ~(if (cljs?)
+ ~(if cljs?
'(catch js/Object e# e#)
'(catch java.lang.Throwable e# e#))))
@@ -1,12 +1,11 @@
(ns speclj.report.documentation-spec
- (#+clj :require #+cljs :require-macros ;cljs-macros
- [speclj.core :refer [around before context describe it should= with]])
+ (#+clj :require #+cljs :require-macros
+ [speclj.core :refer [around before context describe it should= with -new-exception -new-failure -new-pending]])
(:require [clojure.string :refer [split-lines]]
- ;cljs-include
#+cljs [goog.string] ;cljs bug?
[speclj.components :refer [new-description new-characteristic install]]
[speclj.config :refer [*color?*]]
- [speclj.platform :refer [new-exception new-failure new-pending endl]]
+ [speclj.platform :refer [endl]]
[speclj.report.documentation :refer [new-documentation-reporter]]
[speclj.reporting :refer [report-description report-pass report-pending
report-fail report-error red green yellow]]
@@ -23,8 +22,8 @@
(with-out-str (report-description @reporter @description))))
(it "reports errors"
- (should= (str (red (str (new-exception "Compilation failed"))) "\n")
- (with-out-str (report-error @reporter (error-result (new-exception "Compilation failed"))))))
+ (should= (str (red (str (-new-exception "Compilation failed"))) "\n")
+ (with-out-str (report-error @reporter (error-result (-new-exception "Compilation failed"))))))
(it "reports pass"
(let [characteristic (new-characteristic "says pass" @description "pass")
@@ -34,13 +33,13 @@
(it "reports pending"
(let [characteristic (new-characteristic "pending!" `(pending))
- result (pending-result characteristic 1 (new-pending "some reason for pendiness"))]
+ result (pending-result characteristic 1 (-new-pending "some reason for pendiness"))]
(should= (str (yellow "- pending! (PENDING: some reason for pendiness)") endl)
(with-out-str (report-pending @reporter result)))))
(it "reports fail"
(let [characteristic (new-characteristic "says fail" @description "fail")
- result (fail-result characteristic 2 (new-failure "blah"))]
+ result (fail-result characteristic 2 (-new-failure "blah"))]
(should= (str (red "- says fail (FAILED)") endl)
(with-out-str (report-fail @reporter result)))))
@@ -60,7 +59,7 @@
(it "reports nested failure"
(let [characteristic (new-characteristic "nested fail" @nested-description "fail")
- result (fail-result characteristic 2 (new-failure "blah"))]
+ result (fail-result characteristic 2 (-new-failure "blah"))]
(should= (str (red " - nested fail (FAILED)") endl)
(with-out-str (report-fail @reporter result)))))
)
@@ -1,12 +1,12 @@
(ns speclj.report.progress-spec
(#+clj :require #+cljs :require-macros ;cljs-macros
- [speclj.core :refer [around before context describe it should should= with]])
+ [speclj.core :refer [around before context describe it should should= with -new-exception -new-failure -new-pending]])
(:require [clojure.string :as str]
;cljs-include [goog.string] ;cljs bug?
#+cljs [goog.string]
[speclj.components :refer [new-description new-characteristic install]]
[speclj.config :refer [*color?* *full-stack-trace?*]]
- [speclj.platform :refer [new-exception new-failure new-pending format-seconds]]
+ [speclj.platform :refer [format-seconds]]
[speclj.report.progress :refer [new-progress-reporter full-name print-summary print-pendings print-errors]]
[speclj.reporting :refer [report-description report-pass report-pending
report-fail report-error red green yellow grey report-runs]]
@@ -50,7 +50,7 @@
(it "reports errors"
(should= "E"
- (with-out-str (report-error @reporter (new-exception "Compilation failed")))))
+ (with-out-str (report-error @reporter (-new-exception "Compilation failed")))))
(it "reports passing run results"
(binding [*color?* true]
@@ -72,9 +72,9 @@
char1 (new-characteristic "flips" description "flip")
char2 (new-characteristic "spins" description "spin")
char3 (new-characteristic "dives" description "dive")
- result1 (fail-result char1 0.3 (new-failure "Expected flips"))
- result2 (fail-result char2 0.02 (new-failure "Expected spins"))
- result3 (fail-result char3 0.001 (new-failure "Expected dives"))
+ result1 (fail-result char1 0.3 (-new-failure "Expected flips"))
+ result2 (fail-result char2 0.02 (-new-failure "Expected spins"))
+ result3 (fail-result char3 0.001 (-new-failure "Expected dives"))
results [result1 result2 result3]
lines (str/split-lines (with-out-str (report-runs @reporter results)))]
(should= 18 (count lines))
@@ -102,15 +102,15 @@
char1 (new-characteristic "flips" description "flip")
result1 (pass-result char1 0.1)
result2 (pass-result char1 0.02)
- result3 (pending-result char1 0.003 (new-pending "Blah"))
+ result3 (pending-result char1 0.003 (-new-pending "Blah"))
results [result1 result2 result3]
lines (str/split-lines (with-out-str (print-summary results)))]
(should= (yellow "3 examples, 0 failures, 1 pending") (last lines)))))
(it "reports pending summary"
(let [description (new-description "Crazy" "some.ns")
char1 (new-characteristic "flips" description "flip")
- result1 (pending-result char1 0.3 (new-pending "Not Yet Implemented"))
+ result1 (pending-result char1 0.3 (-new-pending "Not Yet Implemented"))
lines (str/split-lines (with-out-str (print-pendings [result1])))]
(should= 6 (count lines))
(should= "" (nth lines 0))
@@ -127,7 +127,7 @@
char1 (new-characteristic "flips" description "flip")
result1 (pass-result char1 0.1)
result2 (pass-result char1 0.02)
- result3 (error-result (new-exception "blah"))
+ result3 (error-result (-new-exception "blah"))
results [result1 result2 result3]
lines (str/split-lines (with-out-str (print-summary results)))]
(should= (red "3 examples, 0 failures, 1 errors") (last lines)))))
@@ -136,13 +136,13 @@
(binding [*full-stack-trace?* false]
(let [description (new-description "Crazy" "some.ns")
char1 (new-characteristic "flips" description "flip")
- result1 (error-result (new-exception "blah"))
+ result1 (error-result (-new-exception "blah"))
lines (str/split-lines (with-out-str (print-errors [result1])))]
(should (> (count lines) 3))
(should= "" (nth lines 0))
(should= "Errors:" (nth lines 1))
(should= "" (nth lines 2))
- (should= (str " 1) " (new-exception "blah")) (nth lines 3)))))
+ (should= (str " 1) " (-new-exception "blah")) (nth lines 3)))))
(it "can calculate the full name of a characteristic"
(let [outer (new-description "Outer" "some.ns")
@@ -4,10 +4,10 @@
should-be-same should-contain should-fail should-not should-not-be-a
should-not-be-nil should-not-be-same should-not-contain
should-not-throw should-not= should-not== should-throw
- should= should== -to-s]]
+ should= should== -to-s -new-throwable -new-exception]]
[speclj.spec-helper :refer [should-fail! should-pass! failure-message]]
)
- (:require [speclj.platform :refer [new-throwable new-exception endl exception type-name throwable]]
+ (:require [speclj.platform :refer [endl exception type-name throwable]]
[speclj.run.standard :refer [run-specs]]))
(describe "Should Assertions: "
@@ -340,36 +340,36 @@
(failure-message (should-throw (+ 1 1)))))
(it "should-throw can test an expected throwable type"
- (should-pass! (should-throw exception (throw (new-exception))))
+ (should-pass! (should-throw exception (throw (-new-exception))))
#+clj
(should-pass! (should-throw java.lang.Object (throw (java.lang.Exception.))))
- (should-fail! (should-throw exception (throw (new-throwable))))
+ (should-fail! (should-throw exception (throw (-new-throwable))))
(should-fail! (should-throw exception (+ 1 1)))
(should= (str "Expected " (type-name exception) " thrown from: (+ 1 1)" endl
(apply str (take (count (type-name exception)) (repeat " "))) " but got: <nothing thrown>")
(failure-message (should-throw exception (+ 1 1))))
- (should= (str "Expected " (type-name exception) " thrown from: (throw (new-throwable \"some message\"))" endl
- (apply str (take (count (type-name exception)) (repeat " "))) " but got: " (pr-str (new-throwable "some message")))
- (failure-message (should-throw exception (throw (new-throwable "some message")))))
+ (should= (str "Expected " (type-name exception) " thrown from: (throw (-new-throwable \"some message\"))" endl
+ (apply str (take (count (type-name exception)) (repeat " "))) " but got: " (pr-str (-new-throwable "some message")))
+ (failure-message (should-throw exception (throw (-new-throwable "some message")))))
)
(it "should-throw can test the message of the exception"
- (should-pass! (should-throw exception "My message" (throw (new-exception "My message"))))
- (should-fail! (should-throw exception "My message" (throw (new-exception "Not my message"))))
+ (should-pass! (should-throw exception "My message" (throw (-new-exception "My message"))))
+ (should-fail! (should-throw exception "My message" (throw (-new-exception "Not my message"))))
(should-fail! (should-throw exception "My message" (throw (throwable "My message"))))
(should-fail! (should-throw exception "My message" (+ 1 1)))
(should= (str "Expected exception message didn't match" endl "Expected: \"My message\"" endl " got: \"Not my message\" (using =)")
- (failure-message (should-throw exception "My message" (throw (new-exception "Not my message"))))))
+ (failure-message (should-throw exception "My message" (throw (-new-exception "Not my message"))))))
(it "should-not-throw tests that nothing was thrown"
(should-pass! (should-not-throw (+ 1 1)))
- (should-fail! (should-not-throw (throw (new-throwable "error"))))
- (should= (str "Expected nothing thrown from: " (pr-str '(throw (new-throwable "error"))) endl
- " but got: " (pr-str (new-throwable "error")))
- (failure-message (should-not-throw (throw (new-throwable "error"))))))
+ (should-fail! (should-not-throw (throw (-new-throwable "error"))))
+ (should= (str "Expected nothing thrown from: " (pr-str '(throw (-new-throwable "error"))) endl
+ " but got: " (pr-str (-new-throwable "error")))
+ (failure-message (should-not-throw (throw (-new-throwable "error"))))))
(context "should-be-a"
@@ -1,10 +1,10 @@
(ns speclj.stub-spec
- (#+clj :require #+cljs :require-macros ;cljs-macros
- [speclj.core :refer [around before context describe it should= should-throw should-invoke should-have-invoked should-not-invoke should-not-have-invoked with with-stubs stub]]
+ (#+clj :require #+cljs :require-macros
+ [speclj.core :refer [around before context describe it should= should-throw should-invoke should-have-invoked should-not-invoke should-not-have-invoked with with-stubs stub -new-exception]]
[speclj.spec-helper :refer [should-fail! should-pass! failure-message]]
)
(:require [speclj.stub :refer [*stubbed-invocations* invocations-of first-invocation-of last-invocation-of]]
- [speclj.platform :refer [endl exception new-exception]]
+ [speclj.platform :refer [endl exception]]
[speclj.run.standard :refer [run-specs]]))
(describe "Stubs"
@@ -30,8 +30,8 @@
(should= 42 ((stub :foo {:return 42}))))
(it "can throw stuff"
- (should-throw exception "Yay!" ((stub :bar {:throw (new-exception "Yay!")})))
- (should-throw exception "Oh no!" ((stub :bar {:throw (new-exception "Oh no!")}))))
+ (should-throw exception "Yay!" ((stub :bar {:throw (-new-exception "Yay!")})))
+ (should-throw exception "Oh no!" ((stub :bar {:throw (-new-exception "Oh no!")}))))
(it "can invoke"
(let [trail (atom [])
@@ -47,12 +47,10 @@
(should= 9 ((stub :foo {:invoke *}) 3 3))
(should= 42 ((stub :foo {:invoke * :return 42}) 3 3)))
- ;cljs-ignore->
#+clj
(it "invoke with wrong number of params"
(should-throw exception "Stub :foo was invoked with 0 arguments, but the :invoke fn has a different arity"
((stub :foo {:invoke (fn [a] a)}))))
- ;<-cljs-ignore
(it "throw error when :invoke argument is not a fn"
(should-throw exception "stub's :invoke argument must be an ifn" ((stub :foo {:invoke 42}))))
Oops, something went wrong.

0 comments on commit 49e2567

Please sign in to comment.