Permalink
Browse files

handling compile errors so they print at the end like failures

  • Loading branch information...
1 parent 11a7ad6 commit 442fb3ab2cea43beb0af3dc4e81db16e74b9bb21 @slagyr committed Apr 23, 2013
View
@@ -1,7 +1,8 @@
-# ?
+# 2.6.0
* Uses Clojure 1.5.0
* Added with! and with-all!. Courtesy of @spadin.
+* Compile errors are caught and reported. Courtesy of @glenjamin. https://github.com/slagyr/speclj/pull/39
# 2.5.0
View
@@ -7,7 +7,7 @@
:distribution :repo
:comments "Copyright 2011-2012 Micah Martin All Rights Reserved."}
- :dependencies [[org.clojure/clojure "1.5.0"]
+ :dependencies [[org.clojure/clojure "1.5.1"]
[fresh "1.0.2"]
[mmargs "1.2.0"]]
:eval-in-leiningen true
@@ -1,16 +1,14 @@
(ns speclj.report.documentation-spec
- (:use
- [speclj.core]
- [speclj.report.documentation :only (new-documentation-reporter)]
- [speclj.reporting]
- [speclj.results :only (pass-result fail-result pending-result)]
- [speclj.components :only (new-description new-characteristic install)]
- [clojure.string :only (split-lines)]
- [speclj.util :only (endl)]
- [speclj.config :only (*color?*)])
- (:import
- [speclj SpecFailure SpecPending]
- [java.io ByteArrayOutputStream OutputStreamWriter]))
+ (:use [speclj.core]
+ [speclj.report.documentation :only (new-documentation-reporter)]
+ [speclj.reporting]
+ [speclj.results :only (pass-result fail-result pending-result error-result)]
+ [speclj.components :only (new-description new-characteristic install)]
+ [clojure.string :only (split-lines)]
+ [speclj.util :only (endl)]
+ [speclj.config :only (*color?*)])
+ (:import [speclj SpecFailure SpecPending]
+ [java.io ByteArrayOutputStream OutputStreamWriter]))
(defn to-s [output]
(String. (.toByteArray output)))
@@ -27,9 +25,9 @@
(report-description @reporter @description)
(should= (str endl "Verbosity" endl) (to-s @output)))
- (it "doesnt report errors"
- (report-error @reporter (Exception. "Compilation failed"))
- (should= "" (to-s @output)))
+ (it "reports errors"
+ (report-error @reporter (error-result (Exception. "Compilation failed")))
+ (should= (str (red "java.lang.Exception: Compilation failed") "\n") (to-s @output)))
(it "reports pass"
(let [characteristic (new-characteristic "says pass" @description "pass")
@@ -1,15 +1,13 @@
(ns speclj.report.progress-spec
- (:use
- [speclj.core]
- [speclj.report.progress :only (new-progress-reporter full-name print-summary print-pendings)]
- [speclj.reporting]
- [speclj.results :only (pass-result fail-result pending-result)]
- [speclj.components :only (new-description new-characteristic install)]
- [speclj.config :only (*color?*)]
- [clojure.string :only (split-lines)])
- (:import
- [speclj SpecFailure SpecPending]
- [java.io ByteArrayOutputStream OutputStreamWriter]))
+ (:use [speclj.core]
+ [speclj.report.progress :only (new-progress-reporter full-name print-summary print-pendings print-errors)]
+ [speclj.reporting]
+ [speclj.results :only (pass-result fail-result pending-result error-result)]
+ [speclj.components :only (new-description new-characteristic install)]
+ [speclj.config :only (*color?* *full-stack-trace?*)]
+ [clojure.string :only (split-lines)])
+ (:import [speclj SpecFailure SpecPending]
+ [java.io ByteArrayOutputStream OutputStreamWriter]))
(defn to-s [output]
(String. (.toByteArray output)))
@@ -52,9 +50,9 @@
(report-description @reporter nil)
(should= "" (to-s @output)))
- (it "doesnt report errors"
+ (it "reports errors"
(report-error @reporter (Exception. "Compilation failed"))
- (should= "" (to-s @output)))
+ (should= "E" (to-s @output)))
(it "reports passing run results"
(binding [*color?* true]
@@ -64,6 +62,7 @@
results [result1 result2 result3]
_ (report-runs @reporter results)
lines (split-lines (to-s @output))]
+ (println "lines: " lines)
(should= 4 (count lines))
(should= "" (lines 0))
(should= "" (lines 1))
@@ -125,9 +124,35 @@
(should= "" (nth lines 2))
(should= (yellow " Crazy flips") (nth lines 3))
(should= (grey " ; Not Yet Implemented") (nth lines 4))
-; (should= (grey " ; /Users/micahmartin/Projects/clojure/speclj/spec/speclj/report/progress_spec.clj:117") (nth lines 5))
+ ; (should= (grey " ; /Users/micahmartin/Projects/clojure/speclj/spec/speclj/report/progress_spec.clj:117") (nth lines 5))
))
+ (it "reports error run results"
+ (binding [*color?* true]
+ (let [description (new-description "Crazy" *ns*)
+ char1 (new-characteristic "flips" description "flip")
+ result1 (pass-result char1 0.1)
+ result2 (pass-result char1 0.02)
+ result3 (error-result (Exception. "blah"))
+ results [result1 result2 result3]
+ _ (print-summary results)
+ lines (split-lines (to-s @output))]
+ (should= (red "3 examples, 0 failures, 1 errors") (last lines)))))
+
+ (it "reports error summary"
+ (binding [*full-stack-trace?* false]
+ (let [description (new-description "Crazy" *ns*)
+ char1 (new-characteristic "flips" description "flip")
+ result1 (error-result (Exception. "blah"))
+ _ (print-errors [result1])
+ lines (split-lines (to-s @output))]
+ (should (> (count lines) 3))
+ (should= "" (nth lines 0))
+ (should= "Errors:" (nth lines 1))
+ (should= "" (nth lines 2))
+ (should= " 1) java.lang.Exception: blah" (nth lines 3))
+ )))
+
(it "can calculate the full name of a characteristic"
(let [outer (new-description "Outer" *ns*)
inner (new-description "Inner" *ns*)
@@ -136,4 +161,4 @@
(should= "Outer Inner char" (full-name char))))
)
-(run-specs)
+(run-specs :stacktrace true)
@@ -23,21 +23,7 @@
(it "returns lots-o failures when running failure example"
(should= 8 (run-directories @runner [failures-dir] @reporters)))
- (it "resets the results before each run"
- (binding [*runner* @runner]
- (describe "Test Describe" (it "runs" (should= 1 1))))
- (run-and-report @runner @reporters)
- (binding [*runner* @runner]
- (describe "Test Describe" (it "runs" (should= 1 1))))
- (run-and-report @runner @reporters)
- (should= 1 (count @(.results @runner))))
- (it "resets the descriptions after each run"
- (binding [*runner* @runner]
- (describe "Test Describe" (it "runs" (should= 1 1))))
- (should= 1 (count @(.descriptions @runner)))
- (run-and-report @runner @reporters)
- (should= 0 (count @(.descriptions @runner))))
)
(run-specs)
View
@@ -5,15 +5,15 @@
<configuration />
</facet>
</component>
- <component name="NewModuleRootManager" inherit-compiler-output="false">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
- <orderEntry type="inheritedJdk" />
+ <orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
@@ -33,7 +33,16 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="library" name="Maven: org.clojure:clojure:1.4.0" level="project" />
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="file://$MODULE_DIR$/target/classes" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="library" name="Maven: org.clojure:clojure:1.5.1" level="project" />
<orderEntry type="library" name="Maven: fresh:fresh:1.0.2" level="project" />
<orderEntry type="library" name="Maven: mmargs:mmargs:1.2.0" level="project" />
</component>
View
@@ -11,6 +11,7 @@
(declare #^{:dynamic true} *runner*)
(def default-runner (atom nil))
+(def default-runner-fn (atom nil))
(defn active-runner []
(if (bound? #'*runner*)
*runner*
View
@@ -2,7 +2,7 @@
(:use [speclj.running :only (submit-description run-and-report)]
[speclj.reporting :only (report-message*)]
[speclj.tags :only (describe-filter)]
- [speclj.config :only (active-reporters active-runner default-runner config-mappings default-config)]
+ [speclj.config :only (active-reporters active-runner default-runner default-runner-fn config-mappings default-config)]
[speclj.components]
[speclj.util :only (endl)])
(:require [speclj.run.standard]
@@ -405,4 +405,7 @@ are evaluated by evaluation the file as a script. Optional configuration paramt
(with-bindings (config-mappings config)
(if-let [filter-msg (describe-filter)]
(report-message* (active-reporters) filter-msg))
- (run-and-report (active-runner) (active-reporters))))))
+ (run-and-report (active-runner) (active-reporters))
+ (reset! default-runner (@default-runner-fn))))))
+
+(reset! default-runner (@default-runner-fn))
@@ -35,9 +35,10 @@
(let [characteristic (.characteristic result)
level (level-of characteristic)]
(println (red (indent (dec level) "- " (.name characteristic) " (FAILED)"))) (flush)))
+ (report-error [this result]
+ (println (red (.toString (.exception result)))))
(report-runs [this results]
- (print-summary results))
- (report-error [this exception]))
+ (print-summary results)))
(defn new-documentation-reporter []
(DocumentationReporter.))
@@ -1,14 +1,11 @@
(ns speclj.report.progress
- (:use
- [speclj.reporting :only (failure-source tally-time red green yellow grey stack-trace indent prefix)]
- [speclj.results :only (pass? fail? pending? categorize)]
- [speclj.util :only (seconds-format)]
- [speclj.config :only (default-reporters)])
- (:require
- [clojure.string :as str])
- (:import
- [speclj.reporting Reporter]
- [speclj SpecFailure]))
+ (:use [speclj.reporting :only (failure-source tally-time red green yellow grey stack-trace indent prefix print-stack-trace)]
+ [speclj.results :only (pass? fail? pending? categorize)]
+ [speclj.util :only (seconds-format)]
+ [speclj.config :only (default-reporters)])
+ (:require [clojure.string :as str])
+ (:import [speclj.reporting Reporter]
+ [speclj SpecFailure]))
(defn full-name [characteristic]
(loop [context @(.parent characteristic) name (.name characteristic)]
@@ -43,24 +40,44 @@
(println (grey (str " ; " (.getMessage (.exception result)))))
(println (grey (str " ; " (failure-source (.exception result)))))))
+(defn print-errors [error-results]
+ (when (seq error-results)
+ (println)
+ (println "Errors:"))
+ (doseq [[number result] (partition 2 (interleave (iterate inc 1) error-results))]
+ (println)
+ (println (indent 1 number ") " (red (str (.exception result)))))
+ (println (grey (indent 2.5 (stack-trace (.exception result))))))
+ (.flush *out*))
+
(defn- print-duration [results]
(println)
(println "Finished in" (.format seconds-format (tally-time results)) "seconds"))
(defn color-fn-for [result-map]
- (cond (not= 0 (count (:fail result-map))) red
+ (cond
+ (not= 0 (count (concat (:fail result-map) (:error result-map)))) red
(not= 0 (count (:pending result-map))) yellow
:else green))
+(defn- apply-pending-tally [report tally]
+ (if (pos? (:pending tally))
+ (conj report (str (:pending tally) " pending"))
+ report))
+
+(defn- apply-error-tally [report tally]
+ (if (pos? (:error tally))
+ (conj report (str (:error tally) " errors"))
+ report))
+
(defn describe-counts-for [result-map]
(let [tally (zipmap (keys result-map) (map count (vals result-map)))
always-on-counts [(str (apply + (vals tally)) " examples")
(str (:fail tally) " failures")]]
-
(str/join ", "
- (if (pos? (:pending tally))
- (conj always-on-counts (str (:pending tally) " pending"))
- always-on-counts))))
+ (-> always-on-counts
+ (apply-pending-tally tally)
+ (apply-error-tally tally)))))
(defn- print-tally [result-map]
(let [color-fn (color-fn-for result-map)]
@@ -70,6 +87,7 @@
(let [result-map (categorize results)]
(print-failures (:fail result-map))
(print-pendings (:pending result-map))
+ (print-errors (:error result-map))
(print-duration results)
(print-tally result-map)))
@@ -84,10 +102,11 @@
(print (yellow "*")) (flush))
(report-fail [this result]
(print (red "F")) (flush))
+ (report-error [this result]
+ (print (red "E")) (flush))
(report-runs [this results]
(println)
- (print-summary results))
- (report-error [this exception]))
+ (print-summary results)))
(defn new-progress-reporter []
(ProgressReporter.))
View
@@ -4,7 +4,7 @@
[speclj.config :only (*reporters* *color?* *full-stack-trace?*)]
[clojure.string :as string :only (split join)])
(:import
- [speclj.results PassResult FailResult PendingResult]
+ [speclj.results PassResult FailResult PendingResult ErrorResult]
[java.io PrintWriter StringWriter]))
(defn- classname->filename [classname]
@@ -46,6 +46,9 @@
(defmethod report-run PendingResult [result reporters]
(doseq [reporter reporters]
(report-pending reporter result)))
+(defmethod report-run ErrorResult [result reporters]
+ (doseq [reporter reporters]
+ (report-error reporter result)))
(defn- stylizer [code]
(fn [text]
Oops, something went wrong.

0 comments on commit 442fb3a

Please sign in to comment.