Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #213 from josephwilk/issue-210

Support colorize as option in .midje
  • Loading branch information...
commit d14ff4981ab6042e10161287da745fed466f40fd 2 parents b5cc711 + 9103b48
@marick authored
View
2  src/midje/Bootstrap.clj
@@ -16,6 +16,8 @@
( (ns-resolve 'midje.emission.api 'load-plugin)
( (ns-resolve 'midje.config 'choice) :emitter))
+ ((ns-resolve 'midje.emission.colorize 'init!))
+
((ns-resolve 'midje.emission.state 'no-more-plugin-installation))
(alter-var-root #'bootstrapped (constantly true))))
View
1  src/midje/config.clj
@@ -35,6 +35,7 @@
(defonce ^{:dynamic true}
*config* {:print-level :print-normally
+ :colorize nil
:visible-deprecation true
:visible-future true
:visible-failure-namespace false
View
44 src/midje/emission/colorize.clj
@@ -2,27 +2,37 @@
Midje output be ergonomically colorful."}
midje.emission.colorize
(:require [colorize.core :as color]
- [clojure.string :as str])
+ [clojure.string :as str]
+ [midje.config :as config])
(:use [midje.util.ecosystem :only [getenv on-windows?]]))
+(defn colorize-setting []
+ (config/choice :colorize))
-(defn colorize-choice []
- (str/upper-case (or (getenv "MIDJE_COLORIZE")
- (str (not (on-windows?))))))
+(defn- colorize-config-as-str []
+ (let [setting (colorize-setting)
+ setting (if (keyword? setting) (name setting) setting)
+ setting-as-str (str setting)]
+ (when-not (str/blank? setting-as-str) setting-as-str)))
-(case (colorize-choice)
- "TRUE" (do
- (def fail color/red)
- (def pass color/green)
- (def note color/cyan))
+(defn- colorize-choice []
+ (str/upper-case (or (getenv "MIDJE_COLORIZE")
+ (colorize-config-as-str)
+ (str (not (on-windows?))))))
- "REVERSE" (do
- (def fail color/red-bg)
- (def pass color/green-bg)
- (def note color/cyan-bg))
+(defn init! []
+ (case (colorize-choice)
+ "TRUE" (do
+ (def fail color/red)
+ (def pass color/green)
+ (def note color/cyan))
- (do
- (def fail str)
- (def pass str)
- (def note str)))
+ "REVERSE" (do
+ (def fail color/red-bg)
+ (def pass color/green-bg)
+ (def note color/cyan-bg))
+ (do
+ (def fail str)
+ (def pass str)
+ (def note str))))
View
3  src/midje/util/exceptions.clj
@@ -1,8 +1,7 @@
(ns ^{:doc "Functions for Midje to deal elegantly with exceptions."}
midje.util.exceptions
(:use [clojure.string :only [join]]
- [midje.util.ecosystem :only [line-separator]]
- [midje.emission.colorize :only [colorize-choice]]))
+ [midje.util.ecosystem :only [line-separator]]))
;;; Creating
View
4 test/implementation/util/fim_exceptions.clj
@@ -1,8 +1,8 @@
(ns implementation.util.fim-exceptions
(:use [midje.util.exceptions]
- [midje.emission.colorize :only [colorize-choice]]
[midje sweet test-util]
- midje.util))
+ [midje.util]))
+
(expose-testables midje.util.exceptions)
(defrecord R [a])
View
56 test/midje/emission/t_colorize.clj
@@ -1,32 +1,44 @@
(ns midje.emission.t-colorize
(:use midje.sweet
[midje.util.ecosystem :only [getenv on-windows?]])
- (:require [midje.emission.colorize :as color]))
+ (:require [midje.emission.colorize :as color]
+ [midje.config :as config]))
+
+
(tabular
- (fact "wraps string in ascii color when env variable is not explicitly set to FALSE"
- (do
- (require '[midje.emission.colorize :as color] :reload ) ;; enables 'provided' to take
- (?color-fn "string")) => ?result
- (provided
- (on-windows?) => ?on-windows :times (range)
- (getenv "MIDJE_COLORIZE") => ?env-var))
-
- ?color-fn ?env-var ?on-windows ?result
- color/fail "FALSE" false "string"
- color/fail "TRUE" false "\u001b[31mstring\u001b[0m"
- color/fail "reverse" false "\u001b[41mstring\u001b[0m"
- color/fail nil false "\u001b[31mstring\u001b[0m"
- color/fail nil true "string"
-
- color/note "FALSE" false "string"
- color/note "TRUE" false "\u001b[36mstring\u001b[0m"
- color/note "reverse" false "\u001b[46mstring\u001b[0m"
- color/note nil false "\u001b[36mstring\u001b[0m"
- color/note nil true "string")
+ (fact "wraps string in ascii color when env variable is not explicitly set to FALSE"
+ (do
+ (color/init!)
+ (?color-fn "string")) => ?result
+ (provided
+ (on-windows?) => ?on-windows :times (range)
+ (color/colorize-setting) => ?config-var :times (range)
+ (getenv "MIDJE_COLORIZE") => ?env-var))
+
+ ?color-fn ?env-var ?config-var ?on-windows ?result
+ color/fail "FALSE" nil false "string"
+ color/fail "TRUE" nil false "\u001b[31mstring\u001b[0m"
+ color/fail "reverse" nil false "\u001b[41mstring\u001b[0m"
+ color/fail nil nil false "\u001b[31mstring\u001b[0m"
+ color/fail nil nil true "string"
+
+ ;Expore priority of config-var vs env var
+ color/fail nil true false "\u001b[31mstring\u001b[0m"
+ color/fail "FALSE" true false "string"
+ color/fail nil false false "string"
+ color/fail "TRUE" false false "\u001b[31mstring\u001b[0m"
+ color/fail nil :reverse false "\u001b[41mstring\u001b[0m"
+
+ color/note "FALSE" nil false "string"
+ color/note "TRUE" nil false "\u001b[36mstring\u001b[0m"
+ color/note "reverse" nil false "\u001b[46mstring\u001b[0m"
+ color/note nil nil false "\u001b[36mstring\u001b[0m"
+ color/note nil nil true "string")
+
;; Reset to user's default colorization.
-(require '[midje.emission.colorize] :reload )
+(color/init!)
(fact "access environment vars only when namespace is loaded"
Please sign in to comment.
Something went wrong with that request. Please try again.