Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support reading colorize from .midje

  • Loading branch information...
commit e71f1f40279f92d4df0db637f8d3b47c05a3db42 1 parent 8a56661
Joseph Wilk josephwilk authored
2  src/midje/Bootstrap.clj
View
@@ -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))))
1  src/midje/config.clj
View
@@ -35,6 +35,7 @@
(defonce ^{:dynamic true}
*config* {:print-level :print-normally
+ :colorize true
:visible-deprecation true
:visible-future true
:visible-failure-namespace false
14 src/midje/emission/colorize.clj
View
@@ -2,13 +2,21 @@
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 []
+(defn- colorize-config-as-str []
+ (let [setting-as-str (str (colorize-setting))]
+ (when-not (str/blank? setting-as-str) setting-as-str)))
+
+(defn- colorize-choice []
(str/upper-case (or (getenv "MIDJE_COLORIZE")
- (str (not (on-windows?))))))
+ (colorize-config-as-str)
+ (str (not (on-windows?))))))
(defn init! []
(case (colorize-choice)
5 src/midje/util/exceptions.clj
View
@@ -1,11 +1,8 @@
(ns ^{:doc "Functions for Midje to deal elegantly with exceptions."}
midje.util.exceptions
(:use [clojure.string :only [join]]
- [midje.util.ecosystem :only [line-separator]])
- (:require
- [midje.emission.colorize :as colorize]))
+ [midje.util.ecosystem :only [line-separator]]))
-(colorize/init!)
;;; Creating
5 test/implementation/util/fim_exceptions.clj
View
@@ -1,11 +1,8 @@
(ns implementation.util.fim-exceptions
(:use [midje.util.exceptions]
[midje sweet test-util]
- [midje.util])
- (:require
- [midje.emission.colorize :as colorize))
+ [midje.util]))
-(colorize/init!)
(expose-testables midje.util.exceptions)
(defrecord R [a])
53 test/midje/emission/t_colorize.clj
View
@@ -1,29 +1,40 @@
(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
- (color/init!)
- (?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/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.
(color/init!)
Please sign in to comment.
Something went wrong with that request. Please try again.