Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added exit code for failures and exceptions

  • Loading branch information...
commit f261ecda3143144633a28e1b8465c10b13df365b 1 parent 67c8c32
@weavejester authored
View
15 src/fact/core.clj
@@ -150,3 +150,18 @@
"Get a lazy list of results from all the facts in a namespace."
([] (verify-facts *ns*))
([ns] (map verify (get-facts ns))))
+
+(defn failure?
+ "Did the fact fail?"
+ [result]
+ (not-empty (result :failures)))
+
+(defn exception?
+ "Did the fact throw an exception?"
+ [result]
+ (not-empty (result :exceptions)))
+
+(defn pending?
+ "Is the fact pending a verification test?"
+ [result]
+ (:pending? (result :fact)))
View
37 src/fact/main.clj
@@ -38,16 +38,25 @@
(let [printer (var-get (ns-resolve namespace 'print-results))]
(printer title results))))
-(defn run-facts
+(defn load-facts
+ "Load and verify facts from a file, returning the namespace and results."
+ [file]
+ (load-file file)
+ (let [ns (namespace-from-path file)]
+ [ns (verify-facts ns)]))
+
+(defn load-result-map
+ "Load all facts in a list of files, and return a map of namespaces to
+ results."
+ [files]
+ (into (sorted-map) (map load-facts files)))
+
+(defn print-result-map
"Load the files with facts in them, verify the facts, and print the results."
- [output files]
- (doseq [file files]
- (load-file file)
- (let [ns (namespace-from-path file)
- results (verify-facts ns)]
- (when-not (empty? results)
- (print-results output ns results)
- (println)))))
+ [output result-map]
+ (doseq [[ns results] result-map]
+ (when-not (empty? results)
+ (print-results output ns results))))
(defn -main [& args]
"Main method."
@@ -55,4 +64,12 @@
"fact - Verify facts in files"
[[output o "The output type to use"]
files]
- (run-facts (or output "verbose") files)))
+ (let [result-map (load-result-map files)
+ results (mapcat val result-map)]
+ (print-result-map
+ (or output "verbose")
+ result-map)
+ (when (some exception? results)
+ (System/exit 2))
+ (when (some failure? results)
+ (System/exit 1)))))
View
15 src/fact/output/color.clj
@@ -11,7 +11,8 @@
;; Verbose color output of fact results.
(ns fact.output.color
- (:require [fact.output.verbose :as verbose]))
+ (:use fact.core)
+ (:use [fact.output.verbose :only (format-result print-summary)]))
(def ansi-red "\033[31m")
(def ansi-green "\033[32m")
@@ -25,11 +26,11 @@
(println title)
(doseq [result results]
(cond
- (verbose/pending? result) (print ansi-brown)
- (verbose/exception? result) (print ansi-red)
- (verbose/failure? result) (print ansi-red)
- :fact-passed (print ansi-green))
- (print (verbose/format-result result))
+ (pending? result) (print ansi-brown)
+ (exception? result) (print ansi-red)
+ (failure? result) (print ansi-red)
+ :fact-passed (print ansi-green))
+ (print (format-result result))
(print ansi-default)
(println))
- (verbose/print-summary results))
+ (print-summary results))
View
28 src/fact/output/verbose.clj
@@ -10,7 +10,8 @@
;;
;; Verbose output of fact results.
-(ns fact.output.verbose)
+(ns fact.output.verbose
+ (:use fact.core))
(defn- format-params
"Format a collection of parameters and values to a string."
@@ -36,21 +37,6 @@
(format-params ((result :fact) :params)
(first (result :failures)))))
-(defn failure?
- "Did the fact fail?"
- [result]
- (seq (result :failures)))
-
-(defn exception?
- "Did the fact throw an exception?"
- [result]
- (seq (result :exceptions)))
-
-(defn pending?
- "Is the fact pending a verification test?"
- [result]
- (:pending? (result :fact)))
-
(defn format-result
"Format a single result from a verified fact."
[result]
@@ -63,10 +49,12 @@
(defn print-summary
"Print a summary of how many facts succeeded, failed, or excepted."
[results]
- (println (count results) "facts,"
- (count (filter pending? results)) "pending,"
- (count (filter failure? results)) "failed,"
- (count (filter exception? results)) "exceptions"))
+ (println
+ (count results) "facts,"
+ (count (filter pending? results)) "pending,"
+ (count (filter failure? results)) "failed,"
+ (count (filter exception? results)) "exceptions")
+ (println))
(defn print-results
"Prints the results from a set of verified facts to *test-out*."
Please sign in to comment.
Something went wrong with that request. Please try again.