Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

write raw results to .circumspec/raw

  • Loading branch information...
commit 9fd22daa25d45097bc35677dd7f2984654705fad 1 parent cadcdb1
@stuarthalloway authored
View
3  .gitignore
@@ -2,4 +2,5 @@
circumspec.jar
classes
local.properties
-lib/*.jar
+lib/*.jar
+.circumspec
View
2  src/circumspec/cli.clj
@@ -2,6 +2,7 @@
(:require [circumspec.report dot nested])
(:use [circumspec.config])
(:use [circumspec.colorize :only (*colorize*)])
+ (:require [circumspec.raw :as raw])
(:use [circumspec.runner :only (namespace-result-seq test-namespaces)]))
(defn tally
@@ -33,5 +34,6 @@
tally (tally results)]
((report-function) results)
(report-tally tally)
+ (raw/dump-results results)
(shutdown-agents)
(System/exit (exit-code tally)))))
View
18 src/circumspec/raw.clj
@@ -0,0 +1,18 @@
+(ns circumspec.raw
+ (:import java.io.File)
+ (:use [clojure.contrib.duck-streams :only (with-out-writer make-parents)]))
+
+(defn dump-file
+ "Create dump file name for a test run"
+ []
+ (File. ".circumspec/raw/" (.toString (java.util.Date.))))
+
+(defn dump-results
+ "Spit results into a file, return java.io.File instance."
+ [results]
+ (let [file (dump-file)]
+ (make-parents file)
+ (with-out-writer file
+ (doseq [result results]
+ (prn result)))
+ file))
View
13 src/circumspec/runner.clj
@@ -25,14 +25,23 @@
{:error 1
:throwable throwable}))
+(defmacro with-timing
+ "Time body, which should return a map. Merge the execution
+ time into the result under the :nsec key."
+ [& body]
+ `(let [start# (System/nanoTime)
+ result# (do ~@body)]
+ (assoc result# :nsec (- (System/nanoTime) start#))))
+
(defn run-spec
[var]
(let [spec-desc (spec-description var)]
(if (pending? var)
(pending-description spec-desc)
(try
- (@var)
- (success-description spec-desc)
+ (with-timing
+ (@var)
+ (success-description spec-desc))
(catch circumspec.AssertFailed afe
(fail-description spec-desc afe))
(catch Throwable t
View
16 test/circumspec/raw_test.clj
@@ -0,0 +1,16 @@
+(ns circumspec.raw-test
+ (:refer-clojure :exclude [assert])
+ (:use circumspec circumspec.raw))
+
+;; TODO: better filename convention
+(describe dump-file
+ (it "creates a file in .circumspec/raw"
+ (let [file (dump-file)]
+ (assert (instance? java.io.File file))
+ (assert (re-find #"\.circumspec/raw/.*" (.toString file))))))
+
+(describe dump-results
+ (it "writes complete restuls to a file"
+ (let [file (dump-results (take 2 (repeat {:sample true})))]
+ (assert (= "{:sample true}\n{:sample true}\n" (slurp (.toString file))))
+ (assert (.delete file) "deleting sample result data"))))
View
11 test/circumspec/runner_test.clj
@@ -0,0 +1,11 @@
+(ns circumspec.runner-test
+ (:refer-clojure :exclude [assert])
+ (:use circumspec)
+ (:require [circumspec.runner :as r]))
+
+(describe "with-timing"
+ (it "adds nsec timings"
+ (let [x (r/with-timing {:success 1})]
+ (assert (= 2 (count x)))
+ (assert (= 1 (:success x)))
+ (assert (instance? Long (:nsec x))))))
Please sign in to comment.
Something went wrong with that request. Please try again.