Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of https://github.com/mylesmegyesi/speclj into …

…clojure_1_3
  • Loading branch information...
commit 8e26af8af08b2df8f6276f2a3bf4d0d48213ae8d 2 parents c33152e + 3cd507b
@slagyr authored
Showing with 22 additions and 6 deletions.
  1. +22 −6 src/speclj/run/vigilant.clj
View
28 src/speclj/run/vigilant.clj
@@ -2,25 +2,39 @@
(:use
[speclj.running :only (do-description run-and-report run-description clj-files-in)]
[speclj.util]
+ [speclj.results :only (categorize)]
[speclj.reporting :only (report-runs* report-message* print-stack-trace)]
[speclj.config :only (active-runner active-reporters config-bindings *specs*)]
- [fresh.core :only (freshener)])
+ [fresh.core :only (freshener make-fresh ns-to-file)])
(:import
[speclj.running Runner]
[java.util.concurrent ScheduledThreadPoolExecutor TimeUnit]))
(def start-time (atom 0))
-(defn- report-update [report]
+(defn- report-update [msg report]
(let [reporters (active-reporters)
reloads (:reloaded report)]
(when (seq reloads)
(report-message* reporters (str endl "----- " (str (java.util.Date.) " -------------------------------------------------------------------")))
(report-message* reporters (str "took " (str-time-since @start-time) " to determine file statuses."))
- (report-message* reporters "reloading files:")
+ (report-message* reporters msg)
(doseq [file reloads] (report-message* reporters (str " " (.getCanonicalPath file))))))
true)
+(defn- ns-for-results [results]
+ (set (map #(str (.ns @(.. % characteristic parent))) results))
+ )
+
+(defn- reload-failed [previous-failed current-results]
+ (when-let [prev-fail previous-failed]
+ (let [ns-to-reload (clojure.set/difference (ns-for-results prev-fail) (ns-for-results current-results))]
+ (reset! start-time (System/nanoTime))
+ (make-fresh (atom {}) (map ns-to-file ns-to-reload) (partial report-update "reloading previously failed files:"))
+ )
+ )
+ )
+
(defn- tick [configuration]
(with-bindings configuration
(let [runner (active-runner)
@@ -29,17 +43,19 @@
(reset! start-time (System/nanoTime))
(@(.reloader runner))
(when (seq @(.results runner))
+ (reload-failed (seq @(.previous-failed runner)) (seq @(.results runner)))
+ (reset! (.previous-failed runner) (:fail (categorize (seq @(.results runner)))))
(run-and-report runner reporters))
(catch Exception e (print-stack-trace e *out*)))
(reset! (.results runner) []))))
-(deftype VigilantRunner [reloader results]
+(deftype VigilantRunner [reloader results previous-failed]
Runner
(run-directories [this directories reporters]
(let [scheduler (ScheduledThreadPoolExecutor. 1)
configuration (config-bindings)
runnable (fn [] (tick configuration))]
- (reset! reloader (freshener #(set (apply clj-files-in directories)) report-update))
+ (reset! reloader (freshener #(set (apply clj-files-in directories)) (partial report-update "reloading files:")))
(.scheduleWithFixedDelay scheduler runnable 0 500 TimeUnit/MILLISECONDS)
(.awaitTermination scheduler Long/MAX_VALUE TimeUnit/SECONDS)
0))
@@ -58,5 +74,5 @@
(toString [this] (.toString this)))
(defn new-vigilant-runner []
- (VigilantRunner. (atom nil) (atom [])))
+ (VigilantRunner. (atom nil) (atom []) (atom [])))
Please sign in to comment.
Something went wrong with that request. Please try again.